Skip to content

Commit

Permalink
[MIG] mail_layout_force: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sergioM-S73 committed Jan 28, 2025
1 parent 9dced53 commit 5d48701
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 124 deletions.
2 changes: 1 addition & 1 deletion mail_layout_force/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "Mail Layout Force",
"summary": "Force a mail layout on selected email templates",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"author": "Camptocamp, Odoo Community Association (OCA)",
"maintainers": ["ivantodorovich"],
"website": "https://github.com/OCA/social",
Expand Down
1 change: 0 additions & 1 deletion mail_layout_force/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from . import mail_template
from . import mail_thread
34 changes: 8 additions & 26 deletions mail_layout_force/models/mail_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# @author Iván Todorovich <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo import fields, models


class MailTemplate(models.Model):
Expand All @@ -16,29 +16,11 @@ class MailTemplate(models.Model):
help="Force a mail layout for this template.",
)

def _ensure_force_email_layout_xml_id(self):
missing = self.force_email_layout_id.filtered(lambda rec: not rec.xml_id)
if missing:
vals = [
{
"module": "__export__",
"name": "force_email_layout_%s" % rec.id,
"model": rec._name,
"res_id": rec.id,
}
for rec in missing
]
self.env["ir.model.data"].sudo().create(vals)
self.force_email_layout_id.invalidate_recordset(["xml_id"])

@api.model_create_multi
def create(self, vals_list):
records = super().create(vals_list)
records._ensure_force_email_layout_xml_id()
return records
email_layout_xmlid = fields.Char(
compute="_compute_email_layout_id", store=True, readonly=False
)

def write(self, vals):
res = super().write(vals)
if "force_email_layout_id" in vals:
self._ensure_force_email_layout_xml_id()
return res
def _compute_email_layout_id(self):
for template in self:
if template.force_email_layout_id:
template.email_layout_xmlid = template.force_email_layout_id.xml_id

Check warning on line 26 in mail_layout_force/models/mail_template.py

View check run for this annotation

Codecov / codecov/patch

mail_layout_force/models/mail_template.py#L26

Added line #L26 was not covered by tests
20 changes: 0 additions & 20 deletions mail_layout_force/models/mail_thread.py

This file was deleted.

1 change: 0 additions & 1 deletion mail_layout_force/tests/__init__.py

This file was deleted.

73 changes: 0 additions & 73 deletions mail_layout_force/tests/test_mail_layout_force.py

This file was deleted.

4 changes: 2 additions & 2 deletions mail_layout_force/wizards/mail_compose_message.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2022 Camptocamp SA (https://www.camptocamp.com).
# @author Iván Todorovich <[email protected]>
# Copyright 2023 Abraham Anes <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)

from odoo import models

Expand All @@ -14,4 +14,4 @@ def _action_send_mail(self, auto_commit=False):
for rec in self:
if rec.template_id.force_email_layout_id:
rec.email_layout_xmlid = rec.template_id.force_email_layout_id.xml_id

Check warning on line 16 in mail_layout_force/wizards/mail_compose_message.py

View check run for this annotation

Codecov / codecov/patch

mail_layout_force/wizards/mail_compose_message.py#L16

Added line #L16 was not covered by tests
return super(MailComposer, self)._action_send_mail(auto_commit=auto_commit)
return super()._action_send_mail(auto_commit=auto_commit)

0 comments on commit 5d48701

Please sign in to comment.