diff --git a/addons/edi/models/edi.py b/addons/edi/models/edi.py index 589922ff178..d083ff4ce87 100644 --- a/addons/edi/models/edi.py +++ b/addons/edi/models/edi.py @@ -681,5 +681,17 @@ class EDIMixin(object): self._edi_import_attachments(cr, uid, record_id, edi_document, context=context) return record_id + +class mail_compose_message(osv.osv_memory): + _inherit = 'mail.compose.message' + + def _pre_render_template(self, cr, uid, active_model, active_id, context): + if active_model in ['account.invoice', 'sale.order', 'purchase.order']: + web_root_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url') + edi_record = self.pool.get(active_model).browse(cr, uid, active_id, context) + edi_token = self.pool.get('edi.document').export_edi(cr, uid, [edi_record])[0] + ctx = dict(context, edi_web_url_view=EDI_VIEW_WEB_URL % (web_root_url, cr.dbname, edi_token)) + context.update(ctx) + return super(mail_compose_message,self)._pre_render_template(cr, uid, active_model, active_id, context) # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index af8baa314de..ed10f0f0c34 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -216,13 +216,14 @@ class mail_compose_message(osv.osv_memory): active_ids = active_model_pool.search(cr, uid, ast.literal_eval(mail.filter_id.domain), context=ast.literal_eval(mail.filter_id.context)) for active_id in active_ids: - subject = self.render_template(cr, uid, mail.subject, active_model, active_id) - rendered_body = self.render_template(cr, uid, body, active_model, active_id) - email_from = self.render_template(cr, uid, mail.email_from, active_model, active_id) - email_to = self.render_template(cr, uid, mail.email_to, active_model, active_id) - email_cc = self.render_template(cr, uid, mail.email_cc, active_model, active_id) - email_bcc = self.render_template(cr, uid, mail.email_bcc, active_model, active_id) - reply_to = self.render_template(cr, uid, mail.reply_to, active_model, active_id) + self._pre_render_template(cr, uid, active_model, active_id, context) + subject = self.render_template(cr, uid, mail.subject, active_model, active_id, context) + rendered_body = self.render_template(cr, uid, body, active_model, active_id, context) + email_from = self.render_template(cr, uid, mail.email_from, active_model, active_id, context) + email_to = self.render_template(cr, uid, mail.email_to, active_model, active_id, context) + email_cc = self.render_template(cr, uid, mail.email_cc, active_model, active_id, context) + email_bcc = self.render_template(cr, uid, mail.email_bcc, active_model, active_id, context) + reply_to = self.render_template(cr, uid, mail.reply_to, active_model, active_id, context) # in mass-mailing mode we only schedule the mail for sending, it will be # processed as soon as the mail scheduler runs. @@ -241,6 +242,9 @@ class mail_compose_message(osv.osv_memory): return {'type': 'ir.actions.act_window_close'} + def _pre_render_template(self, cr, uid, active_model, active_id, context): + return True + def render_template(self, cr, uid, template, model, res_id, context=None): """Render the given template text, replace mako-like expressions ``${expr}`` with the result of evaluating these expressions with an evaluation context