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.

22 lines
882 B

  1. # Copyright 2018 Tecnativa - Ernesto Tejeda
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from odoo import _, api, models
  4. from odoo.exceptions import ValidationError
  5. class MailMassMailingContact(models.Model):
  6. _inherit = 'mail.mass_mailing.contact'
  7. @api.constrains('email', 'list_ids')
  8. def _check_email_list_ids(self):
  9. for contact in self:
  10. lists = contact.subscription_list_ids.mapped('list_id')
  11. lists |= contact.list_ids
  12. others = lists.mapped('contact_ids') - contact
  13. contact_email = contact.email.strip().lower()
  14. other_emails = [e.strip().lower() for e in others.mapped('email')]
  15. if contact_email in other_emails:
  16. raise ValidationError(_("Cannot have the same email more "
  17. "than once in the same list"))