From 8ccde3f101cdb6ca41fe29cc5b4252f13745774a Mon Sep 17 00:00:00 2001 From: "Chong Wang (cwg)" Date: Wed, 21 Feb 2024 11:13:05 +0000 Subject: [PATCH] [FIX] core: fix translation typo fixing for model_terms translated fields, for sake of typo fixing feature if a term is removed after write its translations might be reused by another close term which has totally different meaning this fix removes the typo fixing if the matched closest term exists before write closes odoo/odoo#155476 X-original-commit: 38ec36e9b5dde0c02a4ff47714b1056e0db76812 Signed-off-by: Raphael Collet Signed-off-by: Chong Wang (cwg) --- odoo/addons/base/tests/test_translate.py | 24 ++++++++++++++++++++++++ odoo/fields.py | 2 ++ 2 files changed, 26 insertions(+) diff --git a/odoo/addons/base/tests/test_translate.py b/odoo/addons/base/tests/test_translate.py index 7c009a23dab..81584fc5239 100644 --- a/odoo/addons/base/tests/test_translate.py +++ b/odoo/addons/base/tests/test_translate.py @@ -1157,6 +1157,30 @@ class TestXMLTranslation(TransactionCase): self.assertEqual(view.with_env(env_fr).arch_db, archf % terms_fr) self.assertEqual(view.with_env(env_nl).arch_db, archf % terms_nl) + def test_sync_xml_close_terms(self): + """ Check translations of 'arch' after xml tags changes in source terms. """ + archf = '
%s
%s
%s
' + terms_en = ('RandomRandom1', 'RandomRandom2', 'RandomRandom3') + terms_fr = ('RandomRandom1', 'AléatoireAléatoire2', 'AléatoireAléatoire3') + view = self.create_view(archf, terms_en, en_US=terms_en, fr_FR=terms_fr) + + env_nolang = self.env(context={}) + env_en = self.env(context={'lang': 'en_US'}) + env_fr = self.env(context={'lang': 'fr_FR'}) + + self.assertEqual(view.with_env(env_nolang).arch_db, archf % terms_en) + self.assertEqual(view.with_env(env_en).arch_db, archf % terms_en) + self.assertEqual(view.with_env(env_fr).arch_db, archf % terms_fr) + + # modify source term in view + terms_en = ('RandomRandom1', 'SomethingElse', 'RandomRandom3') + view.with_env(env_en).write({'arch_db': archf % terms_en}) + + # check whether close terms have correct translations + self.assertEqual(view.with_env(env_nolang).arch_db, archf % terms_en) + self.assertEqual(view.with_env(env_en).arch_db, archf % terms_en) + self.assertEqual(view.with_env(env_fr).arch_db, archf % ('RandomRandom1', 'SomethingElse', 'AléatoireAléatoire3')) + def test_cache_consistency(self): view = self.env["ir.ui.view"].create({ "name": "test_translate_xml_cache_invalidation", diff --git a/odoo/fields.py b/odoo/fields.py index 50aaf1af37c..5b3f2f42434 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -1861,6 +1861,8 @@ class _String(Field): matches = get_close_matches(old_term_text, text2terms, 1, 0.9) if matches: closest_term = get_close_matches(old_term, text2terms[matches[0]], 1, 0)[0] + if closest_term in translation_dictionary: + continue old_is_text = is_text(old_term) closest_is_text = is_text(closest_term) if old_is_text or not closest_is_text: