summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphael Collet <rco@odoo.com>2021-02-25 16:56:52 +0000
committerRaphael Collet <rco@odoo.com>2021-02-26 15:07:09 +0000
commitb2235e2749504e6eee9e6f8090d1df54cf5971b7 (patch)
tree86c8f4a989f05e3f7914d56335fafe0ab09aabb8
parent71cc7212b1c1abad5d37e29f3a1f33f6e6cd2a81 (diff)
[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#66937 X-original-commit: 03a4137cc3fa398dbd0cb214dc5472a083ae33b8 Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
-rw-r--r--odoo/addons/test_new_api/tests/test_new_fields.py10
-rw-r--r--odoo/fields.py5
2 files changed, 14 insertions, 1 deletions
diff --git a/odoo/addons/test_new_api/tests/test_new_fields.py b/odoo/addons/test_new_api/tests/test_new_fields.py
index 3efb67ce3e2..5a50f5b2b18 100644
--- a/odoo/addons/test_new_api/tests/test_new_fields.py
+++ b/odoo/addons/test_new_api/tests/test_new_fields.py
@@ -1651,6 +1651,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({
diff --git a/odoo/fields.py b/odoo/fields.py
index fc159a3dc89..0396437a446 100644
--- a/odoo/fields.py
+++ b/odoo/fields.py
@@ -2978,6 +2978,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 = [(6, 0, [])]
@@ -2996,7 +2999,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((1, origin.id, values))