social/mass_mailing_partner/models/mail_mass_mailing_list_contact_rel.py
2022-01-01 16:22:47 +01:00

20 lines
752 B
Python

# Copyright 2018 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import _, api, models
from odoo.exceptions import ValidationError
class MassMailingContactListRel(models.Model):
_inherit = "mail.mass_mailing.list_contact_rel"
@api.constrains("contact_id", "list_id")
def _check_contact_id_partner_id_list_id(self):
for rel in self:
if rel.contact_id.partner_id:
contacts = rel.list_id.contact_ids - rel.contact_id
if rel.contact_id.partner_id in contacts.mapped("partner_id"):
raise ValidationError(
_("A partner cannot be multiple " "times in the same list")
)