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.

33 lines
1.2 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016-2017 Compassion CH (http://www.compassion.ch)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from odoo import models, api
  5. class EmailComposeMessage(models.TransientModel):
  6. _inherit = 'mail.compose.message'
  7. @api.model
  8. def mass_mailing_sendgrid(self, res_ids, composer_values):
  9. """ Helper to generate a new e-mail given a template and objects.
  10. :param res_ids: ids of the resource objects
  11. :param composer_values: values for the composer wizard
  12. :return: browse records of created e-mails (one per resource object)
  13. """
  14. if not isinstance(res_ids, list):
  15. res_ids = [res_ids]
  16. wizard = self.create(composer_values)
  17. all_mail_values = wizard.get_mail_values(res_ids)
  18. email_obj = self.env['mail.mail']
  19. emails = email_obj
  20. for res_id in res_ids:
  21. mail_values = all_mail_values[res_id]
  22. obj = self.env[wizard.model].browse(res_id)
  23. if wizard.model == 'res.partner':
  24. mail_values['recipient_ids'] = [(6, 0, obj.ids)]
  25. else:
  26. mail_values['email_to'] = obj.email
  27. emails += email_obj.create(mail_values)
  28. return emails