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.

64 lines
2.7 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. from odoo import api, models
  2. EMAIL_TEMPLATE_IDS = [
  3. "easy_my_coop_taxshelter_report.email_template_tax_shelter_certificate",
  4. ]
  5. class MailTemplate(models.Model):
  6. _inherit = "mail.template"
  7. def init(self):
  8. for template_id in EMAIL_TEMPLATE_IDS:
  9. mail_template = self.env.ref(template_id)
  10. mail_template.easy_my_coop = True
  11. @api.multi
  12. def send_mail_with_multiple_attachments(self, res_id,
  13. additional_attachments,
  14. force_send=False,
  15. raise_exception=False):
  16. """Generates a new mail message for the given template and record,
  17. and schedules it for delivery through the ``mail``
  18. module's scheduler.
  19. :param int res_id: id of the record to render the template with
  20. (model is taken from the template)
  21. :param bool force_send: if True, the generated mail.message is
  22. immediately sent after being created, as if the scheduler
  23. was executed for this message only.
  24. :returns: id of the mail.message that was created
  25. """
  26. self.ensure_one()
  27. Mail = self.env['mail.mail']
  28. # TDE FIXME: should remove dfeault_type from context
  29. Attachment = self.env['ir.attachment']
  30. # create a mail_mail based on values, without attachments
  31. values = self.generate_email(res_id)
  32. values['recipient_ids'] = [(4, pid) for pid in values.get('partner_ids', list())]
  33. attachment_ids = values.pop('attachment_ids', [])
  34. attachments = values.pop('attachments', [])
  35. # add a protection against void email_from
  36. if 'email_from' in values and not values.get('email_from'):
  37. values.pop('email_from')
  38. mail = Mail.create(values)
  39. # manage attachments
  40. attachments.extend(additional_attachments)
  41. for attachment in attachments:
  42. attachment_data = {
  43. 'name': attachment[0],
  44. 'datas_fname': attachment[0],
  45. 'datas': attachment[1],
  46. 'res_model': 'mail.message',
  47. 'res_id': mail.mail_message_id.id,
  48. }
  49. attachment_ids.append(Attachment.create(attachment_data).id)
  50. if attachment_ids:
  51. values['attachment_ids'] = [(6, 0, attachment_ids)]
  52. mail.write({'attachment_ids': [(6, 0, attachment_ids)]})
  53. if force_send:
  54. mail.send(raise_exception=raise_exception)
  55. return mail.id # TDE CLEANME: return mail + api.returns ?