[FIX] core: convert_to_write() of x2many field with new records
When comparing the values of a new record with its origin, x2many fields are always different because we compare new records with real records. For instance, converting the value of a one2many field where lines have a many2many field always returns update commands for the many2many field. closes odoo/odoo#66950 X-original-commit: 03a4137cc3fa398dbd0cb214dc5472a083ae33b8 Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
This commit is contained in:
@@ -1654,6 +1654,16 @@ class TestFields(TransactionCaseWithUserDemo):
|
||||
self.assertNotEqual(new_disc.participants, disc.participants)
|
||||
self.assertEqual(new_disc.participants._origin, disc.participants)
|
||||
|
||||
# check convert_to_write
|
||||
tag = self.env['test_new_api.multi.tag'].create({'name': 'Foo'})
|
||||
rec = self.env['test_new_api.multi'].create({
|
||||
'lines': [(0, 0, {'tags': [(6, 0, tag.ids)]})],
|
||||
})
|
||||
new = rec.new(origin=rec)
|
||||
self.assertEqual(new.lines.tags._origin, rec.lines.tags)
|
||||
vals = new._convert_to_write(new._cache)
|
||||
self.assertEqual(vals['lines'], [(6, 0, rec.lines.ids)])
|
||||
|
||||
def test_41_new_compute(self):
|
||||
""" Check recomputation of fields on new records. """
|
||||
move = self.env['test_new_api.move'].create({
|
||||
|
||||
+4
-1
@@ -3107,6 +3107,9 @@ class _RelationalMulti(_Relational):
|
||||
value = record.env[self.comodel_name].browse(value)
|
||||
|
||||
if isinstance(value, BaseModel) and value._name == self.comodel_name:
|
||||
def get_origin(val):
|
||||
return val._origin if isinstance(val, BaseModel) else val
|
||||
|
||||
# make result with new and existing records
|
||||
inv_names = {field.name for field in record._field_inverses[self]}
|
||||
result = [Command.set([])]
|
||||
@@ -3125,7 +3128,7 @@ class _RelationalMulti(_Relational):
|
||||
values = record._convert_to_write({
|
||||
name: record[name]
|
||||
for name in record._cache
|
||||
if name not in inv_names and record[name] != origin[name]
|
||||
if name not in inv_names and get_origin(record[name]) != origin[name]
|
||||
})
|
||||
if values:
|
||||
result.append(Command.update(origin.id, values))
|
||||
|
||||
Reference in New Issue
Block a user