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.2 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2019 Coop IT Easy SCRL fs
  3. # Robin Keunen <robin@coopiteasy.be>
  4. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  5. from openerp import models, api, _, fields
  6. from openerp.exceptions import ValidationError
  7. from openerp.tools import config
  8. class ResPartner(models.Model):
  9. _inherit = "res.partner"
  10. email = fields.Char(copy=False)
  11. @api.multi
  12. @api.constrains('email')
  13. def _check_email(self):
  14. if config['test_enable'] and not self.env.context.get(
  15. 'test_partner_email_unique'):
  16. return
  17. for partner in self:
  18. domain = [
  19. ('id', '!=', partner.id),
  20. ('email', '=', partner.email),
  21. ('email', '!=', False),
  22. ]
  23. other_partners = self.search(domain)
  24. # active_test is False when called from
  25. # base.partner.merge.automatic.wizard
  26. if other_partners and self.env.context.get("active_test", True):
  27. raise ValidationError(
  28. _("This email is already set to partner '%s'")
  29. % other_partners[0].display_name)