From af2eaae9418b09d9426bc2eb59e909802f33409c Mon Sep 17 00:00:00 2001 From: Xavier ALT Date: Mon, 21 Sep 2020 13:21:30 +0000 Subject: [PATCH] [FIX] core: add UPDATE as valid many2many command in SSF This commit fix the "Unsupported M2M command 1" raised `Form` helper. The `onchange()` method will in fact emit UPDATE command for many2many fields when the value submitted an the one in database has changed (this is the case for example for nested m2m in form views) OPW-2044631 closes odoo/odoo#59943 X-original-commit: 76bd8208a416cefab6becff9f2d7204c7d196201 Signed-off-by: Xavier Morel (xmo) Signed-off-by: Xavier ALT --- odoo/addons/test_testing_utilities/menu.xml | 24 +++++++++++++++++++ odoo/addons/test_testing_utilities/models.py | 1 + .../tests/test_form_impl.py | 5 +++- odoo/tests/common.py | 4 +++- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/odoo/addons/test_testing_utilities/menu.xml b/odoo/addons/test_testing_utilities/menu.xml index 0bf87b6d5f5..e20c740e8c8 100644 --- a/odoo/addons/test_testing_utilities/menu.xml +++ b/odoo/addons/test_testing_utilities/menu.xml @@ -152,6 +152,30 @@ + + M2M Change View + test_testing_utilities.f + +
+ + + + + + + + + + + + + + + + + +
+ Recursive Relation Test View test_testing_utilities.recursive diff --git a/odoo/addons/test_testing_utilities/models.py b/odoo/addons/test_testing_utilities/models.py index 8796526653a..aa79117e0b0 100644 --- a/odoo/addons/test_testing_utilities/models.py +++ b/odoo/addons/test_testing_utilities/models.py @@ -103,6 +103,7 @@ class M2MSub(models.Model): _description = 'Testing Utilities Subtraction 2' name = fields.Char() + m2o_ids = fields.Many2many('test_testing_utilities.m2o') class M2MChange2(models.Model): _name = 'test_testing_utilities.f' diff --git a/odoo/addons/test_testing_utilities/tests/test_form_impl.py b/odoo/addons/test_testing_utilities/tests/test_form_impl.py index ab846bda87e..d43051637f7 100644 --- a/odoo/addons/test_testing_utilities/tests/test_form_impl.py +++ b/odoo/addons/test_testing_utilities/tests/test_form_impl.py @@ -227,10 +227,13 @@ class TestM2M(TransactionCase): self.assertEqual(f.count, 1) def test_m2m_changed(self): + r1 = self.env['test_testing_utilities.m2o'].create({'name': "A"}) + r2 = self.env['test_testing_utilities.m2o'].create({'name': "B"}) + Sub = self.env['test_testing_utilities.sub2'] a = Sub.create({'name': 'a'}) b = Sub.create({'name': 'b'}) - c = Sub.create({'name': 'c'}) + c = Sub.create({'name': 'c', 'm2o_ids': [(6, 0, [r1.id, r2.id])]}) d = Sub.create({'name': 'd'}) f = Form(self.env['test_testing_utilities.f']) diff --git a/odoo/tests/common.py b/odoo/tests/common.py index 1074b116554..df1b5409232 100644 --- a/odoo/tests/common.py +++ b/odoo/tests/common.py @@ -2108,7 +2108,9 @@ class Form(object): else: ids = list(current[0][2]) for command in value: - if command[0] == 3: + if command[0] == 1: + ids.append(command[1]) + elif command[0] == 3: ids.remove(command[1]) elif command[0] == 4: ids.append(command[1])