From b1a5bf95f8ce26944959c97b760239d008efec95 Mon Sep 17 00:00:00 2001 From: mreficent Date: Mon, 23 Mar 2020 16:02:13 +0000 Subject: [PATCH] [IMP] mail: add a hook in _notify_record_by_email to add model-specific values PURPOSE Be able to customize notification email values in a given model by overriding a simple method instead of having to hijack the email creation process. SPECIFICATIONS Add a hook in mail.thread that can be overridden in specific addons, either by model or globally by inheriting mail.thread. Include _notify_email_headers in it so that it is correctly embedded in model-specific values computation. This removes the need to replace _notify_record_by_email long method in a custom module. Closes odoo/odoo#48213 Closes odoo/odoo#50097 closes odoo/odoo#50129 X-original-commit: 1ba8712d7a797cf2e821ae881cb1f1c4ea2fc11d Signed-off-by: Thibault Delavallee (tde) --- addons/mail/models/mail_thread.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 75ed62c8a8e..5e19ef8d75f 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -2270,9 +2270,7 @@ class MailThread(models.AbstractModel): 'references': message.parent_id.sudo().message_id if message.parent_id else False, 'subject': mail_subject, } - headers = self._notify_email_headers() - if headers: - base_mail_values['headers'] = headers + base_mail_values = self._notify_by_email_add_values(base_mail_values) Mail = self.env['mail.mail'].sudo() emails = self.env['mail.mail'].sudo() @@ -2425,6 +2423,19 @@ class MailThread(models.AbstractModel): 'lang': lang, } + def _notify_by_email_add_values(self, base_mail_values): + """ Add model-specific values to the dictionary used to create the + notification email. Its base behavior is to compute model-specific + headers. + + :param dict base_mail_values: base mail.mail values, holding message + to notify (mail_message_id and its fields), server, references, subject. + """ + headers = self._notify_email_headers() + if headers: + base_mail_values['headers'] = headers + return base_mail_values + def _notify_compute_recipients(self, message, msg_vals): """ Compute recipients to notify based on subtype and followers. This method returns data structured as expected for ``_notify_recipients``. """