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.

31 lines
1.3 KiB

  1. # Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
  2. # Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
  3. # Copyright 2015 Javier Iniesta <javieria@antiun.com>
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. from odoo import api, fields, models, _
  6. from odoo.exceptions import ValidationError
  7. class MailMassMailingList(models.Model):
  8. _inherit = 'mail.mass_mailing.list'
  9. partner_mandatory = fields.Boolean(string="Mandatory Partner",
  10. default=False)
  11. partner_category = fields.Many2one(comodel_name='res.partner.category',
  12. string="Partner Tag")
  13. @api.constrains('contact_ids')
  14. def _check_contact_ids_partner_id(self):
  15. contact_obj = self.env['mail.mass_mailing.contact']
  16. for mailing_list in self:
  17. data = contact_obj.read_group(
  18. [
  19. ('id', 'in', mailing_list.contact_ids.ids),
  20. ('partner_id', '!=', False),
  21. ],
  22. ['partner_id'], ['partner_id']
  23. )
  24. if len(list(filter(lambda r: r['partner_id_count'] > 1, data))):
  25. raise ValidationError(_("A partner cannot be multiple times "
  26. "in the same list"))