[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
This commit is contained in:
Denis Ledoux
2016-06-20 10:53:37 +02:00
parent 39a7ce44b0
commit 1061cb5696
+8 -2
View File
@@ -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: