[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
This commit is contained in:
Lucas Perais (lpe)
2019-02-06 11:07:33 +00:00
parent a21864c36c
commit 80460c40d9
3 changed files with 4 additions and 3 deletions
+1 -1
View File
@@ -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)
+2 -1
View File
@@ -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)
+1 -1
View File
@@ -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)