diff options
| author | Christophe Monniez <moc@odoo.com> | 2021-03-03 12:33:20 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2021-03-03 13:24:52 +0000 |
| commit | d39855bad5153654d443d1b7ede3907f8bae3e66 (patch) | |
| tree | e1a5bc569cdad9785bfff798b483bb334dd466e3 /odoo/addons/test_new_api/tests/test_new_fields.py | |
| parent | f4136c3188e4f5df68a01f57d7d09ecf96be63b6 (diff) | |
[FIX] models: call inverse method right after cache invalidation
When a record is written on a computed field with an inverse method and
an x2many field wit a delete command, the computed field is not properly
handled by the inverse method, because of a whole cache invalidation
that happens during the unlink.
With this commit, we write in cache on the fields that have been
invalidated before invoking the inverse method.
opw #2439861
closes odoo/odoo#67152
Signed-off-by: Christophe Monniez (moc) <moc@odoo.com>
Co-authored-by: Raphael Collet <rco@odoo.com>
Diffstat (limited to 'odoo/addons/test_new_api/tests/test_new_fields.py')
| -rw-r--r-- | odoo/addons/test_new_api/tests/test_new_fields.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/odoo/addons/test_new_api/tests/test_new_fields.py b/odoo/addons/test_new_api/tests/test_new_fields.py index 5a50f5b2b18..61de1807c2c 100644 --- a/odoo/addons/test_new_api/tests/test_new_fields.py +++ b/odoo/addons/test_new_api/tests/test_new_fields.py @@ -628,6 +628,33 @@ class TestFields(TransactionCaseWithUserDemo): with self.assertRaises(AccessError): foo.with_user(user).display_name = 'Forbidden' + def test_13_inverse_with_unlink(self): + """ test x2many delete command combined with an inverse field """ + country1 = self.env['res.country'].create({'name': 'test country'}) + country2 = self.env['res.country'].create({'name': 'other country'}) + company = self.env['res.company'].create({ + 'name': 'test company', + 'child_ids': [ + (0, 0, {'name': 'Child Company 1'}), + (0, 0, {'name': 'Child Company 2'}), + ] + }) + child_company = company.child_ids[0] + + # check first that the field has an inverse and is not stored + field = type(company).country_id + self.assertFalse(field.store) + self.assertTrue(field.inverse) + + company.write({'country_id': country1.id}) + self.assertEqual(company.country_id, country1) + + company.write({ + 'country_id': country2.id, + 'child_ids': [(2, child_company.id)], + }) + self.assertEqual(company.country_id, country2) + def test_14_search(self): """ test search on computed fields """ discussion = self.env.ref('test_new_api.discussion_0') |
