diff --git a/mail_notification_custom_subject/README.rst b/mail_notification_custom_subject/README.rst new file mode 100644 index 0000000000..aecd280f2e --- /dev/null +++ b/mail_notification_custom_subject/README.rst @@ -0,0 +1,123 @@ +================================ +Mail Notification Custom Subject +================================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:b873c6dfb9d094a1b5ebcd5c16a0c39a2127f4e7707aa54dd51dd4049f65d3fe + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/16.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-16-0/social-16-0-mail_notification_custom_subject + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/social&target_branch=16.0 + :alt: Try me on Runboat + +|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 `Jinja `__ 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 to smash 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 + * Carlos Roca + * Víctor Martínez + +* Versada + * Naglis Jonaitis + +* Moduon + * Eduardo de Miguel + +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-yajo| image:: https://github.com/yajo.png?size=40px + :target: https://github.com/yajo + :alt: yajo +.. |maintainer-edlopen| image:: https://github.com/edlopen.png?size=40px + :target: https://github.com/edlopen + :alt: edlopen +.. |maintainer-rafaelbn| image:: https://github.com/rafaelbn.png?size=40px + :target: https://github.com/rafaelbn + :alt: rafaelbn + +Current `maintainers `__: + +|maintainer-yajo| |maintainer-edlopen| |maintainer-rafaelbn| + +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 0000000000..0650744f6b --- /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 0000000000..71e2097ab5 --- /dev/null +++ b/mail_notification_custom_subject/__manifest__.py @@ -0,0 +1,21 @@ +# 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": "16.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": ["yajo", "edlopen", "rafaelbn"], +} diff --git a/mail_notification_custom_subject/i18n/es.po b/mail_notification_custom_subject/i18n/es.po new file mode 100644 index 0000000000..03ff0f0539 --- /dev/null +++ b/mail_notification_custom_subject/i18n/es.po @@ -0,0 +1,129 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_notification_custom_subject +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-10-28 13:30+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: mail_notification_custom_subject +#: model:ir.model.fields.selection,name:mail_notification_custom_subject.selection__mail_message_custom_subject__position__append_after +msgid "Append After" +msgstr "Añadir Después" + +#. module: mail_notification_custom_subject +#: model:ir.model.fields.selection,name:mail_notification_custom_subject.selection__mail_message_custom_subject__position__append_before +msgid "Append Before" +msgstr "Añadir antes de" + +#. 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 "Subtipos Aplicados" + +#. 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 "Creado por" + +#. 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 "Creado el" + +#. 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 "Mostrar Nombre" + +#. 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 +#: model:ir.model.fields,field_description:mail_notification_custom_subject.field_mail_message_custom_subject__id +msgid "ID" +msgstr "ID (identificación)" + +#. 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 "Última Modificación el" + +#. 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 "Actualizado por Última vez por" + +#. 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 "Última Actualización el" + +#. module: mail_notification_custom_subject +#: model:ir.model,name:mail_notification_custom_subject.model_mail_message_custom_subject +msgid "Mail Message Custom Subject" +msgstr "Mensaje de correo Asunto personalizado" + +#. 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 "Modelo" + +#. 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 "Modelo al que se aplica esta plantilla" + +#. module: mail_notification_custom_subject +#: model:ir.model.fields,field_description:mail_notification_custom_subject.field_mail_message_custom_subject__position +msgid "Position" +msgstr "Posición" + +#. module: mail_notification_custom_subject +#: model:ir.model.fields.selection,name:mail_notification_custom_subject.selection__mail_message_custom_subject__position__replace +msgid "Replace" +msgstr "Reemplazar" + +#. 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 "Asunto (pueden utilizarse marcadores de posición)" + +#. 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 Temas" + +#. 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 "Tema Plantilla" + +#. 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 "Nombre de Plantilla" + +#. 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 "" +"Si reemplazar, añadir al principio o añadir al final a otras plantillas que " +"se aplican a un contexto determinado" 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 0000000000..680c521d33 --- /dev/null +++ b/mail_notification_custom_subject/i18n/es_ES.po @@ -0,0 +1,135 @@ +# 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-02-16 10:56+0000\n" +"PO-Revision-Date: 2021-02-16 11:56+0100\n" +"Last-Translator: Carlos \n" +"Language-Team: \n" +"Language: es_ES\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.0.6\n" + +#. module: mail_notification_custom_subject +#: model:ir.model.fields.selection,name:mail_notification_custom_subject.selection__mail_message_custom_subject__position__append_after +msgid "Append After" +msgstr "Añadir después" + +#. module: mail_notification_custom_subject +#: model:ir.model.fields.selection,name:mail_notification_custom_subject.selection__mail_message_custom_subject__position__append_before +msgid "Append Before" +msgstr "Añadir antes" + +#. 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 "Subtipos aplicados" + +#. 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 "Creado por" + +#. 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 "Creado el" + +#. 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 "Nombre mostrado" + +#. 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 +#: model:ir.model.fields,field_description:mail_notification_custom_subject.field_mail_message_custom_subject__id +msgid "ID" +msgstr "ID" + +#. 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 "Última modificación el" + +#. 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 "Última modificación por" + +#. 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 "Última actualización el" + +#. 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 +#: model:ir.model.fields,field_description:mail_notification_custom_subject.field_mail_message_custom_subject__model_id +msgid "Model" +msgstr "Modelo" + +#. 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 "Modelo en el que se aplica la plantilla" + +#. module: mail_notification_custom_subject +#: model:ir.model.fields,field_description:mail_notification_custom_subject.field_mail_message_custom_subject__position +msgid "Position" +msgstr "Posición" + +#. module: mail_notification_custom_subject +#: model:ir.model.fields.selection,name:mail_notification_custom_subject.selection__mail_message_custom_subject__position__replace +msgid "Replace" +msgstr "Sustituir" + +#. 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 "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:ir.model.fields,field_description:mail_notification_custom_subject.field_mail_message_custom_subject__subject_template +#, fuzzy +msgid "Subject Template" +msgstr "Plantillas de Sustitución de Asuntos" + +#. module: mail_notification_custom_subject +#: model:ir.model.fields,field_description:mail_notification_custom_subject.field_mail_message_custom_subject__name +#, fuzzy +msgid "Template Name" +msgstr "Plantillas" + +#. 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 "" +"Ya sea para reemplazar, agregar al principio o agregar al final a otras " +"plantillas que se aplican a un contexto determinado" + +#~ 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 0000000000..50d826a7b5 --- /dev/null +++ b/mail_notification_custom_subject/i18n/mail_notification_custom_subject.pot @@ -0,0 +1,124 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_notification_custom_subject +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.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 +#: model:ir.model.fields.selection,name:mail_notification_custom_subject.selection__mail_message_custom_subject__position__append_after +msgid "Append After" +msgstr "" + +#. module: mail_notification_custom_subject +#: model:ir.model.fields.selection,name:mail_notification_custom_subject.selection__mail_message_custom_subject__position__append_before +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 +#: model:ir.model.fields.selection,name:mail_notification_custom_subject.selection__mail_message_custom_subject__position__replace +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: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 0000000000..3e5486eab2 --- /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 0000000000..4c8db6a8c2 --- /dev/null +++ b/mail_notification_custom_subject/models/mail_message_custom_subject.py @@ -0,0 +1,37 @@ +# 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", + ondelete="cascade", + ) + subtype_ids = fields.Many2many( + comodel_name="mail.message.subtype", + string="Applied Subtypes", + required=True, + ) + subject_template = fields.Char( + required=True, + help="Subject (placeholders may be used here)", + ) + position = fields.Selection( + selection=[ + ("append_before", "Append Before"), + ("append_after", "Append After"), + ("replace", "Replace"), + ], + 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 0000000000..8b97a636c1 --- /dev/null +++ b/mail_notification_custom_subject/models/mail_thread.py @@ -0,0 +1,89 @@ +# Copyright 2020-2021 Tecnativa - João Marques +# Copyright 2021 Tecnativa - Pedro M. Baeza +# Copyright 2022 Moduon - Eduardo de Miguel +# 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", + email_from=None, + author_id=None, + parent_id=False, + subtype_xmlid=None, + subtype_id=False, + partner_ids=None, + attachments=None, + attachment_ids=None, + add_sign=True, + record_name=False, + **kwargs + ): + if subtype_xmlid: + subtype_id = self.env["ir.model.data"]._xmlid_to_res_id( + subtype_xmlid, + raise_if_not_found=False, + ) + if not subtype_id: + subtype_id = self.env["ir.model.data"]._xmlid_to_res_id("mail.mt_note") + if subtype_id: + custom_subjects = ( + self.env["mail.message.custom.subject"] + .sudo() + .search( + [ + ("model_id.model", "=", self._name), + ("subtype_ids", "=", subtype_id), + ] + ) + .sudo(False) + ) + 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_src=template.subject_template, + model=self._name, + res_ids=[self.id], + )[ + 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, + email_from=email_from, + author_id=author_id, + parent_id=parent_id, + subtype_xmlid=subtype_xmlid, + subtype_id=subtype_id, + partner_ids=partner_ids, + attachments=attachments, + attachment_ids=attachment_ids, + add_sign=add_sign, + record_name=record_name, + **kwargs, + ) diff --git a/mail_notification_custom_subject/readme/CONFIGURE.rst b/mail_notification_custom_subject/readme/CONFIGURE.rst new file mode 100644 index 0000000000..c777ed3ae9 --- /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 `Jinja `__ 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 0000000000..f88a42efed --- /dev/null +++ b/mail_notification_custom_subject/readme/CONTRIBUTORS.rst @@ -0,0 +1,12 @@ +* Tecnativa + + * Pedro M. Baeza + * João Marques + * Carlos Roca + * Víctor Martínez + +* Versada + * Naglis Jonaitis + +* Moduon + * Eduardo de Miguel diff --git a/mail_notification_custom_subject/readme/DESCRIPTION.rst b/mail_notification_custom_subject/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..2b0727f1ad --- /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 0000000000..49bed60a72 --- /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 0000000000..bc15034ae6 --- /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 0000000000..3a0328b516 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 0000000000..7afebcf789 --- /dev/null +++ b/mail_notification_custom_subject/static/description/index.html @@ -0,0 +1,477 @@ + + + + + +Mail Notification Custom Subject + + + +
+

