From 922d77a29100453d831f61df9411715b383605df Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 22 Mar 2019 12:43:50 +0000 Subject: [FIX] core: infinite recursion in SSF on self-recursive models The extra setup probably affects any o2m whose edition view itself contains an o2m, but most likely to blow up entirely on models with some sort of tree structure (parent/child relationship): the SSF eagerly loads and setups the o2m's view, and the o2m's o2m's, ... ad infinitam. A better / cleaner fix would be to set up the subview on-demand (and possibly cache it), but the rest of the o2m stuff is unlikely to work correctly recursively so just don't recurse the o2m view setup at all for now. fixes #31458 --- odoo/addons/test_testing_utilities/tests/test_form_impl.py | 3 +++ 1 file changed, 3 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 c13dbd73a60..6b18fb229df 100644 --- a/odoo/addons/test_testing_utilities/tests/test_form_impl.py +++ b/odoo/addons/test_testing_utilities/tests/test_form_impl.py @@ -467,6 +467,9 @@ class TestO2M(TransactionCase): self.assertEqual(commands(), [0, 2, 2], "should contain 1 '0' command and 2 deletions") self.assertEqual(len(r.line_ids), 1) + def test_o2m_self_recursive(self): + Form(self.env['test_testing_utilities.recursive'], view='test_testing_utilities.o2m_recursive_relation_view') + 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 -- cgit v1.2.3 From ef8df8fb4efeb61ea1880cbe04c0a6bf74d5fc37 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 22 Mar 2019 12:22:04 +0000 Subject: [FIX] core: don't send readonly fields in o2m in SSF The SSF would correctly filter out readonly fields when saving a toplevel form, however it could not remove readonly values when saving o2m pseudo-records to the parent form (as these would be expected to remain available for reading upon the next edition and whatnot), so these values would get sent in 0/1 commands. Filter out these fields during the parent / toplevel save call. Complexity notes: * evaluating readonly modifiers requires the entire record, so unchanged fields still have to be written back to the parent form and be filtered out when *it* is set up for save, an alternative would be to store the `changed` and `readonly` flags alongside the record dict, and have the post-process only override the pre-computed readonly flag using force_save * had to fix a test to match the new behaviour, the post-edition states turns out to be in line with the client's behaviour (or how it looks anyway) Fixes #32019 --- .../test_testing_utilities/tests/test_form_impl.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (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 6b18fb229df..0191a4da7ad 100644 --- a/odoo/addons/test_testing_utilities/tests/test_form_impl.py +++ b/odoo/addons/test_testing_utilities/tests/test_form_impl.py @@ -359,7 +359,7 @@ class TestO2M(TransactionCase): self.assertEqual( [get(s) for s in r.subs], - [("5", 2, 5)] + [("5", 0, 5)] ) def test_o2m_inner_default(self): @@ -409,7 +409,10 @@ class TestO2M(TransactionCase): self.assertEqual(sub.value, 1) self.assertEqual(sub.v, 1) - def test_m2o_readonly(self): + def test_readonly_o2m(self): + """ Tests that o2m fields flagged as readonly (readonly="1" in the + view) can't be written to + """ r = self.env['test_testing_utilities.parent'].create({ 'subs': [(0, 0, {})] }) @@ -422,6 +425,20 @@ class TestO2M(TransactionCase): with self.assertRaises(AssertionError): f.subs.remove(index=0) + def test_o2m_readonly_subfield(self): + """ Tests that readonly is applied to the field of the o2m = not sent + as part of the create / write values + """ + f = Form(self.env['o2m_readonly_subfield_parent']) + with f.line_ids.new() as new_line: + new_line.name = "ok" + self.assertEqual(new_line.f, 2) + r = f.save() + self.assertEqual( + (r.line_ids.name, r.line_ids.f), + ('ok', 2) + ) + def test_o2m_dyn_onchange(self): f = Form(self.env['test_testing_utilities.onchange_parent'], view='test_testing_utilities.m2o_onchange_view') -- cgit v1.2.3