From e1bf5bd97c93f05dbbff9fd2a6fb06b9cb69066b Mon Sep 17 00:00:00 2001 From: Simon Lejeune Date: Tue, 8 Apr 2014 15:49:53 +0200 Subject: [PATCH] [IMP] Report: renamed 'render_doc' method as 'translate_doc' for better understanding and added it a 'lang_field' attribute to explicitely set the lang. Adapted report_invoice, report_saleorder, report_overdue and report_intrastatinvoice this way. bzr revid: sle@openerp.com-20140408134953-vql9ft8cosoanixt --- addons/account/views/report_invoice.xml | 2 +- addons/account/views/report_overdue.xml | 2 +- addons/report/models/report.py | 25 +- .../views/report_intrastatinvoice.xml | 2 +- addons/sale/views/report_saleorder.xml | 250 +++++++++--------- 5 files changed, 140 insertions(+), 141 deletions(-) diff --git a/addons/account/views/report_invoice.xml b/addons/account/views/report_invoice.xml index 437c9726bf3..6757095a7d4 100644 --- a/addons/account/views/report_invoice.xml +++ b/addons/account/views/report_invoice.xml @@ -145,7 +145,7 @@ diff --git a/addons/account/views/report_overdue.xml b/addons/account/views/report_overdue.xml index 772e7661800..bc522aa8b9d 100644 --- a/addons/account/views/report_overdue.xml +++ b/addons/account/views/report_overdue.xml @@ -110,7 +110,7 @@ diff --git a/addons/report/models/report.py b/addons/report/models/report.py index f619b2db0cb..8dd8a4dce6f 100644 --- a/addons/report/models/report.py +++ b/addons/report/models/report.py @@ -23,6 +23,7 @@ from openerp.osv import osv from openerp.tools import config from openerp.tools.translate import _ from openerp.addons.web.http import request +from openerp.tools.safe_eval import safe_eval as eval import os import time @@ -103,17 +104,17 @@ class Report(osv.Model): view_obj = self.pool['ir.ui.view'] - def render_doc(doc_id, model, template): - """Helper used when a report should be translated into the associated - partner's lang. + def translate_doc(doc_id, model, lang_field, template): + """Helper used when a report should be translated into a specific lang. - + :param doc_id: id of the record to translate :param model: model of the record to translate - :param template: name of the template to translate into the partner's lang + :param lang_field': field of the record containing the lang + :param template: name of the template to translate into the lang_field """ ctx = context.copy() doc = self.pool[model].browse(cr, uid, doc_id, context=ctx) @@ -122,15 +123,9 @@ class Report(osv.Model): if ctx.get('translatable') is True: qcontext['o'] = doc else: - # Guessing the lang we want to translate the doc into - newlang = None - if doc._model._all_columns.get('partner_id'): - newlang = doc.partner_id.lang - elif doc._model._all_columns.get('lang'): - newlang = doc.lang - if newlang: - ctx['lang'] = newlang - qcontext['o'] = self.pool[model].browse(cr, uid, doc_id, context=ctx) + # Reach the lang we want to translate the doc into + ctx['lang'] = eval('doc.%s' % lang_field, {'doc': doc}) + qcontext['o'] = self.pool[model].browse(cr, uid, doc_id, context=ctx) return view_obj.render(cr, uid, template, qcontext, context=ctx) user = self.pool['res.users'].browse(cr, uid, uid) @@ -139,7 +134,7 @@ class Report(osv.Model): website = request.website values.update({ 'time': time, - 'render_doc': render_doc, + 'translate_doc': translate_doc, 'editable': True, # Will active inherit_branding 'user': user, 'res_company': user.company_id, diff --git a/addons/report_intrastat/views/report_intrastatinvoice.xml b/addons/report_intrastat/views/report_intrastatinvoice.xml index e8bce6e952d..c534f808c95 100644 --- a/addons/report_intrastat/views/report_intrastatinvoice.xml +++ b/addons/report_intrastat/views/report_intrastatinvoice.xml @@ -141,7 +141,7 @@ diff --git a/addons/sale/views/report_saleorder.xml b/addons/sale/views/report_saleorder.xml index 40c8afa045d..c23e680e664 100644 --- a/addons/sale/views/report_saleorder.xml +++ b/addons/sale/views/report_saleorder.xml @@ -1,131 +1,135 @@ + +