[FIX] core: update model terms for en_US and other

For model_terms translated fields if a translation for a lang(fr_FR) has never
been defined

before this commit
when update translations for both en_US and fr_FR, the new translation for fr_FR
cannot be saved.

after this commit
new translations can be correctly saved when en_US and fr_FR are updated at the
same time.

closes odoo/odoo#135103

X-original-commit: ef4b195eeac178a14eb47f4e6cc61ddc97f78866
Signed-off-by: Raphael Collet <rco@odoo.com>
Signed-off-by: Chong Wang (cwg) <cwg@odoo.com>
This commit is contained in:
Chong Wang (cwg)
2023-09-11 23:59:51 +00:00
parent dacbe1d496
commit ddfdba9424
2 changed files with 12 additions and 1 deletions
+10
View File
@@ -1139,6 +1139,16 @@ class TestXMLTranslation(TransactionCase):
self.assertEqual(view.with_context(lang='fr_FR').arch_db, '<form string="X">Pain et fromage<div>Fourchette2</div></form>')
self.assertEqual(view.with_context(lang='nl_NL').arch_db, view_nl)
# update translations for fallback values and en_US
self.env['res.lang']._activate_lang('es_ES')
self.assertEqual(view.with_context(lang='es_ES').arch_db, '<form string="X">Bread and cheese<div>Fork2</div></form>')
view.update_field_translations('arch_db', {
'en_US': {'Fork2': 'Fork3'},
'es_ES': {'Fork2': 'Tenedor3'}
})
self.assertEqual(view.with_context(lang='en_US').arch_db, '<form string="X">Bread and cheese<div>Fork3</div></form>')
self.assertEqual(view.with_context(lang='es_ES').arch_db, '<form string="X">Bread and cheese<div>Tenedor3</div></form>')
class TestHTMLTranslation(TransactionCase):
def test_write_non_existing(self):
+2 -1
View File
@@ -3558,8 +3558,9 @@ class BaseModel(metaclass=MetaModel):
if not old_translations:
return False
new_translations = old_translations
old_value_en = old_translations.get('en_US')
for lang, translation in translations.items():
old_value = new_translations.get(lang) or new_translations.get('en_US')
old_value = new_translations.get(lang, old_value_en)
if digest:
old_terms = field.get_trans_terms(old_value)
old_terms_digested2value = {digest(old_term): old_term for old_term in old_terms}