Subject: changeset in trytond:5.0 Avoid to store in transactional cache former 
translation value
From: Cédric Krier <[email protected]>

changeset 977c21104386 in trytond:5.0
details: https://hg.tryton.org/trytond?cmd=changeset;node=977c21104386
description:
        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
        (grafted from e681112facef998992031559732276b0ddc2c01b)
diffstat:

 trytond/ir/translation.py        |  19 +++++++++++--------
 trytond/tests/test_field_char.py |  18 ++++++++++++++++++
 2 files changed, 29 insertions(+), 8 deletions(-)

diffs (82 lines):

diff -r cf07753010cd -r 977c21104386 trytond/ir/translation.py
--- a/trytond/ir/translation.py Thu Jan 17 17:13:26 2019 +0100
+++ b/trytond/ir/translation.py Wed Jan 30 09:36:21 2019 +0100
@@ -496,12 +496,16 @@
                 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)
@@ -537,6 +541,10 @@
             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
@@ -544,19 +552,14 @@
                     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)
diff -r cf07753010cd -r 977c21104386 trytond/tests/test_field_char.py
--- a/trytond/tests/test_field_char.py  Thu Jan 17 17:13:26 2019 +0100
+++ b/trytond/tests/test_field_char.py  Wed Jan 30 09:36:21 2019 +0100
@@ -453,6 +453,24 @@
     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")
+
 
 @unittest.skipUnless(backend.name() == 'postgresql',
     "unaccent works only on postgresql")

Reply via email to