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.

36 lines
1.1 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 LasLabs Inc.
  3. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
  4. from odoo import _
  5. from odoo.exceptions import ValidationError
  6. def pre_init_hook_login_check(cr):
  7. """This hook will look to see if any conflicting logins exist before
  8. the module is installed
  9. :param openerp.sql_db.Cursor cr:
  10. Database cursor.
  11. """
  12. with cr.savepoint():
  13. users = []
  14. cr.execute("SELECT login FROM res_users")
  15. for user in cr.fetchall():
  16. login = user[0].lower()
  17. if login not in users:
  18. users.append(login)
  19. else:
  20. raise ValidationError(
  21. _('Conflicting user logins exist for `%s`' % login)
  22. )
  23. def post_init_hook_login_convert(cr, registry):
  24. """After the module is installed, set all logins to lowercase
  25. :param openerp.sql_db.Cursor cr:
  26. Database cursor.
  27. :param openerp.modules.registry.RegistryManager registry:
  28. Database registry, using v7 api.
  29. """
  30. with cr.savepoint():
  31. cr.execute("UPDATE res_users SET login=lower(login)")