From 8cd7de22046df2c2387e0e2b637a2a0fa1041e1e Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Fri, 7 Dec 2018 13:54:37 +0000 Subject: [PATCH] [IMP] mail: model description Allow to specify the `model_description` when sending an email to take into account for cases where the same model is used for different business concepts. opw-1915230 --- addons/mail/wizard/mail_compose_message.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index 5422a115fdf..f92e23c6cc1 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -199,6 +199,13 @@ class MailComposer(models.TransientModel): """ Process the wizard content and proceed with sending the related email(s), rendering any template patterns on the fly if needed. """ notif_layout = self._context.get('custom_layout') + # Several custom layouts make use of the model description at rendering, e.g. in the + # 'View ' button. Some models are used for different business concepts, such as + # 'purchase.order' which is used for a RFQ and and PO. To avoid confusion, we must use a + # different wording depending on the state of the object. + # Therefore, we can set the description in the context from the beginning to avoid falling + # back on the regular display_name retrieved in '_notify_prepare_template_context'. + model_description = self._context.get('model_description') for wizard in self: # Duplicate attachments linked to the email.template. # Indeed, basic mail.compose.message wizard duplicates attachments in mass @@ -253,6 +260,7 @@ class MailComposer(models.TransientModel): notif_layout=notif_layout, add_sign=not bool(wizard.template_id), mail_auto_delete=wizard.template_id.auto_delete if wizard.template_id else False, + model_description=model_description, **mail_values) if ActiveModel._name == 'mail.thread' and wizard.model: post_params['model'] = wizard.model