summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Theys <seb@odoo.com>2020-01-22 17:06:38 +0000
committerSébastien Theys <seb@odoo.com>2020-01-24 17:13:05 +0000
commit25708586a709649e8b505e89723671dd58d9800e (patch)
treed67f9c3fbccb7e836bd271df99fdcc34504d56a4
parente7aeb6eb072c77723b99bd26ab29ede4deee12f8 (diff)
[FIX] fields, test_new_api: fix m2m commands in batch
Before this commit executing m2m commands in batch would lead to undesired results, such as duplicating the related records on every subsequent record of the batch. Indeed since [1] the `create` and `unlink` are called in a loop, but their content was not reset at each iteration. [1] 9920f20e4c7753bc17bea71dea3a90f7de687196 closes odoo/odoo#43950 X-original-commit: 0800f64b011c8f020c0d7dd6e1c149aebd1a4627 Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
-rw-r--r--odoo/addons/test_new_api/tests/test_new_fields.py8
-rw-r--r--odoo/fields.py5
2 files changed, 10 insertions, 3 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 e79e3c306fa..e5ad38974bc 100644
--- a/odoo/addons/test_new_api/tests/test_new_fields.py
+++ b/odoo/addons/test_new_api/tests/test_new_fields.py
@@ -1936,6 +1936,14 @@ class TestX2many(common.TransactionCase):
result = recs.search([('id', 'in', recs.ids), ('lines', '!=', False)])
self.assertEqual(result, recs - recZ)
+ def test_create_batch_m2m(self):
+ lines = self.env['test_new_api.multi.line'].create([{
+ 'tags': [(0, 0, {'name': str(j)}) for j in range(3)],
+ } for i in range(3)])
+ self.assertEqual(len(lines), 3)
+ for line in lines:
+ self.assertEqual(len(line.tags), 3)
+
class TestHtmlField(common.TransactionCase):
diff --git a/odoo/fields.py b/odoo/fields.py
index 8569558aa1b..be1a765afed 100644
--- a/odoo/fields.py
+++ b/odoo/fields.py
@@ -3355,10 +3355,9 @@ class Many2many(_RelationalMulti):
for ys1 in new_relation.values():
ys1 -= ys
- to_create = [] # line vals to create
- to_delete = [] # line ids to delete
-
for recs, commands in records_commands_list:
+ to_create = [] # line vals to create
+ to_delete = [] # line ids to delete
for command in (commands or ()):
if not isinstance(command, (list, tuple)) or not command:
continue