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.

34 lines
989 B

  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. @classmethod
  11. def _login(cls, db, login, password):
  12. """ Overload _login to lowercase the `login` before passing to the
  13. super """
  14. login = login.lower()
  15. return super(ResUsers, cls)._login(db, login, password)
  16. @api.model
  17. def create(self, vals):
  18. """ Overload create to lowercase login """
  19. vals['login'] = vals.get('login', '').lower()
  20. return super(ResUsers, self).create(vals)
  21. @api.multi
  22. def write(self, vals):
  23. """ Overload write to lowercase login """
  24. if vals.get('login'):
  25. vals['login'] = vals['login'].lower()
  26. return super(ResUsers, self).write(vals)