Mail Notification Custom Subject

+ + +

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

+

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 Jinja 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 to smash 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 maintainers:

+

yajo edlopen rafaelbn

+

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 0000000000..b0f2b2eff5 --- /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 0000000000..078e19d5a9 --- /dev/null +++ b/mail_notification_custom_subject/tests/test_mail_notification_custom_subject.py @@ -0,0 +1,193 @@ +# Copyright 2020 Tecnativa - João Marques +# Copyright 2022 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# pylint: disable=C8107 +from odoo.tests import common +from odoo.tools import mute_logger + + +class TestMailNotificationCustomSubject(common.TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.partner_1, cls.partner_2 = ( + cls.env["res.partner"] + .with_context(tracking_disable=True) + .create( + [ + {"name": "Test partner 1", "email": "partner1@example.com"}, + {"name": "Test partner 2", "email": "partner2@example.com"}, + ] + ) + ) + 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): + with self.with_user("boss"): + 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_xmlid="mail.mt_comment" + ) + # Get message and check subject + self.assertEqual(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_xmlid="mail.mt_comment" + ) + # Get message and check subject + self.assertEqual(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_xmlid="mail.mt_comment", subject="Test" + ) + # Get message and check subject + self.assertEqual(mail_message_3.subject, "Test partner 2 and something more") + + def test_email_subject_template_normal(self): + with self.with_user("boss"): + 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_xmlid="mail.mt_note", subject="Test" + ) + # Get message and check subject. Subject Template should not apply + self.assertEqual(mail_message_1.subject, "Test") + + def test_email_subject_template_multi(self): + with self.with_user("boss"): + 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", + } + ) + with self.with_user("boss"): + 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_xmlid="mail.mt_comment" + ) + # Get message and check subject + self.assertEqual( + mail_message_1.subject, "Test partner 1 and something different" + ) + with self.with_user("boss"): + 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_xmlid="mail.mt_comment" + ) + # Get message and check subject + self.assertEqual( + mail_message_2.subject, + "Test partner 1 and something different and yet something else", + ) + with self.with_user("boss"): + 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_xmlid="mail.mt_comment" + ) + # Get message and check subject + self.assertEqual( + mail_message_3.subject, + "Re: Test partner 1 and something different and yet something else", + ) + + def test_email_subject_template_w_original(self): + with self.with_user("boss"): + 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_xmlid="mail.mt_comment", + subject="Test", + ) + # Get message and check subject + self.assertEqual(mail_message_1.subject, "Test and something more") + + def test_bad_template_does_not_break(self): + """Create template with error (obaject) to test error.""" + with self.with_user("boss"): + 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 + with mute_logger("odoo.addons.mail.models.mail_render_mixin"): + mail_message_1 = self.partner_1.message_post( + body="Test", + subtype_xmlid="mail.mt_comment", + subject="Test", + ) + # Get message and check subject + # No exception should be raised but subject should remain as original. + self.assertEqual(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_xmlid="mail.mt_comment", subject="Test partner 1" + ) + # Get message and check subject + # No exception should be raised but subject should remain as original. + self.assertEqual(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 0000000000..3267af9fbb --- /dev/null +++ b/mail_notification_custom_subject/views/mail_notification_custom_subject_views.xml @@ -0,0 +1,53 @@ + + + + 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,tree + + + +
diff --git a/setup/mail_notification_custom_subject/odoo/addons/mail_notification_custom_subject b/setup/mail_notification_custom_subject/odoo/addons/mail_notification_custom_subject new file mode 120000 index 0000000000..5212ccad70 --- /dev/null +++ b/setup/mail_notification_custom_subject/odoo/addons/mail_notification_custom_subject @@ -0,0 +1 @@ +../../../../mail_notification_custom_subject \ No newline at end of file diff --git a/setup/mail_notification_custom_subject/setup.py b/setup/mail_notification_custom_subject/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/mail_notification_custom_subject/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)