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.

38 lines
1.2 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2015-2017 LasLabs Inc.
  3. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
  4. from odoo import api, fields, models
  5. class ResUsers(models.Model):
  6. _inherit = 'res.users'
  7. login = fields.Char(
  8. help='Used to log into the system. Case insensitive.',
  9. )
  10. @api.model
  11. def search(self, domain, *args, **kwargs):
  12. """ Overload search to lowercase name domains. This can't be done in
  13. a regular search method as the field is not computed
  14. """
  15. for idx, _domain in enumerate(domain):
  16. if _domain[0] == 'login':
  17. lower = _domain[2].lower() if _domain[2] else False
  18. domain[idx] = (_domain[0], _domain[1], lower)
  19. return super(ResUsers, self).search(domain, *args, **kwargs)
  20. @api.model
  21. def create(self, vals):
  22. """ Overload create to lowercase login """
  23. vals['login'] = vals.get('login', '').lower()
  24. return super(ResUsers, self).create(vals)
  25. @api.multi
  26. def write(self, vals):
  27. """ Overload write to lowercase login """
  28. if vals.get('login'):
  29. vals['login'] = vals['login'].lower()
  30. return super(ResUsers, self).write(vals)