[FIX] base: correct translation synchronisation

Avoid matching terms that will be discarded when synchronising
translations.

opw-1921639
opw-1923669
opw-1921933
opw-1921509
opw-1919989
opw-1917321
opw-1916782
opw-1915683
opw-1900821
opw-1891187

closes odoo/odoo#30114
This commit is contained in:
Christophe Simonis
2019-01-11 09:48:43 +00:00
parent f69fde6e2c
commit 2b9f845222
2 changed files with 30 additions and 0 deletions
@@ -488,6 +488,8 @@ class IrTranslation(models.Model):
for translation in translations:
if translation.src == translation.value:
discarded += translation
# consider it done to avoid being matched against another term
done.add((translation.src, translation.lang))
elif translation.src in terms:
done.add((translation.src, translation.lang))
else:
+28
View File
@@ -406,3 +406,31 @@ class TestXMLTranslation(TransactionCase):
self.assertEqual(view.with_env(env_en).arch_db, archf % terms_en)
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_update(self):
""" Check translations after minor change in source terms. """
archf = '<form string="X"><div>%s</div><div>%s</div></form>'
terms_src = ('Subtotal', 'Subtotal:')
terms_en = ('Subtotal', 'Sub total:')
view = self.create_view(archf, terms_src, en_US=terms_en)
translations = self.env['ir.translation'].search([
('type', '=', 'model_terms'),
('name', '=', "ir.ui.view,arch_db"),
('res_id', '=', view.id),
])
self.assertEqual(len(translations), 2)
# modifying the arch should sync existing translations without errors
view.write({
"arch": archf % ('Subtotal', 'Subtotal:<br/>')
})
translations = self.env['ir.translation'].search([
('type', '=', 'model_terms'),
('name', '=', "ir.ui.view,arch_db"),
('res_id', '=', view.id),
])
# 'Subtotal' being src==value, it will be discared
# 'Subtotal:' will be discarded as it match 'Subtotal' instead of 'Subtotal:<br/>'
self.assertEqual(len(translations), 0)