diff --git a/mail_notification_custom_subject/README.rst b/mail_notification_custom_subject/README.rst new file mode 100644 index 0000000..4aa6426 --- /dev/null +++ b/mail_notification_custom_subject/README.rst @@ -0,0 +1,106 @@ +================================ +Mail Notification Custom Subject +================================ + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png + :target: https://odoo-community.org/page/development-status + :alt: Production/Stable +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github + :target: https://github.com/OCA/social/tree/12.0/mail_notification_custom_subject + :alt: OCA/social +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/social-12-0/social-12-0-mail_notification_custom_subject + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/205/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows you to specify templates to override the subject on the notification +emails sent by Odoo + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + + +* Activate access to **Technical Features** (debug mode). +* Go to **Settings > Technical > Email > Subject Replacement Templates** +* Create a new template. + + * The field **Model** specifies the model to which the subject template should apply in the notification emails sent by Odoo. + * The field **Subject Template** accepts `Jinjah` expressions. + * The field **Replace** specifies if the template should replace existing content or append to it. + +Usage +===== + +To use this module, you need to: + +* Open the chatter in Odoo (e.g. Open an Invoice). +* Send a message. +* Observe the rendered Subject template. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* Tecnativa + + * Pedro M. Baeza + * João Marques + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-joao-p-marques| image:: https://github.com/joao-p-marques.png?size=40px + :target: https://github.com/joao-p-marques + :alt: joao-p-marques + +Current `maintainer `__: + +|maintainer-joao-p-marques| + +This module is part of the `OCA/social `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_notification_custom_subject/__init__.py b/mail_notification_custom_subject/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/mail_notification_custom_subject/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mail_notification_custom_subject/__manifest__.py b/mail_notification_custom_subject/__manifest__.py new file mode 100644 index 0000000..1c970d3 --- /dev/null +++ b/mail_notification_custom_subject/__manifest__.py @@ -0,0 +1,23 @@ +# Copyright 2020-2021 Tecnativa - João Marques +# Copyright 2021 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Mail Notification Custom Subject", + "summary": "Apply a custom subject to mail notifications", + "version": "12.0.1.0.0", + "category": "Social Network", + "website": "https://github.com/OCA/social/", + "author": "Tecnativa, Odoo Community Association (OCA)", + "license": "AGPL-3", + "installable": True, + "depends": [ + "mail", + ], + "data": [ + "security/ir.model.access.csv", + "views/mail_notification_custom_subject_views.xml", + ], + "development_status": "Production/Stable", + "maintainers": ["joao-p-marques"], +} diff --git a/mail_notification_custom_subject/i18n/es_ES.po b/mail_notification_custom_subject/i18n/es_ES.po new file mode 100644 index 0000000..a1147e8 --- /dev/null +++ b/mail_notification_custom_subject/i18n/es_ES.po @@ -0,0 +1,69 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_notification_custom_subject +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2021-01-05 09:11+0000\n" +"PO-Revision-Date: 2021-01-05 09:17+0000\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 2.4.2\n" +"Last-Translator: \n" +"Language: es_ES\n" + +#. module: mail_notification_custom_subject +#: code:addons/mail_notification_custom_subject/models/mail_message_custom_subject.py:150 +#, python-format +msgid "Append After" +msgstr "Añadir después" + +#. module: mail_notification_custom_subject +#: code:addons/mail_notification_custom_subject/models/mail_message_custom_subject.py:149 +#, python-format +msgid "Append Before" +msgstr "Añadir antes" + +#. module: mail_notification_custom_subject +#: model:ir.model,name:mail_notification_custom_subject.model_mail_thread +msgid "Email Thread" +msgstr "Hilo de correo electrónico" + +#. module: mail_notification_custom_subject +#: code:addons/mail_notification_custom_subject/models/mail_message_custom_subject.py:238 +#, python-format +msgid "Failed to render template %r using values %r" +msgstr "Error al procesar la plantilla %r usando los valores %r" + +#. module: mail_notification_custom_subject +#: model:ir.model,name:mail_notification_custom_subject.model_mail_message_custom_subject +msgid "Mail Message Custom Subject" +msgstr "Asunto Personalizado en Mensaje de Correo" + +#. module: mail_notification_custom_subject +#: code:addons/mail_notification_custom_subject/models/mail_message_custom_subject.py:151 +#, python-format +msgid "Replace" +msgstr "Sustituir" + +#. module: mail_notification_custom_subject +#: model_terms:ir.ui.view,arch_db:mail_notification_custom_subject.mail_notification_custom_subject_form +msgid "Subject (placeholders may be used here)" +msgstr "Asunto (se pueden utilizar aquí expresiones de campos)" + +#. module: mail_notification_custom_subject +#: model:ir.actions.act_window,name:mail_notification_custom_subject.action_mail_notification_custom_subject_tree_all +#: model:ir.ui.menu,name:mail_notification_custom_subject.menu_mail_notification_custom_subject +#: model_terms:ir.ui.view,arch_db:mail_notification_custom_subject.mail_notification_custom_subject_form +msgid "Subject Replacement Templates" +msgstr "Plantillas de Sustitución de Asuntos" + +#. module: mail_notification_custom_subject +#: model_terms:ir.ui.view,arch_db:mail_notification_custom_subject.mail_notification_custom_subject_tree +msgid "Templates" +msgstr "Plantillas" diff --git a/mail_notification_custom_subject/i18n/mail_notification_custom_subject.pot b/mail_notification_custom_subject/i18n/mail_notification_custom_subject.pot new file mode 100644 index 0000000..5b48b08 --- /dev/null +++ b/mail_notification_custom_subject/i18n/mail_notification_custom_subject.pot @@ -0,0 +1,134 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_notification_custom_subject +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: mail_notification_custom_subject +#: code:addons/mail_notification_custom_subject/models/mail_message_custom_subject.py:31 +#: selection:mail.message.custom.subject,position:0 +#, python-format +msgid "Append After" +msgstr "" + +#. module: mail_notification_custom_subject +#: code:addons/mail_notification_custom_subject/models/mail_message_custom_subject.py:30 +#: selection:mail.message.custom.subject,position:0 +#, python-format +msgid "Append Before" +msgstr "" + +#. module: mail_notification_custom_subject +#: model:ir.model.fields,field_description:mail_notification_custom_subject.field_mail_message_custom_subject__subtype_ids +msgid "Applied Subtypes" +msgstr "" + +#. module: mail_notification_custom_subject +#: model:ir.model.fields,field_description:mail_notification_custom_subject.field_mail_message_custom_subject__create_uid +msgid "Created by" +msgstr "" + +#. module: mail_notification_custom_subject +#: model:ir.model.fields,field_description:mail_notification_custom_subject.field_mail_message_custom_subject__create_date +msgid "Created on" +msgstr "" + +#. module: mail_notification_custom_subject +#: model:ir.model.fields,field_description:mail_notification_custom_subject.field_mail_message_custom_subject__display_name +msgid "Display Name" +msgstr "" + +#. module: mail_notification_custom_subject +#: model:ir.model,name:mail_notification_custom_subject.model_mail_thread +msgid "Email Thread" +msgstr "" + +#. module: mail_notification_custom_subject +#: model:ir.model.fields,field_description:mail_notification_custom_subject.field_mail_message_custom_subject__id +msgid "ID" +msgstr "" + +#. module: mail_notification_custom_subject +#: model:ir.model.fields,field_description:mail_notification_custom_subject.field_mail_message_custom_subject____last_update +msgid "Last Modified on" +msgstr "" + +#. module: mail_notification_custom_subject +#: model:ir.model.fields,field_description:mail_notification_custom_subject.field_mail_message_custom_subject__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: mail_notification_custom_subject +#: model:ir.model.fields,field_description:mail_notification_custom_subject.field_mail_message_custom_subject__write_date +msgid "Last Updated on" +msgstr "" + +#. module: mail_notification_custom_subject +#: model:ir.model,name:mail_notification_custom_subject.model_mail_message_custom_subject +msgid "Mail Message Custom Subject" +msgstr "" + +#. module: mail_notification_custom_subject +#: model:ir.model.fields,field_description:mail_notification_custom_subject.field_mail_message_custom_subject__model_id +msgid "Model" +msgstr "" + +#. module: mail_notification_custom_subject +#: model:ir.model.fields,help:mail_notification_custom_subject.field_mail_message_custom_subject__model_id +msgid "Model where this template applies" +msgstr "" + +#. module: mail_notification_custom_subject +#: model:ir.model.fields,field_description:mail_notification_custom_subject.field_mail_message_custom_subject__position +msgid "Position" +msgstr "" + +#. module: mail_notification_custom_subject +#: code:addons/mail_notification_custom_subject/models/mail_message_custom_subject.py:32 +#: selection:mail.message.custom.subject,position:0 +#, python-format +msgid "Replace" +msgstr "" + +#. module: mail_notification_custom_subject +#: model:ir.model.fields,help:mail_notification_custom_subject.field_mail_message_custom_subject__subject_template +#: model_terms:ir.ui.view,arch_db:mail_notification_custom_subject.mail_notification_custom_subject_form +msgid "Subject (placeholders may be used here)" +msgstr "" + +#. module: mail_notification_custom_subject +#: model:ir.actions.act_window,name:mail_notification_custom_subject.action_mail_notification_custom_subject_tree_all +#: model:ir.ui.menu,name:mail_notification_custom_subject.menu_mail_notification_custom_subject +#: model_terms:ir.ui.view,arch_db:mail_notification_custom_subject.mail_notification_custom_subject_form +msgid "Subject Replacement Templates" +msgstr "" + +#. module: mail_notification_custom_subject +#: model:ir.model.fields,field_description:mail_notification_custom_subject.field_mail_message_custom_subject__subject_template +msgid "Subject Template" +msgstr "" + +#. module: mail_notification_custom_subject +#: model:ir.model.fields,field_description:mail_notification_custom_subject.field_mail_message_custom_subject__name +msgid "Template Name" +msgstr "" + +#. module: mail_notification_custom_subject +#: model_terms:ir.ui.view,arch_db:mail_notification_custom_subject.mail_notification_custom_subject_tree +msgid "Templates" +msgstr "" + +#. module: mail_notification_custom_subject +#: model:ir.model.fields,help:mail_notification_custom_subject.field_mail_message_custom_subject__position +msgid "Whether to replace, append at beggining or append at end to other templates that apply to a given context" +msgstr "" + diff --git a/mail_notification_custom_subject/models/__init__.py b/mail_notification_custom_subject/models/__init__.py new file mode 100644 index 0000000..3e5486e --- /dev/null +++ b/mail_notification_custom_subject/models/__init__.py @@ -0,0 +1,2 @@ +from . import mail_thread +from . import mail_message_custom_subject diff --git a/mail_notification_custom_subject/models/mail_message_custom_subject.py b/mail_notification_custom_subject/models/mail_message_custom_subject.py new file mode 100644 index 0000000..0fb5bbd --- /dev/null +++ b/mail_notification_custom_subject/models/mail_message_custom_subject.py @@ -0,0 +1,38 @@ +# Copyright 2020 Tecnativa - João Marques +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import _, fields, models + + +class MailMessageCustomSubject(models.Model): + _name = "mail.message.custom.subject" + _description = "Mail Message Custom Subject" + + name = fields.Char(string="Template Name") + model_id = fields.Many2one( + comodel_name="ir.model", + string="Model", + required=True, + help="Model where this template applies", + ) + subtype_ids = fields.Many2many( + comodel_name="mail.message.subtype", + string="Applied Subtypes", + required=True, + ) + subject_template = fields.Char( + string="Subject Template", + required=True, + help="Subject (placeholders may be used here)", + ) + position = fields.Selection( + selection=[ + ("append_before", _("Append Before")), + ("append_after", _("Append After")), + ("replace", _("Replace")), + ], + string="Position", + default="replace", + help="Whether to replace, append at beggining or append at end to other" + " templates that apply to a given context", + ) diff --git a/mail_notification_custom_subject/models/mail_thread.py b/mail_notification_custom_subject/models/mail_thread.py new file mode 100644 index 0000000..c26742e --- /dev/null +++ b/mail_notification_custom_subject/models/mail_thread.py @@ -0,0 +1,75 @@ +# Copyright 2020-2021 Tecnativa - João Marques +# Copyright 2021 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, models + + +class MailThread(models.AbstractModel): + _inherit = "mail.thread" + + @api.returns("mail.message", lambda value: value.id) + def message_post( + self, + body="", + subject=None, + message_type="notification", + subtype=None, + parent_id=False, + attachments=None, + notif_layout=False, + add_sign=True, + model_description=False, + mail_auto_delete=True, + **kwargs + ): + 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, 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), + ] + ) + if not subject: + 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: + rendered_subject_template = self.env[ + "mail.template" + ]._render_template( + template_txt=template.subject_template, + model=self._name, + res_ids=self.id, + ) + if template.position == "replace": + subject = rendered_subject_template + elif template.position == "append_before": + subject = rendered_subject_template + subject + elif template.position == "append_after": + subject += rendered_subject_template + except Exception: + rendered_subject_template = False + return super().message_post( + body=body, + subject=subject, + message_type=message_type, + subtype=subtype, + parent_id=parent_id, + attachments=attachments, + notif_layout=notif_layout, + add_sign=add_sign, + model_description=model_description, + mail_auto_delete=mail_auto_delete, + **kwargs + ) diff --git a/mail_notification_custom_subject/readme/CONFIGURE.rst b/mail_notification_custom_subject/readme/CONFIGURE.rst new file mode 100644 index 0000000..86bed07 --- /dev/null +++ b/mail_notification_custom_subject/readme/CONFIGURE.rst @@ -0,0 +1,8 @@ + +* Activate access to **Technical Features** (debug mode). +* Go to **Settings > Technical > Email > Subject Replacement Templates** +* Create a new template. + + * The field **Model** specifies the model to which the subject template should apply in the notification emails sent by Odoo. + * The field **Subject Template** accepts `Jinjah` expressions. + * The field **Replace** specifies if the template should replace existing content or append to it. diff --git a/mail_notification_custom_subject/readme/CONTRIBUTORS.rst b/mail_notification_custom_subject/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..b0f1687 --- /dev/null +++ b/mail_notification_custom_subject/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* Tecnativa + + * Pedro M. Baeza + * João Marques diff --git a/mail_notification_custom_subject/readme/DESCRIPTION.rst b/mail_notification_custom_subject/readme/DESCRIPTION.rst new file mode 100644 index 0000000..2b0727f --- /dev/null +++ b/mail_notification_custom_subject/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module allows you to specify templates to override the subject on the notification +emails sent by Odoo diff --git a/mail_notification_custom_subject/readme/USAGE.rst b/mail_notification_custom_subject/readme/USAGE.rst new file mode 100644 index 0000000..49bed60 --- /dev/null +++ b/mail_notification_custom_subject/readme/USAGE.rst @@ -0,0 +1,5 @@ +To use this module, you need to: + +* Open the chatter in Odoo (e.g. Open an Invoice). +* Send a message. +* Observe the rendered Subject template. diff --git a/mail_notification_custom_subject/security/ir.model.access.csv b/mail_notification_custom_subject/security/ir.model.access.csv new file mode 100644 index 0000000..bc15034 --- /dev/null +++ b/mail_notification_custom_subject/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_mail_notification_custom_subject_user,mail_notification_custom_object,model_mail_message_custom_subject,base.group_user,1,0,0,0 +access_mail_notification_custom_subject_admin,mail_notification_custom_object,model_mail_message_custom_subject,base.group_system,1,1,1,1 diff --git a/mail_notification_custom_subject/static/description/icon.png b/mail_notification_custom_subject/static/description/icon.png new file mode 100644 index 0000000..3a0328b Binary files /dev/null and b/mail_notification_custom_subject/static/description/icon.png differ diff --git a/mail_notification_custom_subject/static/description/index.html b/mail_notification_custom_subject/static/description/index.html new file mode 100644 index 0000000..21bf700 --- /dev/null +++ b/mail_notification_custom_subject/static/description/index.html @@ -0,0 +1,458 @@ + + + + + + +Mail Notification Custom Subject + + + +
+

