From bfcb9b3d81e995932cf8054eeec22b50bc00ad3a Mon Sep 17 00:00:00 2001 From: Giovanni Francesco Capalbo Date: Tue, 1 Oct 2019 11:26:15 +0200 Subject: [PATCH] [ADD] search function supporting case insensitive login --- .../models/res_users.py | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/auth_user_case_insensitive/models/res_users.py b/auth_user_case_insensitive/models/res_users.py index 501a098aa..5288b7372 100644 --- a/auth_user_case_insensitive/models/res_users.py +++ b/auth_user_case_insensitive/models/res_users.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Copyright 2015-2017 LasLabs Inc. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). - +import collections from odoo import api, fields, models @@ -32,3 +32,24 @@ class ResUsers(models.Model): if vals.get('login'): vals['login'] = vals['login'].lower() return super(ResUsers, self).write(vals) + + @api.model + def search(self, args, offset=0, limit=None, order=None, count=False): + """ + modify all search domains to replace login with login.lower() + """ + new_args = [] + for arg in args: + new_arg = arg + if len(arg) == 3 and arg[0] == 'login': + new_rvalue = arg[2] + if hasattr(arg[2], 'lower'): + new_rvalue = arg[2].lower() + elif isinstance(arg[2], collections.Iterable): + new_rvalue = [getattr( + x, 'lower', lambda: x)() for x in arg[2]] + new_arg = (new_arg[0], new_arg[1], new_rvalue) + new_args.append(new_arg) + return super(ResUsers, self).search( + args=new_args, offset=offset, limit=limit, + order=order, count=count)