From 41ffb5032b490753f944be88027f1fc36ecdbd00 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Fri, 27 Jan 2017 16:56:59 +0100 Subject: [PATCH] [FIX] mail, sale, account: company used in notification emails The `user` variable in the mail templates is the `self.env.user`, https://github.com/odoo/odoo/blob/10.0/addons/mail/models/mail_template.py#L370 which will always be the administrator in the use case of a notification email https://github.com/odoo/odoo/blob/10.0/addons/mail/models/res_partner.py#L151-L156 Using `user.company_id` to determine the company of the sales order or the invoice is therefore wrong, as it will always be the administrator company, which can be different than the order/invoice company. opw-706267 --- addons/account/data/invoice_action_data.xml | 18 ++++++++++-------- addons/mail/models/res_partner.py | 5 +++++ addons/sale/data/mail_template_data.xml | 18 ++++++++++-------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/addons/account/data/invoice_action_data.xml b/addons/account/data/invoice_action_data.xml index 41731b7c527..cdbcec64e0c 100644 --- a/addons/account/data/invoice_action_data.xml +++ b/addons/account/data/invoice_action_data.xml @@ -62,6 +62,8 @@ from ${object.company_id.name}. + % set record = ctx.get('record') + % set company = record and record.company_id or user.company_id @@ -77,7 +79,7 @@ from ${object.company_id.name}.
- ${user.company_id.name} + ${company.name}
@@ -103,16 +105,16 @@ from ${object.company_id.name}. diff --git a/addons/mail/models/res_partner.py b/addons/mail/models/res_partner.py index c75752416be..d1f263d9736 100644 --- a/addons/mail/models/res_partner.py +++ b/addons/mail/models/res_partner.py @@ -77,11 +77,16 @@ class Partner(models.Model): is_discussion = message.subtype_id.id == self.env['ir.model.data'].xmlid_to_res_id('mail.mt_comment') + record = False + if message.res_id and message.model in self.env: + record = self.env[message.model].browse(message.res_id) + return { 'signature': signature, 'website_url': website_url, 'company_name': company_name, 'model_name': model_name, + 'record': record, 'record_name': record_name, 'tracking': tracking, 'is_discussion': is_discussion, diff --git a/addons/sale/data/mail_template_data.xml b/addons/sale/data/mail_template_data.xml index dfb4ac3f041..72e948d375f 100644 --- a/addons/sale/data/mail_template_data.xml +++ b/addons/sale/data/mail_template_data.xml @@ -63,6 +63,8 @@ from ${object.company_id.name}. + % set record = ctx.get('record') + % set company = record and record.company_id or user.company_id
- ${user.company_id.name}
- ${user.company_id.phone or ''} + ${company.name}
+ ${company.phone or ''}
- % if user.company_id.email: - ${user.company_id.email}
+ % if company.email: + ${company.email}
% endif - % if user.company_id.website: - - ${user.company_id.website} + % if company.website: + + ${company.website} % endif
@@ -78,7 +80,7 @@ from ${object.company_id.name}.
- ${user.company_id.name} + ${company.name}
@@ -104,16 +106,16 @@ from ${object.company_id.name}.
- ${user.company_id.name}
- ${user.company_id.phone or ''} + ${company.name}
+ ${company.phone or ''}
- % if user.company_id.email: - ${user.company_id.email}
+ % if company.email: + ${company.email}
% endif - % if user.company_id.website: - - ${user.company_id.website} + % if company.website: + + ${company.website} % endif