From d39855bad5153654d443d1b7ede3907f8bae3e66 Mon Sep 17 00:00:00 2001 From: Christophe Monniez Date: Wed, 3 Mar 2021 12:33:20 +0000 Subject: [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) Co-authored-by: Raphael Collet --- odoo/addons/test_new_api/tests/test_new_fields.py | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'odoo/addons/test_new_api/tests/test_new_fields.py') 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') -- cgit v1.2.3