From d57cd2d3ce07564f23d13503c9b856123d704912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=A1zquez=20Acosta?= Date: Tue, 9 Apr 2019 19:05:18 +0000 Subject: [PATCH] [FIX] base: Correct optimization of name_search Commit 5fcf891e07bf61518e6bf0be0dc4f27859d45778 introduced 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 by 5fcf891e07bf61518e6bf0be0dc4f27859d45778, 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) --- odoo/addons/base/models/res_users.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/odoo/addons/base/models/res_users.py b/odoo/addons/base/models/res_users.py index 7b584ba8234..1fde49a8d22 100644 --- a/odoo/addons/base/models/res_users.py +++ b/odoo/addons/base/models/res_users.py @@ -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)