[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) <tde@openerp.com>
This commit is contained in:
mreficent
2020-04-24 09:30:55 +00:00
committed by Thibault Delavallée
parent 797403c0a9
commit b1a5bf95f8
+14 -3
View File
@@ -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``. """