diff options
| author | Raphael Collet <rco@odoo.com> | 2020-03-10 16:33:05 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2020-03-23 09:04:59 +0000 |
| commit | fd50ba9fb838067fab0b920470cf79b9c94d785c (patch) | |
| tree | 4e7ebd1736c4584fbcb168282ca49e1cf9e6c730 /odoo/addons/test_new_api/tests/test_onchange.py | |
| parent | 8978b0bc8f335a4339e7868343a2767980d29f97 (diff) | |
[IMP] core: do not recompute stored field on new record
The use case is a cache miss of a stored field with compute on a new
record with origin. The field should be computed only when explicitly
triggered, i.e., when a dependency has been modified. Otherwise it
should be fetched from the origin record.
closes odoo/odoo#47353
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Diffstat (limited to 'odoo/addons/test_new_api/tests/test_onchange.py')
| -rw-r--r-- | odoo/addons/test_new_api/tests/test_onchange.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/odoo/addons/test_new_api/tests/test_onchange.py b/odoo/addons/test_new_api/tests/test_onchange.py index 5d544bd2875..398bd537bbd 100644 --- a/odoo/addons/test_new_api/tests/test_onchange.py +++ b/odoo/addons/test_new_api/tests/test_onchange.py @@ -678,3 +678,31 @@ class TestComputeOnchange(common.TransactionCase): form.foo = "foo6" self.assertEqual(form.bar, "foo6") self.assertEqual(form.baz, "baz5") + + def test_onchange_one2many(self): + record = self.env['test_new_api.model_parent_m2o'].create({ + 'name': 'Family', + 'child_ids': [ + (0, 0, {'name': 'W', 'cost': 10}), + (0, 0, {'name': 'X', 'cost': 10}), + (0, 0, {'name': 'Y'}), + (0, 0, {'name': 'Z'}), + ], + }) + record.flush() + self.assertEqual(record.child_ids.mapped('name'), list('WXYZ')) + self.assertEqual(record.cost, 22) + + # modifying a line should not recompute the cost on other lines + with common.Form(record) as form: + with form.child_ids.edit(1) as line: + line.name = 'XXX' + self.assertEqual(form.cost, 15) + + with form.child_ids.edit(1) as line: + line.cost = 20 + self.assertEqual(form.cost, 32) + + with form.child_ids.edit(2) as line: + line.cost = 30 + self.assertEqual(form.cost, 61) |
