2017-06-14 20:47:41 +02:00
|
|
|
# Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
|
|
|
# Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
|
|
|
# Copyright 2015 Javier Iniesta <javieria@antiun.com>
|
2020-02-10 11:40:11 +01:00
|
|
|
# Copyright 2020 Tecnativa - Manuel Calero
|
2016-08-08 13:14:37 +02:00
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
2015-08-28 11:15:50 +02:00
|
|
|
|
2020-02-10 11:35:23 +01:00
|
|
|
from odoo import _, api, fields, models
|
2018-11-09 13:24:39 +01:00
|
|
|
from odoo.exceptions import ValidationError
|
2015-08-28 11:15:50 +02:00
|
|
|
|
|
|
|
|
2020-02-10 11:40:11 +01:00
|
|
|
class MailingList(models.Model):
|
|
|
|
_inherit = "mailing.list"
|
2015-08-28 11:15:50 +02:00
|
|
|
|
2020-02-10 11:35:23 +01:00
|
|
|
partner_mandatory = fields.Boolean(string="Mandatory Partner", default=False)
|
|
|
|
partner_category = fields.Many2one(
|
|
|
|
comodel_name="res.partner.category", string="Partner Tag"
|
|
|
|
)
|
2018-11-09 13:24:39 +01:00
|
|
|
|
2020-02-10 11:35:23 +01:00
|
|
|
@api.constrains("contact_ids")
|
2018-11-09 13:24:39 +01:00
|
|
|
def _check_contact_ids_partner_id(self):
|
2020-02-10 11:40:11 +01:00
|
|
|
contact_obj = self.env["mailing.contact"]
|
2018-11-09 13:24:39 +01:00
|
|
|
for mailing_list in self:
|
|
|
|
data = contact_obj.read_group(
|
|
|
|
[
|
2020-02-10 11:35:23 +01:00
|
|
|
("id", "in", mailing_list.contact_ids.ids),
|
|
|
|
("partner_id", "!=", False),
|
2018-11-09 13:24:39 +01:00
|
|
|
],
|
2020-02-10 11:35:23 +01:00
|
|
|
["partner_id"],
|
|
|
|
["partner_id"],
|
2018-11-09 13:24:39 +01:00
|
|
|
)
|
2020-02-10 11:35:23 +01:00
|
|
|
if len(list(filter(lambda r: r["partner_id_count"] > 1, data))):
|
|
|
|
raise ValidationError(
|
|
|
|
_("A partner cannot be multiple times " "in the same list")
|
|
|
|
)
|