[FIX] base: do not load translations twice
This fixes former pull request odoo/odoo#78287. The language installation wizard was invoking toggle_active() on the target languages, which loads translations for those languages (with overwrite=False), and then loading translations again (with expected parameter overwrite). Simply don't use toggle_active(), and directly set the active field instead, in order to load translations once with the expected parameter overwrite. closes odoo/odoo#90421 X-original-commit: 3e4733859fbe2465c386ec65b7be995b152c8c48 Signed-off-by: Raphael Collet <rco@odoo.com>
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from unittest.mock import patch
|
||||
|
||||
from psycopg2 import IntegrityError
|
||||
|
||||
from odoo.exceptions import AccessError, ValidationError
|
||||
from odoo.tools import mute_logger
|
||||
from odoo.tools.translate import quote, unquote, xml_translate, html_translate
|
||||
from odoo.tests.common import TransactionCase, BaseCase, new_test_user
|
||||
from psycopg2 import IntegrityError
|
||||
|
||||
|
||||
class TranslationToolsTestCase(BaseCase):
|
||||
@@ -244,6 +247,28 @@ class TranslationToolsTestCase(BaseCase):
|
||||
self.assertEqual(result, source)
|
||||
|
||||
|
||||
class TestLanguageInstall(TransactionCase):
|
||||
def test_language_install(self):
|
||||
fr = self.env['res.lang'].with_context(active_test=False).search([('code', '=', 'fr_FR')])
|
||||
self.assertTrue(fr)
|
||||
wizard = self.env['base.language.install'].create({'lang_ids': fr.ids})
|
||||
wizard.flush()
|
||||
|
||||
# running the wizard calls _load_module_terms() to load PO files
|
||||
loaded = []
|
||||
|
||||
def _load_module_terms(self, modules, langs, overwrite=False):
|
||||
loaded.append((modules, langs, overwrite))
|
||||
|
||||
with patch('odoo.addons.base.models.ir_translation.IrTranslation._load_module_terms', _load_module_terms):
|
||||
wizard.lang_install()
|
||||
|
||||
# _load_module_terms is called once with lang='fr_FR' and overwrite=True
|
||||
self.assertEqual(len(loaded), 1)
|
||||
self.assertEqual(loaded[0][1], ['fr_FR'])
|
||||
self.assertEqual(loaded[0][2], True)
|
||||
|
||||
|
||||
class TestTranslation(TransactionCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
||||
@@ -36,13 +36,11 @@ class BaseLanguageInstall(models.TransientModel):
|
||||
def lang_install(self):
|
||||
self.ensure_one()
|
||||
mods = self.env['ir.module.module'].search([('state', '=', 'installed')])
|
||||
lang_ids = self.lang_ids
|
||||
langs_to_activate = lang_ids.filtered(lambda l: not l.active)
|
||||
langs_to_activate.toggle_active()
|
||||
mods._update_translations(lang_ids.mapped('code'), self.overwrite)
|
||||
self.lang_ids.active = True
|
||||
mods._update_translations(self.lang_ids.mapped('code'), self.overwrite)
|
||||
self.env.cr.execute('ANALYZE ir_translation')
|
||||
|
||||
if len(lang_ids) == 1:
|
||||
if len(self.lang_ids) == 1:
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'base.language.install',
|
||||
|
||||
Reference in New Issue
Block a user