diff --git a/mail_notification_custom_subject/__manifest__.py b/mail_notification_custom_subject/__manifest__.py index 1c970d3..7302252 100644 --- a/mail_notification_custom_subject/__manifest__.py +++ b/mail_notification_custom_subject/__manifest__.py @@ -7,13 +7,11 @@ "summary": "Apply a custom subject to mail notifications", "version": "12.0.1.0.0", "category": "Social Network", - "website": "https://github.com/OCA/social/", + "website": "https://github.com/OCA/social", "author": "Tecnativa, Odoo Community Association (OCA)", "license": "AGPL-3", "installable": True, - "depends": [ - "mail", - ], + "depends": ["mail"], "data": [ "security/ir.model.access.csv", "views/mail_notification_custom_subject_views.xml", diff --git a/mail_notification_custom_subject/models/mail_message_custom_subject.py b/mail_notification_custom_subject/models/mail_message_custom_subject.py index 0fb5bbd..60a713a 100644 --- a/mail_notification_custom_subject/models/mail_message_custom_subject.py +++ b/mail_notification_custom_subject/models/mail_message_custom_subject.py @@ -16,9 +16,7 @@ class MailMessageCustomSubject(models.Model): help="Model where this template applies", ) subtype_ids = fields.Many2many( - comodel_name="mail.message.subtype", - string="Applied Subtypes", - required=True, + comodel_name="mail.message.subtype", string="Applied Subtypes", required=True, ) subject_template = fields.Char( string="Subject Template", diff --git a/mail_notification_custom_subject/models/mail_thread.py b/mail_notification_custom_subject/models/mail_thread.py index c26742e..8743fcb 100644 --- a/mail_notification_custom_subject/models/mail_thread.py +++ b/mail_notification_custom_subject/models/mail_thread.py @@ -23,25 +23,21 @@ class MailThread(models.AbstractModel): mail_auto_delete=True, **kwargs ): - subtype_id = kwargs.get('subtype_id', False) + subtype_id = kwargs.get("subtype_id", False) if not subtype_id: - subtype = subtype or 'mt_note' - if '.' not in subtype: - subtype = 'mail.%s' % subtype - subtype_id = self.env['ir.model.data'].xmlid_to_res_id( + subtype = subtype or "mt_note" + if "." not in subtype: + subtype = "mail.%s" % subtype + subtype_id = self.env["ir.model.data"].xmlid_to_res_id( subtype, raise_if_not_found=False, ) if subtype_id: custom_subjects = self.env["mail.message.custom.subject"].search( - [ - ("model_id.model", "=", self._name), - ("subtype_ids", "=", subtype_id), - ] + [("model_id.model", "=", self._name), ("subtype_ids", "=", subtype_id)] ) if not subject: - subject = 'Re: %s' % self.env["mail.message"].with_context( - default_model=self._name, - default_res_id=self.id, + subject = "Re: %s" % self.env["mail.message"].with_context( + default_model=self._name, default_res_id=self.id, )._get_record_name({}) for template in custom_subjects: try: diff --git a/mail_notification_custom_subject/tests/test_mail_notification_custom_subject.py b/mail_notification_custom_subject/tests/test_mail_notification_custom_subject.py index 7ecde6e..dfd672e 100644 --- a/mail_notification_custom_subject/tests/test_mail_notification_custom_subject.py +++ b/mail_notification_custom_subject/tests/test_mail_notification_custom_subject.py @@ -1,6 +1,6 @@ # Copyright 2020 Tecnativa - João Marques # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - +# pylint: disable=C8107 from odoo.tests import common @@ -27,15 +27,7 @@ class TestMailNotificationCustomSubject(common.TransactionCase): { "name": "Test template 1", "model_id": self.env.ref("base.model_res_partner").id, - "subtype_ids": [ - ( - 6, - 0, - [ - self.env.ref("mail.mt_comment").id, - ], - ) - ], + "subtype_ids": [(6, 0, [self.env.ref("mail.mt_comment").id])], "subject_template": "${object.name or 'n/a'} and something more", } ) @@ -65,15 +57,7 @@ class TestMailNotificationCustomSubject(common.TransactionCase): { "name": "Test template 1", "model_id": self.env.ref("base.model_res_partner").id, - "subtype_ids": [ - ( - 6, - 0, - [ - self.env.ref("mail.mt_comment").id, - ], - ) - ], + "subtype_ids": [(6, 0, [self.env.ref("mail.mt_comment").id])], "subject_template": "${object.name or 'n/a'} and something more", } ) @@ -89,15 +73,7 @@ class TestMailNotificationCustomSubject(common.TransactionCase): { "name": "Test template 1", "model_id": self.env.ref("base.model_res_partner").id, - "subtype_ids": [ - ( - 6, - 0, - [ - self.env.ref("mail.mt_comment").id, - ], - ) - ], + "subtype_ids": [(6, 0, [self.env.ref("mail.mt_comment").id])], "subject_template": "${object.name or 'n/a'} and something more", } ) @@ -105,15 +81,7 @@ class TestMailNotificationCustomSubject(common.TransactionCase): { "name": "Test template 2", "model_id": self.env.ref("base.model_res_partner").id, - "subtype_ids": [ - ( - 6, - 0, - [ - self.env.ref("mail.mt_comment").id, - ], - ) - ], + "subtype_ids": [(6, 0, [self.env.ref("mail.mt_comment").id])], "subject_template": "${object.name or 'n/a'} and something different", } ) @@ -129,15 +97,7 @@ class TestMailNotificationCustomSubject(common.TransactionCase): { "name": "Test template 3", "model_id": self.env.ref("base.model_res_partner").id, - "subtype_ids": [ - ( - 6, - 0, - [ - self.env.ref("mail.mt_comment").id, - ], - ) - ], + "subtype_ids": [(6, 0, [self.env.ref("mail.mt_comment").id])], "subject_template": "${' and yet something else'}", "position": "append_after", } @@ -155,15 +115,7 @@ class TestMailNotificationCustomSubject(common.TransactionCase): { "name": "Test template 4", "model_id": self.env.ref("base.model_res_partner").id, - "subtype_ids": [ - ( - 6, - 0, - [ - self.env.ref("mail.mt_comment").id, - ], - ) - ], + "subtype_ids": [(6, 0, [self.env.ref("mail.mt_comment").id])], "subject_template": "${'Re: '}", "position": "append_before", } @@ -183,15 +135,7 @@ class TestMailNotificationCustomSubject(common.TransactionCase): { "name": "Test template 1", "model_id": self.env.ref("base.model_res_partner").id, - "subtype_ids": [ - ( - 6, - 0, - [ - self.env.ref("mail.mt_comment").id, - ], - ) - ], + "subtype_ids": [(6, 0, [self.env.ref("mail.mt_comment").id])], "subject_template": "${' and something more'}", "position": "append_after", } @@ -201,24 +145,14 @@ class TestMailNotificationCustomSubject(common.TransactionCase): body="Test", subtype="mail.mt_comment", subject="Test", ) # Get message and check subject - self.assertEquals( - mail_message_1.subject, "Test and something more" - ) + self.assertEquals(mail_message_1.subject, "Test and something more") def test_bad_template_does_not_break(self): self.env["mail.message.custom.subject"].create( { "name": "Test bad template 1", "model_id": self.env.ref("base.model_res_partner").id, - "subtype_ids": [ - ( - 6, - 0, - [ - self.env.ref("mail.mt_comment").id, - ], - ) - ], + "subtype_ids": [(6, 0, [self.env.ref("mail.mt_comment").id])], "subject_template": "${obaject.number_a} and something", "position": "append_after", } @@ -229,9 +163,7 @@ class TestMailNotificationCustomSubject(common.TransactionCase): ) # Get message and check subject # No exception should be raised but subject should remain as original. - self.assertEquals( - mail_message_1.subject, "Test" - ) + self.assertEquals(mail_message_1.subject, "Test") def test_no_template_default_result(self): # Send message in partner @@ -240,6 +172,4 @@ class TestMailNotificationCustomSubject(common.TransactionCase): ) # Get message and check subject # No exception should be raised but subject should remain as original. - self.assertEquals( - mail_message_1.subject, "Test partner 1" - ) + self.assertEquals(mail_message_1.subject, "Test partner 1") diff --git a/mail_notification_custom_subject/views/mail_notification_custom_subject_views.xml b/mail_notification_custom_subject/views/mail_notification_custom_subject_views.xml index 7dd4e5a..e2b3330 100644 --- a/mail_notification_custom_subject/views/mail_notification_custom_subject_views.xml +++ b/mail_notification_custom_subject/views/mail_notification_custom_subject_views.xml @@ -1,4 +1,4 @@ - + @@ -8,14 +8,17 @@
-
- - + + - +
@@ -27,15 +30,18 @@ mail.message.custom.subject - - - - + + + +
- + Subject Replacement Templates mail.message.custom.subject form @@ -43,8 +49,12 @@ - +