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.

61 lines
2.6 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # This module copyright (C) 2013 Therp BV (<http://therp.nl>).
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from openerp.osv.orm import Model
  22. from openerp.osv import fields
  23. from openerp.addons.email_template.email_template import mako_template_env
  24. class email_template(Model):
  25. _inherit = 'email.template'
  26. def _get_is_template_template(self, cr, uid, ids, fields_name, arg,
  27. context=None):
  28. cr.execute('''select
  29. id, (select count(*) > 0 from email_template e
  30. where email_template_id=email_template.id)
  31. from email_template
  32. where id in %s''', (tuple(ids),))
  33. return dict(cr.fetchall())
  34. _columns = {
  35. 'email_template_id': fields.many2one('email.template', 'Template'),
  36. 'is_template_template': fields.function(
  37. _get_is_template_template, type='boolean',
  38. string='Is a template template'),
  39. }
  40. def get_email_template(self, cr, uid, template_id=False, record_id=None,
  41. context=None):
  42. this = super(email_template, self).get_email_template(
  43. cr, uid, template_id, record_id, context)
  44. if this.email_template_id and not this.is_template_template:
  45. for field in ['body_html']:
  46. if this[field] and this.email_template_id[field]:
  47. try:
  48. mako_template_env.autoescape = False
  49. this._data[this.id][field] = self.render_template(
  50. cr, uid, this.email_template_id[field],
  51. this.email_template_id.model,
  52. this.id, this._context)
  53. finally:
  54. mako_template_env.autoescape = True
  55. return this