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

changeset 145c865d90b0 in trytond:4.4
details: https://hg.tryton.org/trytond?cmd=changeset;node=145c865d90b0
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 +++++++++++--------
 1 files changed, 11 insertions(+), 8 deletions(-)

diffs (54 lines):

diff -r fe396c8fee1c -r 145c865d90b0 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
@@ -524,12 +524,16 @@
                 to_save = []
                 for record, value in izip(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)
@@ -565,6 +569,10 @@
             to_save = []
             for record, value in izip(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
@@ -572,19 +580,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)

Reply via email to