summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--odoo/addons/test_new_api/tests/test_new_fields.py29
-rw-r--r--odoo/fields.py1
2 files changed, 28 insertions, 2 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 c8956245aa6..3efb67ce3e2 100644
--- a/odoo/addons/test_new_api/tests/test_new_fields.py
+++ b/odoo/addons/test_new_api/tests/test_new_fields.py
@@ -1767,8 +1767,8 @@ class TestFields(TransactionCaseWithUserDemo):
[('author_partner.name', '=', 'Marc Demo')])
self.assertEqual(messages, self.env.ref('test_new_api.message_0_1'))
- def test_60_x2many_domain(self):
- """ test the cache consistency of a x2many field with a domain """
+ def test_60_one2many_domain(self):
+ """ test the cache consistency of a one2many field with a domain """
discussion = self.env.ref('test_new_api.discussion_0')
message = discussion.messages[0]
self.assertNotIn(message, discussion.important_messages)
@@ -1782,6 +1782,31 @@ class TestFields(TransactionCaseWithUserDemo):
self.assertFalse(discussion.very_important_messages)
self.assertFalse(message.exists())
+ def test_60_many2many_domain(self):
+ """ test the cache consistency of a many2many field with a domain """
+ discussion = self.env.ref('test_new_api.discussion_0')
+ category = self.env['test_new_api.category'].create({'name': "Foo"})
+ discussion.categories = category
+ discussion.flush()
+ discussion.invalidate_cache()
+
+ # patch the many2many field to give it a domain (this simply avoids
+ # adding yet another test model)
+ field = discussion._fields['categories']
+ self.patch(field, 'domain', [('color', '!=', 42)])
+ self.registry.setup_models(self.cr)
+
+ # the category is in the many2many
+ self.assertIn(category, discussion.categories)
+
+ # modify the category; it should not longer be in the many2many
+ category.color = 42
+ self.assertNotIn(category, discussion.categories)
+
+ # modify again the category; it should be back in the many2many
+ category.color = 69
+ self.assertIn(category, discussion.categories)
+
def test_70_x2many_write(self):
discussion = self.env.ref('test_new_api.discussion_0')
# See YTI FIXME
diff --git a/odoo/fields.py b/odoo/fields.py
index 126108fc12b..fc159a3dc89 100644
--- a/odoo/fields.py
+++ b/odoo/fields.py
@@ -3507,6 +3507,7 @@ class Many2many(_RelationalMulti):
context.update(self.context)
comodel = records.env[self.comodel_name].with_context(**context)
domain = self.get_domain_list(records)
+ comodel._flush_search(domain)
wquery = comodel._where_calc(domain)
comodel._apply_ir_rules(wquery, 'read')
order_by = comodel._generate_order_by(None, wquery)