From b035cfb7e9df10dcdcfdf371946aa77057e5393c Mon Sep 17 00:00:00 2001
From: Ravi Gohil <rgo@openerp.com>
Date: Mon, 17 Nov 2014 17:06:37 +0530
Subject: [PATCH] [FIX] email_template: missing translations in email template

When composing an email based on an email template, some parts of the template
(the result of name_get on fields) were not translated.
This was due to missing language in context when rendering the template.
Fixes #3708, opw 617309
---
 addons/email_template/email_template.py | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/addons/email_template/email_template.py b/addons/email_template/email_template.py
index c5e24b0da5fe..e5ea9a5bb83b 100644
--- a/addons/email_template/email_template.py
+++ b/addons/email_template/email_template.py
@@ -311,11 +311,14 @@ class email_template(osv.osv):
             context = {}
         report_xml_pool = self.pool.get('ir.actions.report.xml')
         template = self.get_email_template(cr, uid, template_id, res_id, context)
+        ctx = context.copy()
+        if template.lang:
+            ctx['lang'] = template._context.get('lang')
         values = {}
         for field in ['subject', 'body_html', 'email_from',
                       'email_to', 'email_recipients', 'email_cc', 'reply_to']:
             values[field] = self.render_template(cr, uid, getattr(template, field),
-                                                 template.model, res_id, context=context) \
+                                                 template.model, res_id, context=ctx) \
                                                  or False
         if template.user_signature:
             signature = self.pool.get('res.users').browse(cr, uid, uid, context).signature
@@ -333,12 +336,9 @@ class email_template(osv.osv):
         attachments = []
         # Add report in attachments
         if template.report_template:
-            report_name = self.render_template(cr, uid, template.report_name, template.model, res_id, context=context)
+            report_name = self.render_template(cr, uid, template.report_name, template.model, res_id, context=ctx)
             report_service = 'report.' + report_xml_pool.browse(cr, uid, template.report_template.id, context).report_name
             # Ensure report is rendered using template's language
-            ctx = context.copy()
-            if template.lang:
-                ctx['lang'] = self.render_template(cr, uid, template.lang, template.model, res_id, context)
             service = netsvc.LocalService(report_service)
             (result, format) = service.create(cr, uid, [res_id], {'model': template.model}, ctx)
             # TODO in trunk, change return format to binary to match message_post expected format
-- 
GitLab