[FIX] models: do not keep the old source in case of copy override

Current behaviour when duplicating a record:

    apply copy override in the user language (e.g. "%s (copy)")
    copy the previous term in all the other languages (including)

So if product was named:

    cheeses (en)
    kaas (nl)
    fromage (fr)

Duplicating the product, while in French, will result into:

    cheeses (en)
    kaas (nl)
    fromage (copie) (fr)

This is a problem if there is a unicity constrain on the field, it will be
raised (there is already a product named 'cheese')

After this PR:

Duplicating the product, while in French, will result into:

    fromage (copie) (en)
    kaas (nl)
    fromage (copie) (fr)

This applies **only** if there is an override of copy

This is detected by comparing the old and new value for the user language

Fixes #7010
Closes #22052
This commit is contained in:
Martin Trigaux
2018-01-09 18:15:47 +01:00
parent a7c2a22310
commit 7e894aca0b
+3 -1
View File
@@ -3822,7 +3822,9 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})):
del vals['module'] # duplicated vals is not linked to any module
vals['res_id'] = target_id
if vals['lang'] == old.env.lang and field.translate is True:
vals['source'] = old_wo_lang[name]
# force a source if the new_val was not changed by copy override
if new_val == old[name]:
vals['source'] = old_wo_lang[name]
# the value should be the new value (given by copy())
vals['value'] = new_val
Translation.create(vals)