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.

35 lines
1.4 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. result = super(MailTemplate, self).generate_email(
  16. res_ids, fields=fields
  17. )
  18. for record_id, this in self.get_email_template(res_ids).iteritems():
  19. if this.body_type == 'qweb' and\
  20. (not fields or 'body_html' in fields):
  21. for record in self.env[this.model].browse(record_id):
  22. result[record_id]['body_html'] = self.render_post_process(
  23. this.body_view_id.render({
  24. 'object': record,
  25. 'email_template': this,
  26. })
  27. )
  28. result[record_id]['body'] = tools.html_sanitize(
  29. result[record_id]['body_html']
  30. )
  31. return result