[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 ce7f31b0b0, 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
This commit is contained in:
@@ -526,3 +526,8 @@ class TestGroups(TransactionCase):
|
||||
# create a cycle and check
|
||||
a.implied_ids = d
|
||||
self.assertFalse(a._check_m2m_recursion('implied_ids'))
|
||||
|
||||
def test_res_group_copy(self):
|
||||
a = self.env['res.groups'].with_context(lang='en_US').create({'name': 'A'})
|
||||
b = a.copy()
|
||||
self.assertFalse(a.name == b.name)
|
||||
|
||||
+2
-1
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user