From 49fbab5329fb95e759c3f90d4e9efb1717a9695c Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Wed, 16 Oct 2019 12:05:02 +0200 Subject: [IMP] base: split and deprecate load_lang load_lang was a kind of hybrid method trying to active or creating a language if not found. This was error prone. Instead rely on two methods with clear purpose: ResLang._create_lang(lang, lang_name=None) - create a new res.lang entry using the locale of the server return the res.lang record to match the API of _activate_lang ResLang._active_lang(code) - activate the given code lang Most of the time, _active_lang is what is expected tools.trans_load_data and IrTranslation._load_module_terms no longer activate the language if not active. Loading the translations should be explicit on an activated language, it is too error prone to silently activate/create a language if not found. Remove lang_name from trans_load_data as no longer needed. --- addons/test_mail_full/tests/test_sms_composer.py | 4 ++-- addons/test_mail_full/tests/test_sms_template.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'addons/test_mail_full') diff --git a/addons/test_mail_full/tests/test_sms_composer.py b/addons/test_mail_full/tests/test_sms_composer.py index 060863e4f02..5e0f74fe1b5 100644 --- a/addons/test_mail_full/tests/test_sms_composer.py +++ b/addons/test_mail_full/tests/test_sms_composer.py @@ -368,7 +368,7 @@ class TestSMSComposerMass(test_mail_full_common.BaseFunctionalTest, sms_common.M self.assertSMSOutgoing(record.customer_id, None, 'Dear %s this is an SMS.' % record.display_name) def test_composer_mass_active_ids_w_template_and_lang(self): - self.env.ref('base.lang_fr').write({'active': True}) + self.env['res.lang']._activate_lang('fr_FR') self.env['ir.translation'].create({ 'type': 'model', 'name': 'sms.template,body', @@ -425,7 +425,7 @@ class TestSMSComposerMass(test_mail_full_common.BaseFunctionalTest, sms_common.M """ Test the context action from a SMS template (Add context action button) and the usage with the sms composer """ # Create the lang info - self.env.ref('base.lang_fr').write({'active': True}) + self.env['res.lang']._activate_lang('fr_FR') self.env['ir.translation'].create({ 'type': 'model', 'name': 'sms.template,body', diff --git a/addons/test_mail_full/tests/test_sms_template.py b/addons/test_mail_full/tests/test_sms_template.py index a1c754511ab..ec5b7cf9f39 100644 --- a/addons/test_mail_full/tests/test_sms_template.py +++ b/addons/test_mail_full/tests/test_sms_template.py @@ -25,7 +25,7 @@ class TestSmsTemplate(test_mail_full_common.BaseFunctionalTest, sms_common.MockS self.assertEqual(rendered_body[self.test_record.id], 'Dear %s this is an SMS.' % self.test_record.display_name) def test_sms_template_lang(self): - self.env.ref('base.lang_fr').write({'active': True}) + self.env['res.lang']._activate_lang('fr_FR') self.user_admin.write({'lang': 'en_US'}) self.env['ir.translation'].create({ 'type': 'model', -- cgit v1.2.3