From 80460c40d9785f3e24fbc9464cc7e117f56f446f Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Wed, 6 Feb 2019 10:34:57 +0000 Subject: [PATCH] [FIX] account, purchase, sale: notification with right lang Have a partner in French while you operate in English Click on 'send by email' on a invoice/sale order/purchase order Before this commit: - The body of the mail is translated in the partner's language - but the notification header/footer surrounding the body was not This is because: - mail templates apply to a model - in the case of the notification header/footer, this model is 'mail.message' - mail.message doesn't have a lang field - at the notification rendering time, we don't have easy (and generic) access to the "real" model or to the lang (let alone to which lang to apply) that we need After this commit, the notification is translated but: the lang to get is hardcoded, and is the one on the partner of the inv/so/po and is un-coupled from the dynamic lang on the proper inv/so/po template This patch is hackish at several levels, I suggest that a generic solution is found in master If no other solution is found until then, then the patch may be forward-ported OPW 1935091 closes odoo/odoo#30873 --- addons/account/models/account_invoice.py | 2 +- addons/purchase/models/purchase.py | 3 ++- addons/sale/wizard/mail_compose_message.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 5f2d83c5035..576f9d9e551 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -1834,5 +1834,5 @@ class MailComposeMessage(models.TransientModel): invoice = self.env['account.invoice'].browse(context['default_res_id']) if not invoice.sent: invoice.sent = True - self = self.with_context(mail_post_autofollow=True) + self = self.with_context(mail_post_autofollow=True, lang=invoice.partner_id.lang) return super(MailComposeMessage, self).send_mail(auto_commit=auto_commit) diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index 53eeaffa2e3..8962513fd02 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -1131,6 +1131,7 @@ class MailComposeMessage(models.TransientModel): @api.multi def send_mail(self, auto_commit=False): if self._context.get('default_model') == 'purchase.order' and self._context.get('default_res_id'): - self = self.with_context(mail_post_autofollow=True) + order = self.env['purchase.order'].browse(self._context['default_res_id']) + self = self.with_context(mail_post_autofollow=True, lang=order.partner_id.lang) self.mail_purchase_order_on_send() return super(MailComposeMessage, self).send_mail(auto_commit=auto_commit) diff --git a/addons/sale/wizard/mail_compose_message.py b/addons/sale/wizard/mail_compose_message.py index 9ec46b48308..0291d3f848c 100644 --- a/addons/sale/wizard/mail_compose_message.py +++ b/addons/sale/wizard/mail_compose_message.py @@ -13,5 +13,5 @@ class MailComposeMessage(models.TransientModel): order = self.env['sale.order'].browse([self._context['default_res_id']]) if order.state == 'draft': order.with_context(tracking_disable=True).state = 'sent' - self = self.with_context(mail_post_autofollow=True) + self = self.with_context(mail_post_autofollow=True, lang=order.partner_id.lang) return super(MailComposeMessage, self).send_mail(auto_commit=auto_commit)