Mail Notification Custom Subject

+ + +

Production/Stable License: AGPL-3 OCA/social Translate me on Weblate Try me on Runbot

+

This module allows you to specify templates to override the subject on the notification +emails sent by Odoo

+

Table of contents

+ +
+

Configuration

+
    +
  • Activate access to Technical Features (debug mode).

    +
  • +
  • Go to Settings > Technical > Email > Subject Replacement Templates

    +
  • +
  • Create a new template.

    +
    +
      +
    • The field Model specifies the model to which the subject template should apply in the notification emails sent by Odoo.
    • +
    • The field Subject Template accepts Jinjah<ttps://jinja.palletsprojects.com/en/2.11.x/> expressions.
    • +
    • The field Replace specifies if the template should replace existing content or append to it.
    • +
    +
    +
  • +
+
+
+

Usage

+

To use this module, you need to:

+
    +
  • Open the chatter in Odoo (e.g. Open an Invoice).
  • +
  • Send a message.
  • +
  • Observe the rendered Subject template.
  • +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainer:

+

joao-p-marques

+

This module is part of the OCA/social project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/mail_notification_custom_subject/tests/__init__.py b/mail_notification_custom_subject/tests/__init__.py new file mode 100644 index 0000000..b0f2b2e --- /dev/null +++ b/mail_notification_custom_subject/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mail_notification_custom_subject 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 new file mode 100644 index 0000000..7ecde6e --- /dev/null +++ b/mail_notification_custom_subject/tests/test_mail_notification_custom_subject.py @@ -0,0 +1,245 @@ +# Copyright 2020 Tecnativa - João Marques +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.tests import common + + +class TestMailNotificationCustomSubject(common.TransactionCase): + def setUp(self): + super(TestMailNotificationCustomSubject, self).setUp() + self.partner_1 = self.env["res.partner"].create( + { + "name": "Test partner 1", + "supplier": True, + "email": "partner1@example.com", + } + ) + self.partner_2 = self.env["res.partner"].create( + { + "name": "Test partner 2", + "supplier": True, + "email": "partner2@example.com", + } + ) + + def test_email_subject_template_overrides(self): + self.env["mail.message.custom.subject"].create( + { + "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, + ], + ) + ], + "subject_template": "${object.name or 'n/a'} and something more", + } + ) + # Send message in partner + mail_message_1 = self.partner_1.message_post( + body="Test", subtype="mail.mt_comment" + ) + # Get message and check subject + self.assertEquals(mail_message_1.subject, "Test partner 1 and something more") + + # Send message in partner 2 + mail_message_2 = self.partner_2.message_post( + body="Test", subtype="mail.mt_comment" + ) + # Get message and check subject + self.assertEquals(mail_message_2.subject, "Test partner 2 and something more") + + # Explicit subject should also be overwritten + mail_message_3 = self.partner_2.message_post( + body="Test", subtype="mail.mt_comment", subject="Test" + ) + # Get message and check subject + self.assertEquals(mail_message_3.subject, "Test partner 2 and something more") + + def test_email_subject_template_normal(self): + self.env["mail.message.custom.subject"].create( + { + "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, + ], + ) + ], + "subject_template": "${object.name or 'n/a'} and something more", + } + ) + # Send note in partner + mail_message_1 = self.partner_1.message_post( + body="Test", subtype="mail.mt_note", subject="Test" + ) + # Get message and check subject. Subject Template should not apply + self.assertEquals(mail_message_1.subject, "Test") + + def test_email_subject_template_multi(self): + self.env["mail.message.custom.subject"].create( + { + "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, + ], + ) + ], + "subject_template": "${object.name or 'n/a'} and something more", + } + ) + self.env["mail.message.custom.subject"].create( + { + "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, + ], + ) + ], + "subject_template": "${object.name or 'n/a'} and something different", + } + ) + # Send message in partner + mail_message_1 = self.partner_1.message_post( + body="Test", subtype="mail.mt_comment" + ) + # Get message and check subject + self.assertEquals( + mail_message_1.subject, "Test partner 1 and something different" + ) + self.env["mail.message.custom.subject"].create( + { + "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, + ], + ) + ], + "subject_template": "${' and yet something else'}", + "position": "append_after", + } + ) + # Send message in partner + mail_message_2 = self.partner_1.message_post( + body="Test", subtype="mail.mt_comment" + ) + # Get message and check subject + self.assertEquals( + mail_message_2.subject, + "Test partner 1 and something different and yet something else", + ) + self.env["mail.message.custom.subject"].create( + { + "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, + ], + ) + ], + "subject_template": "${'Re: '}", + "position": "append_before", + } + ) + # Send message in partner + mail_message_3 = self.partner_1.message_post( + body="Test", subtype="mail.mt_comment" + ) + # Get message and check subject + self.assertEquals( + mail_message_3.subject, + "Re: Test partner 1 and something different and yet something else", + ) + + def test_email_subject_template_w_original(self): + self.env["mail.message.custom.subject"].create( + { + "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, + ], + ) + ], + "subject_template": "${' and something more'}", + "position": "append_after", + } + ) + # Send message in partner + mail_message_1 = self.partner_1.message_post( + body="Test", subtype="mail.mt_comment", subject="Test", + ) + # Get message and check subject + 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, + ], + ) + ], + "subject_template": "${obaject.number_a} and something", + "position": "append_after", + } + ) + # Send message in partner + mail_message_1 = self.partner_1.message_post( + body="Test", subtype="mail.mt_comment", subject="Test", + ) + # Get message and check subject + # No exception should be raised but subject should remain as original. + self.assertEquals( + mail_message_1.subject, "Test" + ) + + def test_no_template_default_result(self): + # Send message in partner + mail_message_1 = self.partner_1.message_post( + body="Test", subtype="mail.mt_comment", subject="Test partner 1" + ) + # 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" + ) 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 new file mode 100644 index 0000000..7dd4e5a --- /dev/null +++ b/mail_notification_custom_subject/views/mail_notification_custom_subject_views.xml @@ -0,0 +1,50 @@ + + + + + mail.message.custom.subject.form + mail.message.custom.subject + +
+ +
+
+ + + + + + +
+
+
+
+ + + mail.message.custom.subject.tree + mail.message.custom.subject + + + + + + + + + + + + Subject Replacement Templates + mail.message.custom.subject + form + form,tree + + + + + +
+