summaryrefslogtreecommitdiff
path: root/odoo/models.py
diff options
context:
space:
mode:
authorNicolas Martinelli <nim@odoo.com>2017-06-29 11:59:06 +0200
committerNicolas Martinelli <nim@odoo.com>2017-06-30 10:52:15 +0200
commitc61ae3a3ed65b7a40b470076c5dbbd881e791f78 (patch)
tree1828c3115d18a25172b520fcedce320319d98792 /odoo/models.py
parentd1e92c312f2fdfd63d59ea8ec27eb264750873b7 (diff)
[FIX] models: copy field with unique constrain
When a model contains a field translatable which has a unique constrain, it is impossible to copy a record. Indeed, the unicity constrain is always triggered, even if the model takes in charge the overriding of the copy method to avoid duplication. Introduced with commit ce7f31b0b0a5fba, with the goal to target only XML/HTML translations. We apply this behavior in case of a callable translate property, to target only the desired problematic use case. opw-749481
Diffstat (limited to 'odoo/models.py')
-rw-r--r--odoo/models.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/odoo/models.py b/odoo/models.py
index 005b2412f7e..5eeef77ef4e 100644
--- a/odoo/models.py
+++ b/odoo/models.py
@@ -4363,7 +4363,7 @@ class BaseModel(object):
trans_name, source_id, target_id = get_trans(field, old, new)
domain = [('name', '=', trans_name), ('res_id', '=', source_id)]
new_val = new_wo_lang[name]
- if old.env.lang:
+ if old.env.lang and callable(field.translate):
# the new value *without lang* must be the old value without lang
new_wo_lang[name] = old_wo_lang[name]
for vals in Translation.search_read(domain):
@@ -4372,6 +4372,7 @@ class BaseModel(object):
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]
# the value should be the new value (given by copy())
vals['value'] = new_val
Translation.create(vals)