# -*- coding: utf-8 -*-

from odoo import models, fields, api
from odoo.exceptions import ValidationError
import re

class res_users(models.Model):
    _inherit = 'res.users'

    login = fields.Char(required=True, help="Used to log into the system")

    @api.constrains('login')
    def formato_login(self):
       # Validar que el login tenga un arroba
       if self.login:
           if not re.match('^[(a-z0-9\_\-\.)]+@[(a-z0-9\_\-\.)]+\.[(a-z)]{2,15}$', self.login.lower()):
               raise ValidationError(('Formato de login invalido \n %s \n La forma correcta es: ejemplo@dominio.com' % (self.login).encode('utf-8')))
