Browse Source

[ADD] search function supporting case insensitive login

10.0
Giovanni Francesco Capalbo 5 years ago
parent
commit
bfcb9b3d81
  1. 23
      auth_user_case_insensitive/models/res_users.py

23
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)
Loading…
Cancel
Save