From 2b830e5d41163e12de2fd493d21eba24daf8f924 Mon Sep 17 00:00:00 2001 From: fw-bot Date: Mon, 7 Oct 2019 19:57:00 +0000 Subject: [PATCH] [FIX] mail: translate assignation msg in recipient lang Before this commit, when assigning a user onto a record, through the field user_id, the email was sent in the current user's language After this commit, it is sent in the partner's language OPW 2060898 closes odoo/odoo#38142 Signed-off-by: Lucas Perais (lpe) --- addons/mail/models/mail_thread.py | 8 +++++--- addons/test_mail/tests/test_performance.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 59a74eaf364..3cb4a2276b3 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -2870,7 +2870,9 @@ class MailThread(models.AbstractModel): for pid, sids, template in res: new_partners.setdefault(pid, sids) if template: - notify_data.setdefault(template, list()).append(pid) + partner = self.env['res.partner'].browse(pid) + lang = partner.lang if partner else None + notify_data.setdefault((template, lang), list()).append(pid) self.env['mail.followers']._insert_followers( self._name, self.ids, @@ -2879,8 +2881,8 @@ class MailThread(models.AbstractModel): check_existing=True, existing_policy='skip') # notify people from auto subscription, for example like assignation - for template, pids in notify_data.items(): - self._message_auto_subscribe_notify(pids, template) + for (template, lang), pids in notify_data.items(): + self.with_context(lang=lang)._message_auto_subscribe_notify(pids, template) return True diff --git a/addons/test_mail/tests/test_performance.py b/addons/test_mail/tests/test_performance.py index 3c5de0a5986..64faed185b2 100644 --- a/addons/test_mail/tests/test_performance.py +++ b/addons/test_mail/tests/test_performance.py @@ -200,7 +200,7 @@ class TestAdvMailPerformance(BaseMailPerformance): def test_message_assignation_email(self): self.user_test.write({'notification_type': 'email'}) record = self.env['mail.test.track'].create({'name': 'Test'}) - with self.assertQueryCount(__system__=39, emp=40): + with self.assertQueryCount(__system__=40, emp=41): record.write({ 'user_id': self.user_test.id, })