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

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