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
906 B

  1. # Copyright 2019 Komit <https://komit-consulting.com>
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  3. import logging
  4. from odoo import api, models, _
  5. from odoo.exceptions import UserError
  6. _logger = logging.getLogger(__name__)
  7. try:
  8. from validate_email import validate_email
  9. except ImportError:
  10. _logger.debug('Cannot import "validate_email".')
  11. def validate_email(email):
  12. _logger.warning(
  13. 'Can not validate email, '
  14. 'python dependency required "validate_email"')
  15. return True
  16. class ResPartner(models.Model):
  17. _inherit = 'res.partner'
  18. @api.constrains('email')
  19. def constrains_email(self):
  20. for rec in self.filtered("email"):
  21. self.email_check(rec.email)
  22. @api.model
  23. def email_check(self, email):
  24. if validate_email(email):
  25. return True
  26. raise UserError(_('Invalid e-mail!'))