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.

37 lines
1.5 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 EmailTemplate(models.Model):
  6. _inherit = 'email.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.model
  14. def generate_email_batch(self, template_id, res_ids, fields=None):
  15. result = super(EmailTemplate, self).generate_email_batch(
  16. template_id, res_ids, fields=fields)
  17. this = self.browse(template_id)
  18. for record_id, this in self.get_email_template_batch(
  19. template_id, res_ids
  20. ).iteritems():
  21. if this.body_type == 'qweb' and\
  22. (not fields or 'body_html' in fields):
  23. for record in self.env[this.model].browse(record_id):
  24. result[record_id]['body_html'] = self.render_post_process(
  25. this.body_view_id.render({
  26. 'object': record,
  27. 'email_template': this,
  28. })
  29. )
  30. result[record_id]['body'] = tools.html_sanitize(
  31. result[record_id]['body_html']
  32. )
  33. return result