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.

39 lines
1.6 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 Therp BV <http://therp.nl>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp import api, fields, tools, models
  5. class MailTemplate(models.Model):
  6. _inherit = 'mail.template'
  7. body_type = fields.Selection(
  8. [('jinja2', 'Jinja2'), ('qweb', 'QWeb')], 'Body templating engine',
  9. default='jinja2', required=True)
  10. body_view_id = fields.Many2one(
  11. 'ir.ui.view', 'Body view', domain=[('type', '=', 'qweb')])
  12. body_view_arch = fields.Text(related=['body_view_id', 'arch'])
  13. @api.multi
  14. def generate_email(self, res_ids, fields=None):
  15. multi_mode = True
  16. if isinstance(res_ids, (int, long)):
  17. res_ids = [res_ids]
  18. multi_mode = False
  19. result = super(MailTemplate, self).generate_email(
  20. res_ids, fields=fields
  21. )
  22. for record_id, this in self.get_email_template(res_ids).iteritems():
  23. if this.body_type == 'qweb' and\
  24. (not fields or 'body_html' in fields):
  25. for record in self.env[this.model].browse(record_id):
  26. result[record_id]['body_html'] = self.render_post_process(
  27. this.body_view_id.render({
  28. 'object': record,
  29. 'email_template': this,
  30. })
  31. )
  32. result[record_id]['body'] = tools.html_sanitize(
  33. result[record_id]['body_html']
  34. )
  35. return multi_mode and result or result[res_ids[0]]