From c6d718f2118a00a37d6ce35b84239a4990c07935 Mon Sep 17 00:00:00 2001 From: mreficent Date: Thu, 26 Apr 2018 18:50:30 +0000 Subject: [PATCH] [FIX] In new records *2many, enable to handle multiple RPC inputs closes odoo/odoo#24458 Signed-off-by: Raphael Collet (rco) --- .../test_new_api/tests/test_one2many.py | 19 ++++++++++++++++++- odoo/fields.py | 4 ++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/odoo/addons/test_new_api/tests/test_one2many.py b/odoo/addons/test_new_api/tests/test_one2many.py index 8531396fe48..03abaec4f2d 100644 --- a/odoo/addons/test_new_api/tests/test_one2many.py +++ b/odoo/addons/test_new_api/tests/test_one2many.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from openerp.tests.common import TransactionCase +from odoo.tests.common import TransactionCase class One2manyCase(TransactionCase): @@ -51,6 +51,8 @@ class One2manyCase(TransactionCase): self.multi.lines = self.multi.lines[:-1] self.assertEqual(len(self.multi.lines), 9) self.assertIn("hello", self.multi.lines.mapped('name')) + if not self.multi.id: + return # Invalidate the cache and check again; this crashes if the value # of self.multi.lines in cache contains new records self.multi.invalidate_cache() @@ -89,11 +91,26 @@ class One2manyCase(TransactionCase): self.multi.lines = [(0, 0, {"name": str(name)})] self.operations() + def test_rpcstyle_one_by_one_on_new(self): + self.multi = self.env["test_new_api.multi"].new({ + "name": "What is up?" + }) + for name in range(10): + self.multi.lines = [(0, 0, {"name": str(name)})] + self.operations() + def test_rpcstyle_single(self): """Check lines created with RPC style and added in one step""" self.multi.lines = [(0, 0, {'name': str(name)}) for name in range(10)] self.operations() + def test_rpcstyle_single_on_new(self): + self.multi = self.env["test_new_api.multi"].new({ + "name": "What is up?" + }) + self.multi.lines = [(0, 0, {'name': str(name)}) for name in range(10)] + self.operations() + def test_many2one_integer(self): """Test several models one2many with same inverse Integer field""" # utility function to convert records to tuples with id,name diff --git a/odoo/fields.py b/odoo/fields.py index 954d33ee683..4be470b31d1 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -2080,8 +2080,8 @@ class _RelationalMulti(_Relational): elif isinstance(value, (list, tuple)): # value is a list/tuple of commands, dicts or record ids comodel = record.env[self.comodel_name] - # determine the value ids; by convention empty on new records - ids = OrderedSet(record[self.name].ids if record.id else ()) + # determine the value ids + ids = OrderedSet(record[self.name]._ids) # modify ids with the commands for command in value: if isinstance(command, (tuple, list)):