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.1 KiB

  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="Avoid resend",
  10. help="Avoid to send this mass mailing email twice "
  11. "to the same recipient")
  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. "There is no more recipients to send and 'Avoid resend' "
  25. "option is enabled"))
  26. return res_ids