diff options
| author | Xavier Morel <xmo@odoo.com> | 2020-07-17 08:38:21 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2020-07-20 11:42:58 +0000 |
| commit | b3761a8cba6f24bbcb4b35f14e076965d1210f69 (patch) | |
| tree | e610ddb26702da9f7d822e19ae2fabc02137c1f1 /odoo/addons/test_testing_utilities/tests/test_form_impl.py | |
| parent | 8f09ef294a6aa7a845114474658cf0b4f32c46e1 (diff) | |
[FIX] core: fix handling of removals in sub-o2m
Issue is specifically in the case of an onchange removing a record in
an o2m in an o2m (so a sub-o2m) if loading an *existing* record in the
SSF: since the server pretty much only returns a REMOVE_ALL followed
by the records to keep or create, conserving the removal information
requires diffing the value currently stored in the form and the result
fo the onchange.
Diff which was properly done for top-level o2ms, but not for the ones
below that (apparently forgot this bit when improving support for
nested o2ms earlier this year).
X-original-commit: 177d009541cca589c6ebb85fc051b893ec001536
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.py | 26 |
1 files changed, 26 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 6e108b43fb1..af49d27cbe5 100644 --- a/odoo/addons/test_testing_utilities/tests/test_form_impl.py +++ b/odoo/addons/test_testing_utilities/tests/test_form_impl.py @@ -667,6 +667,32 @@ class TestNestedO2M(TransactionCase): form.qty_producing = 2 form.save() + def test_remove(self): + """ onchanges can remove o2m records which haven't been loaded yet due + to lazy loading of o2ms. The removal information should still be + retained, otherwise due to the stateful update system we end up + retaining records we don't even know exist. + """ + # create structure with sub-sub-children + r = self.env['o2m_changes_parent'].create({ + 'name': "A", + 'line_ids': [ + (0, 0, { + 'name': 'line 1', + 'v': 42, + 'line_ids': [(0, 0, {'v': 1, 'vv': 1})], + }) + ] + }) + + with Form(r) as f: + f.name = 'B' + + self.assertEqual(len(r.line_ids), 1) + self.assertEqual(len(r.line_ids.line_ids), 1) + self.assertEqual(r.line_ids.line_ids.v, 0) + self.assertEqual(r.line_ids.line_ids.vv, 0) + class TestEdition(TransactionCase): """ These use the context manager form as we don't need the record post-save (we already have it) and it's easier to see what bits act on |
