From 5d487016747daa97ad07277d0559c0fad02c75b3 Mon Sep 17 00:00:00 2001 From: sergio Date: Tue, 28 Jan 2025 10:15:00 +0100 Subject: [PATCH] [MIG] mail_layout_force: Migration to 17.0 --- mail_layout_force/__manifest__.py | 2 +- mail_layout_force/models/__init__.py | 1 - mail_layout_force/models/mail_template.py | 34 ++------- mail_layout_force/models/mail_thread.py | 20 ----- mail_layout_force/tests/__init__.py | 1 - .../tests/test_mail_layout_force.py | 73 ------------------- .../wizards/mail_compose_message.py | 4 +- 7 files changed, 11 insertions(+), 124 deletions(-) delete mode 100644 mail_layout_force/models/mail_thread.py delete mode 100644 mail_layout_force/tests/__init__.py delete mode 100644 mail_layout_force/tests/test_mail_layout_force.py diff --git a/mail_layout_force/__manifest__.py b/mail_layout_force/__manifest__.py index 6152eaa26a..8872c8bf26 100644 --- a/mail_layout_force/__manifest__.py +++ b/mail_layout_force/__manifest__.py @@ -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", diff --git a/mail_layout_force/models/__init__.py b/mail_layout_force/models/__init__.py index 89e090b241..44e83956eb 100644 --- a/mail_layout_force/models/__init__.py +++ b/mail_layout_force/models/__init__.py @@ -1,2 +1 @@ from . import mail_template -from . import mail_thread diff --git a/mail_layout_force/models/mail_template.py b/mail_layout_force/models/mail_template.py index f19c340191..e9f29977e5 100644 --- a/mail_layout_force/models/mail_template.py +++ b/mail_layout_force/models/mail_template.py @@ -2,7 +2,7 @@ # @author Iván Todorovich # 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): @@ -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 diff --git a/mail_layout_force/models/mail_thread.py b/mail_layout_force/models/mail_thread.py deleted file mode 100644 index 25be8bddae..0000000000 --- a/mail_layout_force/models/mail_thread.py +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright 2022 Camptocamp SA (https://www.camptocamp.com). -# @author Iván Todorovich -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). - -from odoo import models - - -class MailThread(models.AbstractModel): - _inherit = "mail.thread" - - def message_post_with_template( - self, template_id, email_layout_xmlid=None, **kwargs - ): - # OVERRIDE to force the email_layout_xmlid defined on the mail.template - template = self.env["mail.template"].sudo().browse(template_id) - if template.force_email_layout_id: - email_layout_xmlid = template.force_email_layout_id.xml_id - return super().message_post_with_template( - template_id, email_layout_xmlid=email_layout_xmlid, **kwargs - ) diff --git a/mail_layout_force/tests/__init__.py b/mail_layout_force/tests/__init__.py deleted file mode 100644 index 9fd17597d3..0000000000 --- a/mail_layout_force/tests/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from . import test_mail_layout_force diff --git a/mail_layout_force/tests/test_mail_layout_force.py b/mail_layout_force/tests/test_mail_layout_force.py deleted file mode 100644 index 8ef77222cc..0000000000 --- a/mail_layout_force/tests/test_mail_layout_force.py +++ /dev/null @@ -1,73 +0,0 @@ -# Copyright 2022 Camptocamp SA (https://www.camptocamp.com). -# @author Iván Todorovich -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). - -from odoo.tests import TransactionCase - - -class TestMailLayoutForce(TransactionCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.layout_noop = cls.env.ref("mail_layout_force.mail_layout_noop") - cls.layout_test = cls.env["ir.ui.view"].create( - { - "name": "Test Layout", - "type": "qweb", - "mode": "primary", - "arch": "

", - } - ) - cls.template = cls.env["mail.template"].create( - { - "name": "Test Template", - "body_html": "

Test

", - "subject": "Test", - "model_id": cls.env.ref("base.model_res_partner").id, - "auto_delete": False, - } - ) - cls.partner = cls.env.ref("base.res_partner_10") - cls.partner.message_ids.unlink() - cls.partner.message_subscribe([cls.partner.id]) - - def test_noop_layout(self): - self.template.force_email_layout_id = self.layout_noop - self.partner.message_post_with_template( - self.template.id, - # This is ignored because the template has a force_email_layout_id - email_layout_xmlid="mail.mail_notification_light", - ) - message = self.partner.message_ids[-1] - self.assertEqual(message.mail_ids.body_html.strip(), "

Test

") - - def test_custom_layout(self): - self.template.force_email_layout_id = self.layout_test - self.partner.message_post_with_template( - self.template.id, - # This is ignored because the template has a force_email_layout_id - email_layout_xmlid="mail.mail_notification_light", - ) - message = self.partner.message_ids[-1] - self.assertEqual(message.mail_ids.body_html.strip(), "

Test

") - - def test_custom_layout_composer(self): - self.template.force_email_layout_id = self.layout_test - composer = ( - self.env["mail.compose.message"] - .with_context( - # This is ignored because the template has a force_email_layout_id - custom_layout="mail.mail_notification_light" - ) - .create( - { - "res_id": self.partner.id, - "model": self.partner._name, - "template_id": self.template.id, - } - ) - ) - composer._onchange_template_id_wrapper() - composer._action_send_mail() - message = self.partner.message_ids[-1] - self.assertEqual(message.mail_ids.body_html.strip(), "

Test

") diff --git a/mail_layout_force/wizards/mail_compose_message.py b/mail_layout_force/wizards/mail_compose_message.py index 7ab38d6ced..4d3346c23f 100644 --- a/mail_layout_force/wizards/mail_compose_message.py +++ b/mail_layout_force/wizards/mail_compose_message.py @@ -1,7 +1,7 @@ # Copyright 2022 Camptocamp SA (https://www.camptocamp.com). # @author Iván Todorovich # Copyright 2023 Abraham Anes -# 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 @@ -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 - return super(MailComposer, self)._action_send_mail(auto_commit=auto_commit) + return super()._action_send_mail(auto_commit=auto_commit)