From a577afc75e9009694aec3de0aee0acecf68ede06 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Dufays Date: Mon, 11 Apr 2022 14:03:16 +0000 Subject: [PATCH 1/3] [IMP] account,crm,project,purchase,sale,[test_]mail: improves activity notif Ease the understanding of the notifications sent when users are assigned to an activity or a model (task, lead, ...). Technical note: - the customization of data sent to the email layout template (here subtitles) should be done by overriding mail_thread._notify_by_email_prepare_rendering_context on the model. But in this case, we send an activity (ex.: todo) for a model (ex.: crm.lead) which involves 2 models. Data from both models must be sent to the template layout. To solve this problem an optional parameter to mail_thread.message_notify has been added: subtitles. This allows the caller which knows about the 2 models to set the values for subtitles for the template. - mail_activity._render_notify_header has been added to render the subject and subtitles using the language of the recipients through the context lang variable. - a generic mail notification template has been added and the specific mail_notification_paynow has been derived from it as the only change is the handling of the signature. Task-2801600 Part-of: odoo/odoo#88466 --- addons/account/models/account_move.py | 8 ++-- addons/crm/models/crm_lead.py | 12 +++++ addons/mail/data/mail_templates_chatter.xml | 34 +++++++------- .../data/mail_templates_email_layouts.xml | 46 ++++++++++++------- addons/mail/models/mail_activity.py | 23 ++++++---- addons/mail/models/mail_thread.py | 9 ++-- addons/project/data/mail_template_data.xml | 13 ++---- addons/project/models/project.py | 20 ++++++-- addons/purchase/models/purchase.py | 12 +++-- addons/sale/models/sale_order.py | 14 +++--- addons/test_mail/tests/test_mail_activity.py | 2 +- 11 files changed, 118 insertions(+), 75 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 377a85b191c..0f87d565aae 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -3584,13 +3584,15 @@ class AccountMove(models.Model): message, msg_vals, model_description=model_description, force_email_company=force_email_company, force_email_lang=force_email_lang ) + subtitles = [render_context['record'].name] if self.invoice_date_due: - render_context['subtitle'] = _('%(amount)s due\N{NO-BREAK SPACE}%(date)s', + subtitles.append(_('%(amount)s due\N{NO-BREAK SPACE}%(date)s', amount=format_amount(self.env, self.amount_total, self.currency_id, lang_code=render_context.get('lang')), date=format_date(self.env, self.invoice_date_due, date_format='short', lang_code=render_context.get('lang')) - ) + )) else: - render_context['subtitle'] = format_amount(self.env, self.amount_total, self.currency_id, lang_code=render_context.get('lang')) + subtitles.append(format_amount(self.env, self.amount_total, self.currency_id, lang_code=render_context.get('lang'))) + render_context['subtitles'] = subtitles return render_context # ------------------------------------------------------------------------- diff --git a/addons/crm/models/crm_lead.py b/addons/crm/models/crm_lead.py index 2586bceff1e..db4613877ab 100644 --- a/addons/crm/models/crm_lead.py +++ b/addons/crm/models/crm_lead.py @@ -16,6 +16,7 @@ from odoo.exceptions import UserError, AccessError from odoo.osv import expression from odoo.tools.translate import _ from odoo.tools import date_utils, email_re, email_split, is_html_empty, groupby +from odoo.tools.misc import get_lang from . import crm_stage @@ -1792,6 +1793,17 @@ class Lead(models.Model): return self.env.ref('crm.mt_lead_lost') return super(Lead, self)._track_subtype(init_values) + def _notify_by_email_prepare_rendering_context(self, message, msg_vals=False, model_description=False, + force_email_company=False, force_email_lang=False): + render_context = super()._notify_by_email_prepare_rendering_context( + message, msg_vals, model_description=model_description, + force_email_company=force_email_company, force_email_lang=force_email_lang + ) + if self.date_deadline: + render_context['subtitles'].append( + _('Deadline: %s', self.date_deadline.strftime(get_lang(self.env).date_format))) + return render_context + def _notify_get_recipients_groups(self, msg_vals=None): """ Handle salesman recipients that can convert leads into opportunities and set opportunities as won / lost. """ diff --git a/addons/mail/data/mail_templates_chatter.xml b/addons/mail/data/mail_templates_chatter.xml index 3d86bdfe9ec..a230a48b603 100644 --- a/addons/mail/data/mail_templates_chatter.xml +++ b/addons/mail/data/mail_templates_chatter.xml @@ -3,15 +3,12 @@ - - -