[FIX] fields: x2many value overrides default value on new records

When instantiating a new record, the commands of an x2many field apply
on an empty recordset instead of the field's default value.  This is
less bug-prone, and avoids an infinite recursion in `convert_to_cache`.
This commit is contained in:
Raphael Collet
2019-06-13 15:01:29 +00:00
parent ef3a2118f6
commit 26bf8ca880
2 changed files with 3 additions and 3 deletions
@@ -958,9 +958,9 @@ class TestFields(common.TransactionCase):
# no value gives the default value
new_disc = discussion.new({'name': "Foo"})
self.assertEqual(new_disc.categories._origin, cat1)
# value is combined with default value
# value overrides default value
new_disc = discussion.new({'name': "Foo", 'categories': [(4, cat2.id)]})
self.assertEqual(new_disc.categories._origin, cat1 + cat2)
self.assertEqual(new_disc.categories._origin, cat2)
def test_40_new_fields(self):
""" Test new records with relational fields. """
+1 -1
View File
@@ -2321,7 +2321,7 @@ class _RelationalMulti(_Relational):
else:
browse = comodel.browse
# determine the value ids
ids = OrderedSet(record[self.name]._ids)
ids = OrderedSet(record[self.name]._ids if validate else ())
# modify ids with the commands
for command in value:
if isinstance(command, (tuple, list)):