diff --git a/addons/mail/models/template_reset_mixin.py b/addons/mail/models/template_reset_mixin.py index f8735d6e3bb..9f211e8ed56 100644 --- a/addons/mail/models/template_reset_mixin.py +++ b/addons/mail/models/template_reset_mixin.py @@ -89,11 +89,15 @@ class TemplateResetMixin(models.AbstractModel): user lang (all langs are not supported due to costly file operation). """ expr = "//*[local-name() = $tag and (@id = $xml_id or @id = $external_id)]" templates_with_missing_source = [] + lang_false = {code: False for code, _ in self.env['res.lang'].get_installed() if code != 'en_US'} for template in self.filtered('template_fs'): external_id = template.get_external_id().get(template.id) module, xml_id = external_id.split('.') fullpath = get_resource_path(*template.template_fs.split('/')) if fullpath: + for field_name, field in template._fields.items(): + if field.translate is True: + template.update_field_translations(field_name, lang_false) doc = etree.parse(fullpath) for rec in doc.xpath(expr, tag='record', xml_id=xml_id, external_id=external_id): # We don't have a way to pass context while loading record from a file, so we use this hack diff --git a/addons/mail/tests/test_mail_template.py b/addons/mail/tests/test_mail_template.py index e0d4f9133cf..621ed9a589c 100644 --- a/addons/mail/tests/test_mail_template.py +++ b/addons/mail/tests/test_mail_template.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. from markupsafe import Markup +from unittest.mock import patch from odoo.addons.mail.tests.common import MailCommon from odoo.exceptions import AccessError, ValidationError, UserError @@ -209,6 +210,50 @@ class TestMailTemplateReset(MailCommon): # subject is not there in the data file template, so it should be set to False self.assertFalse(mail_template.subject, "Subject should be set to False") + def test_mail_template_reset_translation(self): + """ Test if a translated value can be reset correctly when its translation exists/doesn't exist in the po file of the directory """ + self._load('mail', 'tests', 'test_mail_template.xml') + + self.env['res.lang']._activate_lang('en_UK') + self.env['res.lang']._activate_lang('fr_FR') + mail_template = self.env.ref('mail.mail_template_test').with_context(lang='en_US') + mail_template.write({ + 'body_html': '