changeset e681112facef in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=e681112facef
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
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 e6e553bfde14 -r e681112facef trytond/ir/translation.py
--- a/trytond/ir/translation.py Mon Jan 28 10:03:47 2019 +0100
+++ b/trytond/ir/translation.py Wed Jan 30 09:36:21 2019 +0100
@@ -471,12 +471,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)
@@ -512,6 +516,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
@@ -519,19 +527,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 e6e553bfde14 -r e681112facef trytond/tests/test_field_char.py
--- a/trytond/tests/test_field_char.py  Mon Jan 28 10:03:47 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")
+
 
 class UnaccentedTestCase(unittest.TestCase):
     @classmethod

Reply via email to