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.

57 lines
2.4 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # This module copyright (C) 2012 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. class email_template(Model):
  24. _inherit = 'email.template'
  25. def _get_is_template_template(self, cr, uid, ids, fields_name, arg,
  26. context=None):
  27. cr.execute('''select
  28. id, (select count(*) > 0 from email_template e
  29. where email_template_id=email_template.id)
  30. from email_template
  31. where id in %s''', (tuple(ids),))
  32. return dict(cr.fetchall())
  33. _columns = {
  34. 'email_template_id': fields.many2one('email.template', 'Template'),
  35. 'is_template_template': fields.function(
  36. _get_is_template_template, type='boolean',
  37. string='Is a template template'),
  38. }
  39. def get_email_template(self, cr, uid, template_id=False, record_id=None,
  40. context=None):
  41. this = super(
  42. 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', 'body_text']:
  46. if this[field] and this.email_template_id[field]:
  47. this._data[this.id][field] = self.render_template(
  48. cr, uid, this.email_template_id[field],
  49. this.email_template_id.model,
  50. this.id, this._context)
  51. return this