2018-11-09 13:24:39 +01:00
|
|
|
# Copyright 2018 Tecnativa - Ernesto Tejeda
|
2020-02-10 11:40:11 +01:00
|
|
|
# Copyright 2020 Tecnativa - Manuel Calero
|
2018-11-09 13:24:39 +01:00
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|
|
|
|
2020-02-10 11:35:23 +01:00
|
|
|
from odoo import _, api, models
|
2018-11-09 13:24:39 +01:00
|
|
|
from odoo.exceptions import ValidationError
|
|
|
|
|
|
|
|
|
2020-02-10 11:40:11 +01:00
|
|
|
class MailingContactSubscription(models.Model):
|
|
|
|
_inherit = "mailing.contact.subscription"
|
2018-11-09 13:24:39 +01:00
|
|
|
|
2020-02-10 11:35:23 +01:00
|
|
|
@api.constrains("contact_id", "list_id")
|
2018-11-09 13:24:39 +01:00
|
|
|
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
|
2020-02-10 11:35:23 +01:00
|
|
|
if rel.contact_id.partner_id in contacts.mapped("partner_id"):
|
|
|
|
raise ValidationError(
|
2020-02-10 11:40:11 +01:00
|
|
|
_("A partner cannot be multiple times in the same list")
|
2020-02-10 11:35:23 +01:00
|
|
|
)
|