Skip to content
Snippets Groups Projects
Commit 5621ae3d authored by Nans Lefebvre's avatar Nans Lefebvre
Browse files

[FIX] account: bulk send invoice in each partner language


Select invoices with partners with different languages.
Execute the 'Send' action, and choose send_mail.
The mails are all sent in the same language.

The composer extracts the template's body to put it as self.body
(note that everything also applies to the subject field).
This is done with one language.
Down the line, mail_compose_message renders the values with the object,
using self.body (which can be manually edited).
Therefore the lang parameter is ignored at this point.

This should ideally be fixed at the mail level, which is riskier in stable,
so it may be fixed either later or in master.
So this fix only intends to fix the consequences for this specific use-case,
in a much safer way, but it could be removed once the true fix is one.

opw 2035525

closes odoo/odoo#34975

Signed-off-by: default avatarNans Lefebvre (len) <len@odoo.com>
parent e6225eeb
No related branches found
No related tags found
No related merge requests found
......@@ -80,7 +80,19 @@ class AccountInvoiceSend(models.TransientModel):
@api.multi
def send_and_print_action(self):
self.ensure_one()
self._send_email()
# Send the mails in the correct language by splitting the ids per lang.
# This should ideally be fixed in mail_compose_message, so when a fix is made there this whole commit should be reverted.
# basically self.body (which could be manually edited) extracts self.template_id,
# which is then not translated for each customer.
active_ids = self.env.context.get('active_ids', self.res_id)
active_records = self.env[self.model].browse(active_ids)
langs = active_records.mapped('partner_id.lang')
default_lang = self.env.context.get('lang', 'en_US')
for lang in (set(langs) or [default_lang]):
active_ids_lang = active_records.filtered(lambda r: r.partner_id.lang == lang).ids
self_lang = self.with_context(active_ids=active_ids_lang, lang=lang)
self_lang.onchange_template_id()
self_lang._send_email()
if self.is_print:
return self._print_document()
return {'type': 'ir.actions.act_window_close'}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment