From e36ad5b0b01aca802e835b82e1fbb79a0d40e659 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 21 Feb 2019 10:20:49 +0000 Subject: [FIX] core: handling of o2m record deletion in SSF The SSF would properly mark its own records as deleted, but it would not properly handle deletion requests coming from an onchange, and it would not necessarily convert DELETE_ALL commands (5) into the proper sequence of individual (2)s matching existing records. closes odoo/odoo#31431 --- .../test_testing_utilities/tests/test_form_impl.py | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'odoo/addons/test_testing_utilities/tests/test_form_impl.py') 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 344ae62f4d2..c13dbd73a60 100644 --- a/odoo/addons/test_testing_utilities/tests/test_form_impl.py +++ b/odoo/addons/test_testing_utilities/tests/test_form_impl.py @@ -432,6 +432,40 @@ class TestO2M(TransactionCase): with f.line_ids.edit(index=0) as new_line: self.assertTrue(new_line.flag) + def test_o2m_remove(self): + def commands(): + return [c[0] for c in f._values['line_ids']] + f = Form(self.env['test_testing_utilities.onchange_count']) + + self.assertEqual(f.count, 0) + self.assertEqual(len(f.line_ids), 0) + + f.count = 5 + self.assertEqual(f.count, 5) + self.assertEqual(len(f.line_ids), 5) + + f.count = 2 + self.assertEqual(f.count, 2) + self.assertEqual(len(f.line_ids), 2) + + f.count = 4 + + r = f.save() + + previous = r.line_ids + self.assertEqual(len(previous), 4) + + with Form(r) as f: + f.count = 2 + self.assertEqual(commands(), [0, 0, 2, 2, 2, 2], "Should contain 2 creations and 4 deletions") + self.assertEqual(len(r.line_ids), 2) + + with Form(r) as f: + f.line_ids.remove(0) + self.assertEqual(commands(), [2, 1]) + f.count = 1 + self.assertEqual(commands(), [0, 2, 2], "should contain 1 '0' command and 2 deletions") + self.assertEqual(len(r.line_ids), 1) class TestEdition(TransactionCase): """ These use the context manager form as we don't need the record -- cgit v1.2.3