Permalink
Browse files

[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
  • Loading branch information...
KangOl committed Jan 10, 2019
1 parent 5e1b874 commit 9ccbf5f9cbd1123bdd2f22cd98d60b990e4cb00f
Showing with 30 additions and 0 deletions.
  1. +2 −0 odoo/addons/base/models/ir_translation.py
  2. +28 −0 odoo/addons/base/tests/test_translate.py
@@ -488,6 +488,8 @@ def _sync_terms_translations(self, field, records):
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:
@@ -406,3 +406,31 @@ def test_sync(self):
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)

0 comments on commit 9ccbf5f

Please sign in to comment.