[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) <xmo@odoo.com>
Signed-off-by: Xavier ALT <xavieralt@users.noreply.github.com>
This commit is contained in:
Xavier ALT
2020-10-14 08:23:22 +00:00
parent 550d2935bd
commit af2eaae941
4 changed files with 32 additions and 2 deletions
@@ -152,6 +152,30 @@
</field>
</record>
<record id="m2m_change_view" model="ir.ui.view">
<field name="name">M2M Change View</field>
<field name="model">test_testing_utilities.f</field>
<field name="arch" type="xml">
<form>
<field name="m2o"/>
<field name="m2m" nolabel="1">
<tree>
<field name="name"/>
<field name="m2o_ids" widget="many2many_tags"/>
</tree>
<form>
<field name="name"/>
<field name="m2o_ids">
<tree>
<field name="name"/>
</tree>
</field>
</form>
</field>
</form>
</field>
</record>
<record id="o2m_recursive_relation_view" model="ir.ui.view">
<field name="name">Recursive Relation Test View</field>
<field name="model">test_testing_utilities.recursive</field>
@@ -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'
@@ -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'])
+3 -1
View File
@@ -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])