diff options
| author | Raphael Collet <rco@odoo.com> | 2020-01-21 09:21:03 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2020-01-21 09:31:58 +0000 |
| commit | 9ce78bff5fb084de67034bf54a814d1f30ffda46 (patch) | |
| tree | 9c67c27bc5422dcfeed36231f77706179f7b9710 | |
| parent | 3b4cdbebf23f131e9f71a89674ab2f9e71f2784d (diff) | |
[FIX] core: search on one2many fields with context
Consider an x2many field `foo_ids` with `context={'active_test': False}`
in its definition, and a comodel with an active field. The value of the
field includes inactive records.
Now consider a search with a domain like `[('foo_ids.bar', op, value)]`.
The search should return all the records with corecords that satisfy the
domain `[('bar', op, value)]`, including inactive corecords, because the
field's context explicitly disables filtering on the active field.
closes odoo/odoo#43625
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
| -rw-r--r-- | odoo/addons/test_new_api/models/test_new_api.py | 1 | ||||
| -rw-r--r-- | odoo/addons/test_new_api/tests/test_new_fields.py | 16 | ||||
| -rw-r--r-- | odoo/osv/expression.py | 2 |
3 files changed, 18 insertions, 1 deletions
diff --git a/odoo/addons/test_new_api/models/test_new_api.py b/odoo/addons/test_new_api/models/test_new_api.py index d88ab0777aa..330eed18008 100644 --- a/odoo/addons/test_new_api/models/test_new_api.py +++ b/odoo/addons/test_new_api/models/test_new_api.py @@ -756,6 +756,7 @@ class ModelActiveField(models.Model): _name = 'test_new_api.model_active_field' _description = 'A model with active field' + name = fields.Char() active = fields.Boolean(default=True) parent_id = fields.Many2one('test_new_api.model_active_field') children_ids = fields.One2many('test_new_api.model_active_field', 'parent_id') 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 e5ad38974bc..0f6c7fe9bb5 100644 --- a/odoo/addons/test_new_api/tests/test_new_fields.py +++ b/odoo/addons/test_new_api/tests/test_new_fields.py @@ -1824,6 +1824,22 @@ class TestX2many(common.TransactionCase): self.assertEqual(parent.with_context(active_test=False).all_children_ids, all_children) self.assertEqual(parent.with_context(active_test=False).active_children_ids, act_children) + def test_12_active_test_one2many_search(self): + Model = self.env['test_new_api.model_active_field'] + parent = Model.create({}) + all_children = Model.create([ + {'name': 'A', 'parent_id': parent.id, 'active': True}, + {'name': 'B', 'parent_id': parent.id, 'active': False}, + ]) + + # a one2many field without context does not match its inactive children + self.assertIn(parent, Model.search([('children_ids.name', '=', 'A')])) + self.assertNotIn(parent, Model.search([('children_ids.name', '=', 'B')])) + + # a one2many field with active_test=False matches its inactive children + self.assertIn(parent, Model.search([('all_children_ids.name', '=', 'A')])) + self.assertIn(parent, Model.search([('all_children_ids.name', '=', 'B')])) + def test_search_many2many(self): """ Tests search on many2many fields. """ tags = self.env['test_new_api.multi.tag'] diff --git a/odoo/osv/expression.py b/odoo/osv/expression.py index 927c7fa739c..070396efb4d 100644 --- a/odoo/osv/expression.py +++ b/odoo/osv/expression.py @@ -909,7 +909,7 @@ class expression(object): # Making search easier when there is a left operand as one2many or many2many elif len(path) > 1 and field.store and field.type in ('many2many', 'one2many'): - right_ids = comodel.search([('.'.join(path[1:]), operator, right)]).ids + right_ids = comodel.with_context(**field.context).search([('.'.join(path[1:]), operator, right)]).ids leaf.leaf = (path[0], 'in', right_ids) push(leaf) |
