Avoid to store in transactional cache former translation value
Translated fields are stored in the transactional cache. Using the instance to get the source value when it is being set, store the former value into the cache and the source. issue7997 review58471002
This commit is contained in:
1 parent
62f175d3d1
commit
23c81ec015
2 files changed
+29
-8
No files matched your search
@@ -471,12 +471,16 @@ class Translation(ModelSQL, ModelView):
|
||||
to_save = []
|
||||
for record, value in zip(records, values):
|
||||
translation = translations.get(get_name(record))
|
||||
if lang == 'en':
|
||||
src = value
|
||||
else:
|
||||
src = getattr(record, field_name)
|
||||
if not translation:
|
||||
translation = cls()
|
||||
translation.name = name
|
||||
translation.lang = lang
|
||||
translation.type = ttype
|
||||
translation.src = getattr(record, field_name)
|
||||
translation.src = src
|
||||
translation.value = value
|
||||
translation.fuzzy = False
|
||||
to_save.append(translation)
|
||||
@@ -512,6 +516,10 @@ class Translation(ModelSQL, ModelView):
|
||||
to_save = []
|
||||
for record, value in zip(records, values):
|
||||
translation = translations.get(record.id)
|
||||
if lang == Config.get_language():
|
||||
src = value
|
||||
else:
|
||||
src = getattr(record, field_name)
|
||||
if not translation:
|
||||
translation = cls()
|
||||
translation.name = name
|
||||
@@ -519,19 +527,14 @@ class Translation(ModelSQL, ModelView):
|
||||
translation.type = ttype
|
||||
translation.res_id = record.id
|
||||
else:
|
||||
cls.write([translation], {
|
||||
'value': value,
|
||||
'src': getattr(record, field_name),
|
||||
'fuzzy': False,
|
||||
})
|
||||
other_langs = other_translations.get(record.id)
|
||||
if other_langs:
|
||||
for other_lang in other_langs:
|
||||
other_lang.src = getattr(record, field_name)
|
||||
other_lang.src = src
|
||||
other_lang.fuzzy = True
|
||||
to_save.append(other_lang)
|
||||
translation.value = value
|
||||
translation.src = getattr(record, field_name)
|
||||
translation.src = src
|
||||
translation.fuzzy = False
|
||||
to_save.append(translation)
|
||||
cls.save(to_save)
|
||||
|
||||
@@ -453,6 +453,24 @@ class FieldCharTranslatedTestCase(unittest.TestCase, CommonTestCaseMixin):
|
||||
def Char(self):
|
||||
return Pool().get('test.char_translate')
|
||||
|
||||
@with_transaction()
|
||||
def test_translation_default_language_cache(self):
|
||||
"""Test set translation for default language does not fill transactional
|
||||
cache with former value"""
|
||||
pool = Pool()
|
||||
Config = pool.get('ir.configuration')
|
||||
Char = self.Char()
|
||||
|
||||
with Transaction().set_context(language=Config.get_language()):
|
||||
char, = Char.create([{
|
||||
'char': "foo",
|
||||
}])
|
||||
|
||||
char.char = "bar"
|
||||
char.save()
|
||||
|
||||
self.assertEqual(char.char, "bar")
|
||||
|
||||
|
||||
class UnaccentedTestCase(unittest.TestCase):
|
||||
@classmethod
|
||||
|
||||
Reference in new issue
Block a user