summaryrefslogtreecommitdiff
path: root/odoo/addons/test_testing_utilities/tests/test_form_impl.py
diff options
context:
space:
mode:
authorXavier Morel <xmo@odoo.com>2019-02-21 10:20:49 +0000
committerXavier Morel <xmo@odoo.com>2019-02-26 13:18:57 +0000
commite36ad5b0b01aca802e835b82e1fbb79a0d40e659 (patch)
treeed539cff24b2c283a73cbbcd2c0c2451432ebf26 /odoo/addons/test_testing_utilities/tests/test_form_impl.py
parentca6d495ebf489d4388bebdbc20dd410fb6324919 (diff)
[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
Diffstat (limited to 'odoo/addons/test_testing_utilities/tests/test_form_impl.py')
-rw-r--r--odoo/addons/test_testing_utilities/tests/test_form_impl.py34
1 files changed, 34 insertions, 0 deletions
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