diff --git a/odoo/addons/base/tests/test_translate.py b/odoo/addons/base/tests/test_translate.py index 455d9681a85..276c05bf7ba 100644 --- a/odoo/addons/base/tests/test_translate.py +++ b/odoo/addons/base/tests/test_translate.py @@ -365,7 +365,6 @@ class TestTranslation(TransactionCase): self.assertEqual(cheese.with_context(lang='fr_FR').name, 'Fromage') self.assertEqual(cheese.with_context(lang='en_US').name, 'The Cheese') cheese.flush() - cheese.invalidate_cache() # set a new master value cheese.with_context(lang='en_US').write({'name': 'Delicious Cheese'}) @@ -686,7 +685,6 @@ class TestXMLTranslation(TransactionCase): # modify source term in view (fixed type in 'cheeze') terms_en = ('Bread and cheese',) view.with_env(env_en).write({'arch_db': archf % terms_en}) - view.invalidate_cache(fnames=['arch_db'], ids=view.ids) # check whether translations have been synchronized self.assertEqual(view.with_env(env_nolang).arch_db, archf % terms_en) @@ -698,7 +696,6 @@ class TestXMLTranslation(TransactionCase): # modify source term in view in another language with close term new_terms_fr = ('Pains et fromage',) view.with_env(env_fr).write({'arch_db': archf % new_terms_fr}) - view.invalidate_cache(fnames=['arch_db'], ids=view.ids) # check whether translations have been synchronized self.assertEqual(view.with_env(env_nolang).arch_db, archf % new_terms_fr) @@ -707,7 +704,7 @@ class TestXMLTranslation(TransactionCase): self.assertEqual(view.with_env(env_nl).arch_db, archf % terms_nl) def test_sync_update(self): - """ Check translations after minor change in source terms. """ + """ Check translations after major changes in source terms. """ archf = '
%s
%s
' terms_src = ('Subtotal', 'Subtotal:') terms_en = ('', 'Sub total:') @@ -721,9 +718,8 @@ class TestXMLTranslation(TransactionCase): self.assertEqual(len(translations), 2) # modifying the arch should sync existing translations without errors - view.write({ - "arch": archf % ('Subtotal', 'Subtotal:
') - }) + new_arch = archf % ('Subtotal', 'Subtotal:
') + view.write({"arch_db": new_arch}) translations = self.env['ir.translation'].search([ ('type', '=', 'model_terms'), @@ -733,3 +729,18 @@ class TestXMLTranslation(TransactionCase): # 'Subtotal' being src==value, it will be discared # 'Subtotal:' will be discarded as it match 'Subtotal' instead of 'Subtotal:
' self.assertEqual(len(translations), 0) + + def test_cache_consistency(self): + view = self.env["ir.ui.view"].create({ + "name": "test_translate_xml_cache_invalidation", + "model": "res.partner", + "arch": "
content
", + }) + view_fr = view.with_context({"lang": "fr_FR"}) + self.assertIn("", view.arch_db) + self.assertIn("", view_fr.arch_db) + + # write with no lang, and check consistency in other languages + view.write({"arch_db": "
content
"}) + self.assertIn("", view.arch_db) + self.assertIn("", view_fr.arch_db) diff --git a/odoo/fields.py b/odoo/fields.py index a96d0f9631a..41e50c722f6 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -1446,7 +1446,10 @@ class _String(Field): if self.translate is True and cache_value is not None: tname = "%s,%s" % (records._name, self.name) records.env['ir.translation']._set_source(tname, real_recs._ids, value) - records.invalidate_cache(fnames=[self.name], ids=records.ids) + if self.translate: + # invalidate the field in the other languages + cache.invalidate([(self, records.ids)]) + cache.update(records, self, [cache_value] * len(records)) if update_trans: if callable(self.translate):