Merge PR #1016 into 15.0

Signed-off-by rafaelbn
This commit is contained in:
OCA-git-bot 2022-12-02 09:38:50 +00:00
commit b44d3bf1c6
3 changed files with 92 additions and 71 deletions

View File

@ -17,5 +17,5 @@
"views/mail_notification_custom_subject_views.xml", "views/mail_notification_custom_subject_views.xml",
], ],
"development_status": "Production/Stable", "development_status": "Production/Stable",
"maintainers": ["joao-p-marques"], "maintainers": ["yajo"],
} }

View File

@ -33,8 +33,16 @@ class MailThread(models.AbstractModel):
raise_if_not_found=False, raise_if_not_found=False,
) )
if subtype_id: if subtype_id:
custom_subjects = self.env["mail.message.custom.subject"].search( custom_subjects = (
[("model_id.model", "=", self._name), ("subtype_ids", "=", subtype_id)] self.env["mail.message.custom.subject"]
.sudo()
.search(
[
("model_id.model", "=", self._name),
("subtype_ids", "=", subtype_id),
]
)
.sudo(False)
) )
if not subject: if not subject:
subject = "Re: %s" % self.env["mail.message"].with_context( subject = "Re: %s" % self.env["mail.message"].with_context(

View File

@ -20,8 +20,14 @@ class TestMailNotificationCustomSubject(common.TransactionCase):
] ]
) )
) )
cls.admin = common.new_test_user(cls.env, "boss", "base.group_system")
def setUp(self):
super().setUp()
self.uid = common.new_test_user(self.env, "worker")
def test_email_subject_template_overrides(self): def test_email_subject_template_overrides(self):
with self.with_user("boss"):
self.env["mail.message.custom.subject"].create( self.env["mail.message.custom.subject"].create(
{ {
"name": "Test template 1", "name": "Test template 1",
@ -52,6 +58,7 @@ class TestMailNotificationCustomSubject(common.TransactionCase):
self.assertEqual(mail_message_3.subject, "Test partner 2 and something more") self.assertEqual(mail_message_3.subject, "Test partner 2 and something more")
def test_email_subject_template_normal(self): def test_email_subject_template_normal(self):
with self.with_user("boss"):
self.env["mail.message.custom.subject"].create( self.env["mail.message.custom.subject"].create(
{ {
"name": "Test template 1", "name": "Test template 1",
@ -68,6 +75,7 @@ class TestMailNotificationCustomSubject(common.TransactionCase):
self.assertEqual(mail_message_1.subject, "Test") self.assertEqual(mail_message_1.subject, "Test")
def test_email_subject_template_multi(self): def test_email_subject_template_multi(self):
with self.with_user("boss"):
self.env["mail.message.custom.subject"].create( self.env["mail.message.custom.subject"].create(
{ {
"name": "Test template 1", "name": "Test template 1",
@ -76,6 +84,7 @@ class TestMailNotificationCustomSubject(common.TransactionCase):
"subject_template": "{{object.name or 'n/a'}} and something more", "subject_template": "{{object.name or 'n/a'}} and something more",
} }
) )
with self.with_user("boss"):
self.env["mail.message.custom.subject"].create( self.env["mail.message.custom.subject"].create(
{ {
"name": "Test template 2", "name": "Test template 2",
@ -92,6 +101,7 @@ class TestMailNotificationCustomSubject(common.TransactionCase):
self.assertEqual( self.assertEqual(
mail_message_1.subject, "Test partner 1 and something different" mail_message_1.subject, "Test partner 1 and something different"
) )
with self.with_user("boss"):
self.env["mail.message.custom.subject"].create( self.env["mail.message.custom.subject"].create(
{ {
"name": "Test template 3", "name": "Test template 3",
@ -110,6 +120,7 @@ class TestMailNotificationCustomSubject(common.TransactionCase):
mail_message_2.subject, mail_message_2.subject,
"Test partner 1 and something different and yet something else", "Test partner 1 and something different and yet something else",
) )
with self.with_user("boss"):
self.env["mail.message.custom.subject"].create( self.env["mail.message.custom.subject"].create(
{ {
"name": "Test template 4", "name": "Test template 4",
@ -130,6 +141,7 @@ class TestMailNotificationCustomSubject(common.TransactionCase):
) )
def test_email_subject_template_w_original(self): def test_email_subject_template_w_original(self):
with self.with_user("boss"):
self.env["mail.message.custom.subject"].create( self.env["mail.message.custom.subject"].create(
{ {
"name": "Test template 1", "name": "Test template 1",
@ -150,6 +162,7 @@ class TestMailNotificationCustomSubject(common.TransactionCase):
def test_bad_template_does_not_break(self): def test_bad_template_does_not_break(self):
"""Create template with error (obaject) to test error.""" """Create template with error (obaject) to test error."""
with self.with_user("boss"):
self.env["mail.message.custom.subject"].create( self.env["mail.message.custom.subject"].create(
{ {
"name": "Test bad template 1", "name": "Test bad template 1",