Skip to content
Permalink
Browse files

[FIX] models: do not erase master version

For a translated field with a callable method (e.g. xml_translate), when
modifying the value of this field in another language than en_US, the master
version was lost.

Before this patch:

>>> record.arch = "<h1>Title</h1>"
>>> record.with_context(lang='fr_FR').arch = "<h1>Titre</h1>"
>>> record.with_context(lang='fr_FR').arch
"<h1>Titre</h1>"
>>> record.arch
"<h1>Titre</h1>"  # lost English version

After this patch:

>>> record.arch = "<h1>Title</h1>"
>>> record.with_context(lang='fr_FR').arch = "<h1>Titre</h1>"
>>> record.with_context(lang='fr_FR').arch
"<h1>Title</h1>"  # write had no effect
>>> record.arch
"<h1>Title</h1>"

When modifying a translated HTML field in English, a matching to detect the
difference and avoid losing the translations is done.
This is not supported for update in another language.
The main reason is the difficulty to detect changes in the architecture.

To update translations, the supported way is to go to the list of translations
and update them there.

Before this patch, the given value in another language was given to the SQL
query and made an update in database:
if single_lang or not (has_translation and field.translate is True)
-> True or not (True and False) -> True

If a field is callable, it should also be ignored, the same way than
translate=True fields

opw-1887162
  • Loading branch information...
mart-e committed Feb 21, 2019
1 parent 10db0a5 commit efc30a7b4820251fdd4402b97a86e430bed13127
Showing with 1 addition and 1 deletion.
  1. +1 −1 odoo/models.py
@@ -3360,7 +3360,7 @@ def _write(self, vals):
_logger.warning('Field %s is deprecated: %s', field, field.deprecated)

if field.column_type:
if single_lang or not (has_translation and field.translate is True):
if single_lang or not (has_translation and field.translate):
# val is not a translation: update the table
val = field.convert_to_column(val, self, vals)
columns.append((name, field.column_format, val))

0 comments on commit efc30a7

Please sign in to comment.
You can’t perform that action at this time.