diff options
| author | Xavier Morel <xmo@odoo.com> | 2020-01-09 12:14:27 +0000 |
|---|---|---|
| committer | Xavier Morel <xmo@odoo.com> | 2020-01-13 16:24:17 +0000 |
| commit | 9d74b1f73a92b9030438f590f729bb7866cba191 (patch) | |
| tree | 01c83948fe32241cfc3b3bb8b6899665c70d71f0 /odoo/addons/test_testing_utilities/tests/test_form_impl.py | |
| parent | ba69b1d534883960dceb49ed558d3a4229864e97 (diff) | |
[FIX] core: saving of o2m value init'd via onchange
In the SSF, o2m updates get initialized with no values (1, id,
{}). The record data is only fetched when the "record" gets updated
explicitly from which updates will hopefully get properly tracked &
saved.
However if the "record" was first initialized through an onchange
values which are updated by the onchange (diverging from the db) those
would not get tracked and thus wouldn't get saved when the record is
saved.
* use more specific placeholder (None) for "o2m records to update but
we don't have values yet"
* once we have values, always store them as an update-tracking dict
* if we don't have values yet for an o2m and an onchange is trying to
write to it, initialize with values from database first (might
eventually be a good idea to initialize upfront though there's the
question of what happens for default values and recursive views)
* mark anything coming back from the onchange and differing from local
values as changed (so they get sent out on save)
* properly reify parent values for onchange instead of sending them
as-is
* the evaluation context for contexts (and domains) needs properly
formatted values so use `_values_to_save` to get them, however it
cares about neither required-ing nor filtering out e.g. unmodified
fields, therefore add an awful toggle to handle this
Task 2150302
Probably todo in the future:
* better UI for change-tracking dict, should have "snapshot"
support (to freeze / discard previous changes)
* cleanup save, it's unclear that it properly resets the form
closes odoo/odoo#43235
X-original-commit: 6c99fe3ffec3aeb8d210e3b943ccef81d62d44ce
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
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 | 38 |
1 files changed, 38 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 3c1d53bd6da..cc2620f9e46 100644 --- a/odoo/addons/test_testing_utilities/tests/test_form_impl.py +++ b/odoo/addons/test_testing_utilities/tests/test_form_impl.py @@ -534,6 +534,44 @@ class TestO2M(TransactionCase): a | b | c ) + def test_o2m_onchange_change_saved(self): + """ If an onchange updates o2m values (in existing sub-records of an + existing record), those updated values should be saved, both if the + sub-records were touched by the user and not (check that one maybe) + """ + # create record: line created before v is updated should reflect it, + # line created after should not + f = Form(self.env['o2m_changes_children']) + with f.line_ids.new() as line: + line.v = 1 + line.vv = 5 + f.v = 5 + with f.line_ids.new() as line: + ... + r = f.save() + self.assertEqual(r.v, 5) + self.assertEqual(r.mapped('line_ids.vv'), [5, 0]) + self.assertEqual(r.line_ids[0].v, 5, "onchange should have updated the existing lines") + self.assertEqual(r.line_ids[1].v, 0, "onchange should not impact new line") + + # update record: onchange then touch the lines + with Form(r) as f: + f.v = 6 + with f.line_ids.edit(0) as line: + line.vv = 1 + with f.line_ids.edit(1) as line: + line.vv = 2 + self.assertEqual(r.v, 6) + self.assertEqual(r.mapped('line_ids.vv'), [1, 2]) + self.assertEqual(r.mapped('line_ids.v'), [6, 6], "onchange should have updated vs") + + # update record: onchange then don't even touch the lines + with Form(r) as f: + f.v = 7 + self.assertEqual(r.v, 7) + self.assertEqual(r.mapped('line_ids.vv'), [1, 2]) + self.assertEqual(r.mapped('line_ids.v'), [7, 7]) + 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 |
