[IMP] mail_notification_custom_subject: black, isort, prettier
This commit is contained in:
parent
586be98e65
commit
1bb5aee507
@ -7,13 +7,11 @@
|
|||||||
"summary": "Apply a custom subject to mail notifications",
|
"summary": "Apply a custom subject to mail notifications",
|
||||||
"version": "12.0.1.0.0",
|
"version": "12.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)",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"installable": True,
|
"installable": True,
|
||||||
"depends": [
|
"depends": ["mail"],
|
||||||
"mail",
|
|
||||||
],
|
|
||||||
"data": [
|
"data": [
|
||||||
"security/ir.model.access.csv",
|
"security/ir.model.access.csv",
|
||||||
"views/mail_notification_custom_subject_views.xml",
|
"views/mail_notification_custom_subject_views.xml",
|
||||||
|
@ -16,9 +16,7 @@ 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",
|
comodel_name="mail.message.subtype", string="Applied Subtypes", required=True,
|
||||||
string="Applied Subtypes",
|
|
||||||
required=True,
|
|
||||||
)
|
)
|
||||||
subject_template = fields.Char(
|
subject_template = fields.Char(
|
||||||
string="Subject Template",
|
string="Subject Template",
|
||||||
|
@ -23,25 +23,21 @@ class MailThread(models.AbstractModel):
|
|||||||
mail_auto_delete=True,
|
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:
|
||||||
subtype = subtype or 'mt_note'
|
subtype = subtype or "mt_note"
|
||||||
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 = "Re: %s" % self.env["mail.message"].with_context(
|
||||||
default_model=self._name,
|
default_model=self._name, default_res_id=self.id,
|
||||||
default_res_id=self.id,
|
|
||||||
)._get_record_name({})
|
)._get_record_name({})
|
||||||
for template in custom_subjects:
|
for template in custom_subjects:
|
||||||
try:
|
try:
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Copyright 2020 Tecnativa - João Marques
|
# Copyright 2020 Tecnativa - João Marques
|
||||||
# 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
|
||||||
from odoo.tests import common
|
from odoo.tests import common
|
||||||
|
|
||||||
|
|
||||||
@ -27,15 +27,7 @@ class TestMailNotificationCustomSubject(common.TransactionCase):
|
|||||||
{
|
{
|
||||||
"name": "Test template 1",
|
"name": "Test template 1",
|
||||||
"model_id": self.env.ref("base.model_res_partner").id,
|
"model_id": self.env.ref("base.model_res_partner").id,
|
||||||
"subtype_ids": [
|
"subtype_ids": [(6, 0, [self.env.ref("mail.mt_comment").id])],
|
||||||
(
|
|
||||||
6,
|
|
||||||
0,
|
|
||||||
[
|
|
||||||
self.env.ref("mail.mt_comment").id,
|
|
||||||
],
|
|
||||||
)
|
|
||||||
],
|
|
||||||
"subject_template": "${object.name or 'n/a'} and something more",
|
"subject_template": "${object.name or 'n/a'} and something more",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -65,15 +57,7 @@ class TestMailNotificationCustomSubject(common.TransactionCase):
|
|||||||
{
|
{
|
||||||
"name": "Test template 1",
|
"name": "Test template 1",
|
||||||
"model_id": self.env.ref("base.model_res_partner").id,
|
"model_id": self.env.ref("base.model_res_partner").id,
|
||||||
"subtype_ids": [
|
"subtype_ids": [(6, 0, [self.env.ref("mail.mt_comment").id])],
|
||||||
(
|
|
||||||
6,
|
|
||||||
0,
|
|
||||||
[
|
|
||||||
self.env.ref("mail.mt_comment").id,
|
|
||||||
],
|
|
||||||
)
|
|
||||||
],
|
|
||||||
"subject_template": "${object.name or 'n/a'} and something more",
|
"subject_template": "${object.name or 'n/a'} and something more",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -89,15 +73,7 @@ class TestMailNotificationCustomSubject(common.TransactionCase):
|
|||||||
{
|
{
|
||||||
"name": "Test template 1",
|
"name": "Test template 1",
|
||||||
"model_id": self.env.ref("base.model_res_partner").id,
|
"model_id": self.env.ref("base.model_res_partner").id,
|
||||||
"subtype_ids": [
|
"subtype_ids": [(6, 0, [self.env.ref("mail.mt_comment").id])],
|
||||||
(
|
|
||||||
6,
|
|
||||||
0,
|
|
||||||
[
|
|
||||||
self.env.ref("mail.mt_comment").id,
|
|
||||||
],
|
|
||||||
)
|
|
||||||
],
|
|
||||||
"subject_template": "${object.name or 'n/a'} and something more",
|
"subject_template": "${object.name or 'n/a'} and something more",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -105,15 +81,7 @@ class TestMailNotificationCustomSubject(common.TransactionCase):
|
|||||||
{
|
{
|
||||||
"name": "Test template 2",
|
"name": "Test template 2",
|
||||||
"model_id": self.env.ref("base.model_res_partner").id,
|
"model_id": self.env.ref("base.model_res_partner").id,
|
||||||
"subtype_ids": [
|
"subtype_ids": [(6, 0, [self.env.ref("mail.mt_comment").id])],
|
||||||
(
|
|
||||||
6,
|
|
||||||
0,
|
|
||||||
[
|
|
||||||
self.env.ref("mail.mt_comment").id,
|
|
||||||
],
|
|
||||||
)
|
|
||||||
],
|
|
||||||
"subject_template": "${object.name or 'n/a'} and something different",
|
"subject_template": "${object.name or 'n/a'} and something different",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -129,15 +97,7 @@ class TestMailNotificationCustomSubject(common.TransactionCase):
|
|||||||
{
|
{
|
||||||
"name": "Test template 3",
|
"name": "Test template 3",
|
||||||
"model_id": self.env.ref("base.model_res_partner").id,
|
"model_id": self.env.ref("base.model_res_partner").id,
|
||||||
"subtype_ids": [
|
"subtype_ids": [(6, 0, [self.env.ref("mail.mt_comment").id])],
|
||||||
(
|
|
||||||
6,
|
|
||||||
0,
|
|
||||||
[
|
|
||||||
self.env.ref("mail.mt_comment").id,
|
|
||||||
],
|
|
||||||
)
|
|
||||||
],
|
|
||||||
"subject_template": "${' and yet something else'}",
|
"subject_template": "${' and yet something else'}",
|
||||||
"position": "append_after",
|
"position": "append_after",
|
||||||
}
|
}
|
||||||
@ -155,15 +115,7 @@ class TestMailNotificationCustomSubject(common.TransactionCase):
|
|||||||
{
|
{
|
||||||
"name": "Test template 4",
|
"name": "Test template 4",
|
||||||
"model_id": self.env.ref("base.model_res_partner").id,
|
"model_id": self.env.ref("base.model_res_partner").id,
|
||||||
"subtype_ids": [
|
"subtype_ids": [(6, 0, [self.env.ref("mail.mt_comment").id])],
|
||||||
(
|
|
||||||
6,
|
|
||||||
0,
|
|
||||||
[
|
|
||||||
self.env.ref("mail.mt_comment").id,
|
|
||||||
],
|
|
||||||
)
|
|
||||||
],
|
|
||||||
"subject_template": "${'Re: '}",
|
"subject_template": "${'Re: '}",
|
||||||
"position": "append_before",
|
"position": "append_before",
|
||||||
}
|
}
|
||||||
@ -183,15 +135,7 @@ class TestMailNotificationCustomSubject(common.TransactionCase):
|
|||||||
{
|
{
|
||||||
"name": "Test template 1",
|
"name": "Test template 1",
|
||||||
"model_id": self.env.ref("base.model_res_partner").id,
|
"model_id": self.env.ref("base.model_res_partner").id,
|
||||||
"subtype_ids": [
|
"subtype_ids": [(6, 0, [self.env.ref("mail.mt_comment").id])],
|
||||||
(
|
|
||||||
6,
|
|
||||||
0,
|
|
||||||
[
|
|
||||||
self.env.ref("mail.mt_comment").id,
|
|
||||||
],
|
|
||||||
)
|
|
||||||
],
|
|
||||||
"subject_template": "${' and something more'}",
|
"subject_template": "${' and something more'}",
|
||||||
"position": "append_after",
|
"position": "append_after",
|
||||||
}
|
}
|
||||||
@ -201,24 +145,14 @@ class TestMailNotificationCustomSubject(common.TransactionCase):
|
|||||||
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(
|
self.assertEquals(mail_message_1.subject, "Test and something more")
|
||||||
mail_message_1.subject, "Test and something more"
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_bad_template_does_not_break(self):
|
def test_bad_template_does_not_break(self):
|
||||||
self.env["mail.message.custom.subject"].create(
|
self.env["mail.message.custom.subject"].create(
|
||||||
{
|
{
|
||||||
"name": "Test bad template 1",
|
"name": "Test bad template 1",
|
||||||
"model_id": self.env.ref("base.model_res_partner").id,
|
"model_id": self.env.ref("base.model_res_partner").id,
|
||||||
"subtype_ids": [
|
"subtype_ids": [(6, 0, [self.env.ref("mail.mt_comment").id])],
|
||||||
(
|
|
||||||
6,
|
|
||||||
0,
|
|
||||||
[
|
|
||||||
self.env.ref("mail.mt_comment").id,
|
|
||||||
],
|
|
||||||
)
|
|
||||||
],
|
|
||||||
"subject_template": "${obaject.number_a} and something",
|
"subject_template": "${obaject.number_a} and something",
|
||||||
"position": "append_after",
|
"position": "append_after",
|
||||||
}
|
}
|
||||||
@ -229,9 +163,7 @@ class TestMailNotificationCustomSubject(common.TransactionCase):
|
|||||||
)
|
)
|
||||||
# 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(
|
self.assertEquals(mail_message_1.subject, "Test")
|
||||||
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
|
||||||
@ -240,6 +172,4 @@ class TestMailNotificationCustomSubject(common.TransactionCase):
|
|||||||
)
|
)
|
||||||
# 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(
|
self.assertEquals(mail_message_1.subject, "Test partner 1")
|
||||||
mail_message_1.subject, "Test partner 1"
|
|
||||||
)
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<odoo>
|
<odoo>
|
||||||
<data>
|
<data>
|
||||||
<record model="ir.ui.view" id="mail_notification_custom_subject_form">
|
<record model="ir.ui.view" id="mail_notification_custom_subject_form">
|
||||||
@ -8,14 +8,17 @@
|
|||||||
<form string="Subject Replacement Templates">
|
<form string="Subject Replacement Templates">
|
||||||
<sheet>
|
<sheet>
|
||||||
<div class="oe_title">
|
<div class="oe_title">
|
||||||
<label for="name" class="oe_edit_only"/>
|
<label for="name" class="oe_edit_only" />
|
||||||
<h1 name="name"><field name="name"/></h1>
|
<h1 name="name"><field name="name" /></h1>
|
||||||
</div>
|
</div>
|
||||||
<group>
|
<group>
|
||||||
<field name="subject_template" placeholder="Subject (placeholders may be used here)"/>
|
<field
|
||||||
<field name="model_id"/>
|
name="subject_template"
|
||||||
|
placeholder="Subject (placeholders may be used here)"
|
||||||
|
/>
|
||||||
|
<field name="model_id" />
|
||||||
<field name="subtype_ids" widget="many2many_tags" />
|
<field name="subtype_ids" widget="many2many_tags" />
|
||||||
<field name="position"/>
|
<field name="position" />
|
||||||
</group>
|
</group>
|
||||||
</sheet>
|
</sheet>
|
||||||
</form>
|
</form>
|
||||||
@ -27,15 +30,18 @@
|
|||||||
<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 string="Templates">
|
||||||
<field name="name"/>
|
<field name="name" />
|
||||||
<field name="model_id"/>
|
<field name="model_id" />
|
||||||
<field name="subtype_ids"/>
|
<field name="subtype_ids" />
|
||||||
<field name="subject_template"/>
|
<field name="subject_template" />
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record model="ir.actions.act_window" id="action_mail_notification_custom_subject_tree_all">
|
<record
|
||||||
|
model="ir.actions.act_window"
|
||||||
|
id="action_mail_notification_custom_subject_tree_all"
|
||||||
|
>
|
||||||
<field name="name">Subject Replacement Templates</field>
|
<field name="name">Subject Replacement Templates</field>
|
||||||
<field name="res_model">mail.message.custom.subject</field>
|
<field name="res_model">mail.message.custom.subject</field>
|
||||||
<field name="view_type">form</field>
|
<field name="view_type">form</field>
|
||||||
@ -43,8 +49,12 @@
|
|||||||
<field name="view_id" ref="mail_notification_custom_subject_tree" />
|
<field name="view_id" ref="mail_notification_custom_subject_tree" />
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<menuitem id="menu_mail_notification_custom_subject" parent="base.menu_email" action="action_mail_notification_custom_subject_tree_all"
|
<menuitem
|
||||||
sequence="21"/>
|
id="menu_mail_notification_custom_subject"
|
||||||
|
parent="base.menu_email"
|
||||||
|
action="action_mail_notification_custom_subject_tree_all"
|
||||||
|
sequence="21"
|
||||||
|
/>
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
Loading…
Reference in New Issue
Block a user