[FIX] base: Correct optimization of name_search
Commit5fcf891e07introduced optimizations for name_search in several models. However, that produces some counter-intuitive searches. In a DB with project and custom data: >>> Project = self.env['project.task'] >>> Project.search([('user_id', 'ilike', 'demo')]).mapped('user_id.name') ['Marc Demo'] >>> Project.search([('user_id', 'not ilike', 'demo')]).mapped('user_id.name') ['Marc Demo'] The projects returned with 'not ilike' are a super-set of those returned with 'ilike': >>> Project.search([('user_id', 'ilike', 'demo')]) project.task(22, 21, 20, 16, 14, 13) >>> Project.search([('user_id', 'not ilike', 'demo')]) project.task(22, 21, 29, 28, 27, 26, 25, 20, 16, 14, 13, 31, 30) This commit fix this behaviour by choosing '!=' instead of '=' whenever the operator is a negation operator. The 'res.users' is more exposed than the other models touched by5fcf891e07, because user may search for 'Created by' in the web client. closes odoo/odoo#40140 X-original-commit: b3c539b09a0bd462309a10c565cb91375a7011b9 Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
committed by
fw-bot
parent
3942308bc4
commit
d57cd2d3ce
@@ -548,7 +548,10 @@ class Users(models.Model):
|
||||
if operator == 'ilike' and not (name or '').strip():
|
||||
domain = []
|
||||
else:
|
||||
domain = [('login', '=', name)]
|
||||
if operator not in expression.NEGATIVE_TERM_OPERATORS:
|
||||
domain = [('login', '=', name)]
|
||||
else:
|
||||
domain = [('login', '!=', name)]
|
||||
user_ids = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
|
||||
if not user_ids:
|
||||
user_ids = self._search(expression.AND([[('name', operator, name)], args]), limit=limit, access_rights_uid=name_get_uid)
|
||||
|
||||
Reference in New Issue
Block a user