You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.3 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2015-TODAY LasLabs Inc.
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp import models, api, fields
  5. class ResUsers(models.Model):
  6. _inherit = 'res.users'
  7. login = fields.Char(
  8. 'Login',
  9. size=64,
  10. required=True,
  11. help='Used to log into the system. Case insensitive.',
  12. )
  13. @api.model
  14. def search(self, domain, *args, **kwargs):
  15. '''
  16. Overload search to lowercase name domains. Can't do in a typical
  17. search method due to the field not being computed
  18. '''
  19. for idx, _domain in enumerate(domain):
  20. if _domain[0] == 'login':
  21. lower = _domain[2].lower() if _domain[2] else False
  22. domain[idx] = (_domain[0], _domain[1], lower)
  23. return super(ResUsers, self).search(domain, *args, **kwargs)
  24. @api.model
  25. def create(self, vals, ):
  26. ''' Overload create to lowercase login '''
  27. vals['login'] = vals.get('login', '').lower()
  28. return super(ResUsers, self).create(vals)
  29. @api.multi
  30. def write(self, vals, ):
  31. ''' Overload write to lowercase login '''
  32. if vals.get('login'):
  33. vals['login'] = vals['login'].lower()
  34. return super(ResUsers, self).write(vals)