mail_mass_mailing.py 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. # -*- coding: utf-8 -*-
  2. # © 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp import models, api, fields, _
  5. from openerp.exceptions import Warning as UserError
  6. class MailMassMailing(models.Model):
  7. _inherit = 'mail.mass_mailing'
  8. avoid_resend = fields.Boolean(
  9. string="Evitar reenvío",
  10. help="Evita el envío de este email dos veces "
  11. "al mismo receptor o cliente")
  12. @api.model
  13. def get_recipients(self, mailing):
  14. res_ids = super(MailMassMailing, self).get_recipients(mailing)
  15. if mailing.avoid_resend:
  16. already_sent = self.env['mail.mail.statistics'].search([
  17. ('mass_mailing_id', '=', mailing.id),
  18. ('model', '=', mailing.mailing_model),
  19. ])
  20. res_ids = list(set(res_ids).difference(
  21. already_sent.mapped('res_id')))
  22. if not res_ids:
  23. raise UserError(_(
  24. "No hay mas recipientes para enviar o 'Evitar Reenvio' "
  25. "Opcion Habilitada"))
  26. return res_ids