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.

30 lines
1.0 KiB

  1. # Copyright 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
  2. # Copyright 2016 Tecnativa - Vicent Cubells
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo import models, api, _, tools
  5. from odoo.exceptions import ValidationError
  6. class MailMassMailingContact(models.Model):
  7. _inherit = "mail.mass_mailing.contact"
  8. @api.constrains('email', 'list_ids')
  9. def _check_email_list_ids(self):
  10. for contact in self:
  11. other_contact = self.search([
  12. ('email', '=ilike', tools.escape_psql(contact.email)),
  13. ('id', '!=', contact.id)
  14. ])
  15. if contact.list_ids & other_contact.mapped('list_ids'):
  16. raise ValidationError(_("Cannot have the same email more "
  17. "than once in the same list"))
  18. class MailMassMailingList(models.Model):
  19. _inherit = "mail.mass_mailing.list"
  20. _sql_constraints = [
  21. ("unique_name", "UNIQUE(name)",
  22. "Cannot have more than one lists with the same name.")
  23. ]