diff options
| -rw-r--r-- | odoo/addons/test_new_api/tests/test_new_fields.py | 27 | ||||
| -rw-r--r-- | odoo/models.py | 5 |
2 files changed, 32 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') diff --git a/odoo/models.py b/odoo/models.py index 1f4c5ba0e2b..6bd10fde74a 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -3688,6 +3688,11 @@ Fields: real_recs._validate_fields(vals, inverse_fields) for fields in determine_inverses.values(): + # write again on non-stored fields that have been invalidated from cache + for field in fields: + if not field.store and any(self.env.cache.get_missing_ids(real_recs, field)): + field.write(real_recs, vals[field.name]) + # inverse records that are not being computed try: fields[0].determine_inverse(real_recs) |
