[IMP] mail_notification_custom_subject: black, isort, prettier

This commit is contained in:
Naglis Jonaitis 2021-08-12 12:57:11 +03:00 committed by Víctor Martínez
parent 51c4d08122
commit d5f0d97a9d
3 changed files with 20 additions and 7 deletions

View File

@ -16,7 +16,9 @@ class MailMessageCustomSubject(models.Model):
help="Model where this template applies", help="Model where this template applies",
) )
subtype_ids = fields.Many2many( 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( subject_template = fields.Char(
string="Subject Template", string="Subject Template",

View File

@ -29,16 +29,23 @@ class MailThread(models.AbstractModel):
if "." not in subtype: if "." not in subtype:
subtype = "mail.%s" % subtype subtype = "mail.%s" % subtype
subtype_id = self.env["ir.model.data"].xmlid_to_res_id( subtype_id = self.env["ir.model.data"].xmlid_to_res_id(
subtype, raise_if_not_found=False, subtype,
raise_if_not_found=False,
) )
if subtype_id: if subtype_id:
custom_subjects = self.env["mail.message.custom.subject"].search( 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: if not subject:
subject = "Re: %s" % self.env["mail.message"].with_context( subject = (
default_model=self._name, default_res_id=self.id, "Re: %s"
)._get_record_name({}) % self.env["mail.message"]
.with_context(
default_model=self._name,
default_res_id=self.id,
)
._get_record_name({})
)
for template in custom_subjects: for template in custom_subjects:
try: try:
rendered_subject_template = self.env[ rendered_subject_template = self.env[

View File

@ -134,7 +134,9 @@ class TestMailNotificationCustomSubject(common.TransactionCase):
) )
# Send message in partner # Send message in partner
mail_message_1 = self.partner_1.message_post( mail_message_1 = self.partner_1.message_post(
body="Test", subtype="mail.mt_comment", subject="Test", body="Test",
subtype="mail.mt_comment",
subject="Test",
) )
# Get message and check subject # 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")
@ -152,7 +154,9 @@ class TestMailNotificationCustomSubject(common.TransactionCase):
) )
# Send message in partner # Send message in partner
mail_message_1 = self.partner_1.message_post( mail_message_1 = self.partner_1.message_post(
body="Test", subtype="mail.mt_comment", subject="Test", body="Test",
subtype="mail.mt_comment",
subject="Test",
) )
# Get message and check subject # Get message and check subject
# No exception should be raised but subject should remain as original. # No exception should be raised but subject should remain as original.