From 1061cb5696b8e68170d23cba1d60dfebb64e1733 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Mon, 20 Jun 2016 10:53:37 +0200 Subject: [PATCH] [FIX] expression: search on *2many fields with domain Some one2many fields have a domain specified in their definition e.g. `mail.thread`.`message_follower_ids` `hr.applicant`.`attachment_ids` `project.task`.`attachment_ids` which is required for the one2many field to make sense. For the mail thread, it does not make sense to include the followers of other models with the same `res_id`. This domain must be took into account when doing a 'like' search on the one2many field e.g. Followers contains demo Otherwise it will include threads from other model opw-680825 --- openerp/osv/expression.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/openerp/osv/expression.py b/openerp/osv/expression.py index 6e3d775bc54..13413f2fbf5 100644 --- a/openerp/osv/expression.py +++ b/openerp/osv/expression.py @@ -961,7 +961,10 @@ class expression(object): if right is not False: if isinstance(right, basestring): op = {'!=': '=', 'not like': 'like', 'not ilike': 'ilike'}.get(operator, operator) - ids2 = [x[0] for x in comodel.name_search(cr, uid, right, [], op, context=context, limit=None)] + domain = column._domain + if callable(domain): + domain = domain(model) + ids2 = [x[0] for x in comodel.name_search(cr, uid, right, domain or [], op, context=context, limit=None)] if ids2: operator = 'not in' if operator in NEGATIVE_TERM_OPERATORS else 'in' elif isinstance(right, collections.Iterable): @@ -1012,7 +1015,10 @@ class expression(object): if right is not False: if isinstance(right, basestring): op = {'!=': '=', 'not like': 'like', 'not ilike': 'ilike'}.get(operator, operator) - res_ids = [x[0] for x in comodel.name_search(cr, uid, right, [], op, context=context, limit=None)] + domain = column._domain + if callable(domain): + domain = domain(model) + res_ids = [x[0] for x in comodel.name_search(cr, uid, right, domain or [], op, context=context, limit=None)] if res_ids: operator = 'not in' if operator in NEGATIVE_TERM_OPERATORS else 'in' else: