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 07e1a24 commit af2d8bfc759c3704a8bb8f05722711b2cb57b1fe
Showing with 32 additions and 0 deletions.
  1. +4 −0 odoo/addons/base/models/ir_translation.py
  2. +28 −0 odoo/addons/base/tests/test_translate.py
@@ -500,6 +500,10 @@ def _sync_terms_translations(self, field, records):
outdated += translation
elif (src, translation.lang) in done:
discarded += translation
elif any(d.src == src for d in discarded):
# If a previously discarded (because src==value) translation match the close
# term, we should also discard this translation to avoid constraint violation
discarded += translation
else:
translation.write({'src': src, 'state': translation.state})
done.add((src, translation.lang))
@@ -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 af2d8bf

Please sign in to comment.