[FIX] email_template: allow to modify render_template context

- add _prepare_render_template_context() method to email.template to allow
    modifying context used for rendering template.

  - override mail.compose.message wizard to use email.template's
    _prepare_render_template_context instead of mail's one.

bzr revid: xal@openerp.com-20120820083047-a52nj5e113c0lniz
This commit is contained in:
Xavier ALT
2012-08-20 10:30:47 +02:00
parent 9f7d2c697a
commit dc7ed565d6
2 changed files with 10 additions and 1 deletions
+7 -1
View File
@@ -78,6 +78,11 @@ class email_template(osv.osv):
logging.exception("failed to render mako template value %r", template)
return u""
def _prepare_render_template_context(self, cr, uid, model, res_id, context=None):
if context is None:
return {}
return context.copy()
def get_email_template(self, cr, uid, template_id=False, record_id=None, context=None):
if context is None:
context = {}
@@ -317,12 +322,13 @@ class email_template(osv.osv):
report_xml_pool = self.pool.get('ir.actions.report.xml')
template = self.get_email_template(cr, uid, template_id, res_id, context)
template_context = self._prepare_render_template_context(cr, uid, template.model, res_id, context)
for field in ['subject', 'body_text', 'body_html', 'email_from',
'email_to', 'email_cc', 'email_bcc', 'reply_to',
'message_id']:
values[field] = self.render_template(cr, uid, getattr(template, field),
template.model, res_id, context=context) \
template.model, res_id, context=template_context) \
or False
if values['body_html']:
@@ -204,4 +204,7 @@ class mail_compose_message(osv.osv_memory):
def render_template(self, cr, uid, template, model, res_id, context=None):
return self.pool.get('email.template').render_template(cr, uid, template, model, res_id, context=context)
def _prepare_render_template_context(self, cr, uid, model, res_id, context=None):
return self.pool.get('email.template')._prepare_render_template_context(cr, uid, model, res_id, context=context)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: