[MIG] mail_notification_custom_subject: Migration to 14.0
This commit is contained in:
parent
d5f0d97a9d
commit
14cc2d99be
@ -5,7 +5,7 @@
|
|||||||
{
|
{
|
||||||
"name": "Mail Notification Custom Subject",
|
"name": "Mail Notification Custom Subject",
|
||||||
"summary": "Apply a custom subject to mail notifications",
|
"summary": "Apply a custom subject to mail notifications",
|
||||||
"version": "13.0.1.0.0",
|
"version": "14.0.1.0.0",
|
||||||
"category": "Social Network",
|
"category": "Social Network",
|
||||||
"website": "https://github.com/OCA/social",
|
"website": "https://github.com/OCA/social",
|
||||||
"author": "Tecnativa, Odoo Community Association (OCA)",
|
"author": "Tecnativa, Odoo Community Association (OCA)",
|
||||||
|
@ -14,6 +14,7 @@ class MailMessageCustomSubject(models.Model):
|
|||||||
string="Model",
|
string="Model",
|
||||||
required=True,
|
required=True,
|
||||||
help="Model where this template applies",
|
help="Model where this template applies",
|
||||||
|
ondelete="cascade",
|
||||||
)
|
)
|
||||||
subtype_ids = fields.Many2many(
|
subtype_ids = fields.Many2many(
|
||||||
comodel_name="mail.message.subtype",
|
comodel_name="mail.message.subtype",
|
||||||
|
@ -11,25 +11,27 @@ class MailThread(models.AbstractModel):
|
|||||||
@api.returns("mail.message", lambda value: value.id)
|
@api.returns("mail.message", lambda value: value.id)
|
||||||
def message_post(
|
def message_post(
|
||||||
self,
|
self,
|
||||||
|
*,
|
||||||
body="",
|
body="",
|
||||||
subject=None,
|
subject=None,
|
||||||
message_type="notification",
|
message_type="notification",
|
||||||
subtype=None,
|
email_from=None,
|
||||||
|
author_id=None,
|
||||||
parent_id=False,
|
parent_id=False,
|
||||||
|
subtype_xmlid=None,
|
||||||
|
subtype_id=False,
|
||||||
|
partner_ids=None,
|
||||||
|
channel_ids=None,
|
||||||
attachments=None,
|
attachments=None,
|
||||||
notif_layout=False,
|
attachment_ids=None,
|
||||||
add_sign=True,
|
add_sign=True,
|
||||||
model_description=False,
|
record_name=False,
|
||||||
mail_auto_delete=True,
|
|
||||||
**kwargs
|
**kwargs
|
||||||
):
|
):
|
||||||
subtype_id = kwargs.get("subtype_id", False)
|
subtype_id = kwargs.get("subtype_id", False)
|
||||||
if not subtype_id:
|
if not subtype_id and subtype_xmlid:
|
||||||
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_id = self.env["ir.model.data"].xmlid_to_res_id(
|
||||||
subtype,
|
subtype_xmlid,
|
||||||
raise_if_not_found=False,
|
raise_if_not_found=False,
|
||||||
)
|
)
|
||||||
if subtype_id:
|
if subtype_id:
|
||||||
@ -51,10 +53,12 @@ class MailThread(models.AbstractModel):
|
|||||||
rendered_subject_template = self.env[
|
rendered_subject_template = self.env[
|
||||||
"mail.template"
|
"mail.template"
|
||||||
]._render_template(
|
]._render_template(
|
||||||
template_txt=template.subject_template,
|
template_src=template.subject_template,
|
||||||
model=self._name,
|
model=self._name,
|
||||||
res_ids=self.id,
|
res_ids=[self.id],
|
||||||
)
|
)[
|
||||||
|
self.id
|
||||||
|
]
|
||||||
if template.position == "replace":
|
if template.position == "replace":
|
||||||
subject = rendered_subject_template
|
subject = rendered_subject_template
|
||||||
elif template.position == "append_before":
|
elif template.position == "append_before":
|
||||||
@ -67,12 +71,16 @@ class MailThread(models.AbstractModel):
|
|||||||
body=body,
|
body=body,
|
||||||
subject=subject,
|
subject=subject,
|
||||||
message_type=message_type,
|
message_type=message_type,
|
||||||
subtype=subtype,
|
email_from=email_from,
|
||||||
|
author_id=author_id,
|
||||||
parent_id=parent_id,
|
parent_id=parent_id,
|
||||||
|
subtype_xmlid=subtype_xmlid,
|
||||||
|
subtype_id=subtype_id,
|
||||||
|
partner_ids=partner_ids,
|
||||||
|
channel_ids=channel_ids,
|
||||||
attachments=attachments,
|
attachments=attachments,
|
||||||
notif_layout=notif_layout,
|
attachment_ids=attachment_ids,
|
||||||
add_sign=add_sign,
|
add_sign=add_sign,
|
||||||
model_description=model_description,
|
record_name=record_name,
|
||||||
mail_auto_delete=mail_auto_delete,
|
**kwargs,
|
||||||
**kwargs
|
|
||||||
)
|
)
|
||||||
|
@ -3,3 +3,6 @@
|
|||||||
* Pedro M. Baeza
|
* Pedro M. Baeza
|
||||||
* João Marques
|
* João Marques
|
||||||
* Carlos Roca
|
* Carlos Roca
|
||||||
|
|
||||||
|
* Versada <https://versada.eu>
|
||||||
|
* Naglis Jonaitis
|
||||||
|
@ -2,16 +2,22 @@
|
|||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
# pylint: disable=C8107
|
# pylint: disable=C8107
|
||||||
from odoo.tests import common
|
from odoo.tests import common
|
||||||
|
from odoo.tools import mute_logger
|
||||||
|
|
||||||
|
|
||||||
class TestMailNotificationCustomSubject(common.TransactionCase):
|
class TestMailNotificationCustomSubject(common.SavepointCase):
|
||||||
def setUp(self):
|
@classmethod
|
||||||
super().setUp()
|
def setUpClass(cls):
|
||||||
self.partner_1 = self.env["res.partner"].create(
|
super().setUpClass()
|
||||||
{"name": "Test partner 1", "email": "partner1@example.com"}
|
cls.partner_1, cls.partner_2 = (
|
||||||
)
|
cls.env["res.partner"]
|
||||||
self.partner_2 = self.env["res.partner"].create(
|
.with_context(tracking_disable=True)
|
||||||
{"name": "Test partner 2", "email": "partner2@example.com"}
|
.create(
|
||||||
|
[
|
||||||
|
{"name": "Test partner 1", "email": "partner1@example.com"},
|
||||||
|
{"name": "Test partner 2", "email": "partner2@example.com"},
|
||||||
|
]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_email_subject_template_overrides(self):
|
def test_email_subject_template_overrides(self):
|
||||||
@ -25,24 +31,24 @@ 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"
|
body="Test", subtype_xmlid="mail.mt_comment"
|
||||||
)
|
)
|
||||||
# Get message and check subject
|
# Get message and check subject
|
||||||
self.assertEquals(mail_message_1.subject, "Test partner 1 and something more")
|
self.assertEqual(mail_message_1.subject, "Test partner 1 and something more")
|
||||||
|
|
||||||
# Send message in partner 2
|
# Send message in partner 2
|
||||||
mail_message_2 = self.partner_2.message_post(
|
mail_message_2 = self.partner_2.message_post(
|
||||||
body="Test", subtype="mail.mt_comment"
|
body="Test", subtype_xmlid="mail.mt_comment"
|
||||||
)
|
)
|
||||||
# Get message and check subject
|
# Get message and check subject
|
||||||
self.assertEquals(mail_message_2.subject, "Test partner 2 and something more")
|
self.assertEqual(mail_message_2.subject, "Test partner 2 and something more")
|
||||||
|
|
||||||
# Explicit subject should also be overwritten
|
# Explicit subject should also be overwritten
|
||||||
mail_message_3 = self.partner_2.message_post(
|
mail_message_3 = self.partner_2.message_post(
|
||||||
body="Test", subtype="mail.mt_comment", subject="Test"
|
body="Test", subtype_xmlid="mail.mt_comment", subject="Test"
|
||||||
)
|
)
|
||||||
# Get message and check subject
|
# Get message and check subject
|
||||||
self.assertEquals(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):
|
||||||
self.env["mail.message.custom.subject"].create(
|
self.env["mail.message.custom.subject"].create(
|
||||||
@ -55,10 +61,10 @@ class TestMailNotificationCustomSubject(common.TransactionCase):
|
|||||||
)
|
)
|
||||||
# Send note in partner
|
# Send note in partner
|
||||||
mail_message_1 = self.partner_1.message_post(
|
mail_message_1 = self.partner_1.message_post(
|
||||||
body="Test", subtype="mail.mt_note", subject="Test"
|
body="Test", subtype_xmlid="mail.mt_note", subject="Test"
|
||||||
)
|
)
|
||||||
# Get message and check subject. Subject Template should not apply
|
# Get message and check subject. Subject Template should not apply
|
||||||
self.assertEquals(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):
|
||||||
self.env["mail.message.custom.subject"].create(
|
self.env["mail.message.custom.subject"].create(
|
||||||
@ -79,10 +85,10 @@ 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"
|
body="Test", subtype_xmlid="mail.mt_comment"
|
||||||
)
|
)
|
||||||
# Get message and check subject
|
# Get message and check subject
|
||||||
self.assertEquals(
|
self.assertEqual(
|
||||||
mail_message_1.subject, "Test partner 1 and something different"
|
mail_message_1.subject, "Test partner 1 and something different"
|
||||||
)
|
)
|
||||||
self.env["mail.message.custom.subject"].create(
|
self.env["mail.message.custom.subject"].create(
|
||||||
@ -96,10 +102,10 @@ class TestMailNotificationCustomSubject(common.TransactionCase):
|
|||||||
)
|
)
|
||||||
# Send message in partner
|
# Send message in partner
|
||||||
mail_message_2 = self.partner_1.message_post(
|
mail_message_2 = self.partner_1.message_post(
|
||||||
body="Test", subtype="mail.mt_comment"
|
body="Test", subtype_xmlid="mail.mt_comment"
|
||||||
)
|
)
|
||||||
# Get message and check subject
|
# Get message and check subject
|
||||||
self.assertEquals(
|
self.assertEqual(
|
||||||
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",
|
||||||
)
|
)
|
||||||
@ -114,10 +120,10 @@ class TestMailNotificationCustomSubject(common.TransactionCase):
|
|||||||
)
|
)
|
||||||
# Send message in partner
|
# Send message in partner
|
||||||
mail_message_3 = self.partner_1.message_post(
|
mail_message_3 = self.partner_1.message_post(
|
||||||
body="Test", subtype="mail.mt_comment"
|
body="Test", subtype_xmlid="mail.mt_comment"
|
||||||
)
|
)
|
||||||
# Get message and check subject
|
# Get message and check subject
|
||||||
self.assertEquals(
|
self.assertEqual(
|
||||||
mail_message_3.subject,
|
mail_message_3.subject,
|
||||||
"Re: Test partner 1 and something different and yet something else",
|
"Re: Test partner 1 and something different and yet something else",
|
||||||
)
|
)
|
||||||
@ -135,11 +141,11 @@ 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",
|
body="Test",
|
||||||
subtype="mail.mt_comment",
|
subtype_xmlid="mail.mt_comment",
|
||||||
subject="Test",
|
subject="Test",
|
||||||
)
|
)
|
||||||
# Get message and check subject
|
# Get message and check subject
|
||||||
self.assertEquals(mail_message_1.subject, "Test and something more")
|
self.assertEqual(mail_message_1.subject, "Test and something more")
|
||||||
|
|
||||||
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."""
|
||||||
@ -153,20 +159,21 @@ class TestMailNotificationCustomSubject(common.TransactionCase):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
# Send message in partner
|
# Send message in partner
|
||||||
mail_message_1 = self.partner_1.message_post(
|
with mute_logger("odoo.addons.mail.models.mail_render_mixin"):
|
||||||
body="Test",
|
mail_message_1 = self.partner_1.message_post(
|
||||||
subtype="mail.mt_comment",
|
body="Test",
|
||||||
subject="Test",
|
subtype_xmlid="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.
|
||||||
self.assertEquals(mail_message_1.subject, "Test")
|
self.assertEqual(mail_message_1.subject, "Test")
|
||||||
|
|
||||||
def test_no_template_default_result(self):
|
def test_no_template_default_result(self):
|
||||||
# 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 partner 1"
|
body="Test", subtype_xmlid="mail.mt_comment", subject="Test partner 1"
|
||||||
)
|
)
|
||||||
# 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.
|
||||||
self.assertEquals(mail_message_1.subject, "Test partner 1")
|
self.assertEqual(mail_message_1.subject, "Test partner 1")
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
name="subject_template"
|
name="subject_template"
|
||||||
placeholder="Subject (placeholders may be used here)"
|
placeholder="Subject (placeholders may be used here)"
|
||||||
/>
|
/>
|
||||||
<field name="model_id" />
|
<field name="model_id" options="{'no_create': True}" />
|
||||||
<field name="subtype_ids" widget="many2many_tags" />
|
<field name="subtype_ids" widget="many2many_tags" />
|
||||||
<field name="position" />
|
<field name="position" />
|
||||||
</group>
|
</group>
|
||||||
@ -29,7 +29,7 @@
|
|||||||
<field name="name">mail.message.custom.subject.tree</field>
|
<field name="name">mail.message.custom.subject.tree</field>
|
||||||
<field name="model">mail.message.custom.subject</field>
|
<field name="model">mail.message.custom.subject</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree string="Templates">
|
<tree>
|
||||||
<field name="name" />
|
<field name="name" />
|
||||||
<field name="model_id" />
|
<field name="model_id" />
|
||||||
<field name="subtype_ids" />
|
<field name="subtype_ids" />
|
||||||
|
Loading…
Reference in New Issue
Block a user