[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
This commit is contained in:
Simon Lejeune 2014-04-08 15:49:53 +02:00
parent 90422afbc9
commit e1bf5bd97c
5 changed files with 140 additions and 141 deletions

View File

@ -145,7 +145,7 @@
<template id="report_invoice">
<t t-call="report.html_container">
<t t-foreach="doc_ids" t-as="doc_id">
<t t-raw="render_doc(doc_id, doc_model, 'account.report_invoice_document')"/>
<t t-raw="translate_doc(doc_id, doc_model, 'partner_id.lang', 'account.report_invoice_document')"/>
</t>
</t>
</template>

View File

@ -110,7 +110,7 @@
<template id="report_overdue">
<t t-call="report.html_container">
<t t-foreach="doc_ids" t-as="doc_id">
<t t-raw="render_doc(doc_id, doc_model, 'account.report_overdue_document')"/>
<t t-raw="translate_doc(doc_id, doc_model, 'lang', 'account.report_overdue_document')"/>
</t>
</t>
</template>

View File

@ -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.
<t t-foreach="doc_ids" t-as="doc_id">
<t t-raw="render_doc(doc_id, doc_model, 'module.templatetocall')"/>
<t t-raw="translate_doc(doc_id, doc_model, 'partner_id.lang', account.report_invoice_document')"/>
</t>
: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,14 +123,8 @@ 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
# 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)
@ -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,

View File

@ -141,7 +141,7 @@
<template id="report_intrastatinvoice">
<t t-call="report.html_container">
<t t-foreach="doc_ids" t-as="doc_id">
<t t-raw="render_doc(doc_id, doc_model, 'report_intrastat.report_intrastatinvoice_document')"/>
<t t-raw="translate_doc(doc_id, doc_model, 'partner_id.lang', 'report_intrastat.report_intrastatinvoice_document')"/>
</t>
</t>
</template>

View File

@ -1,9 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="report_saleorder">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="o">
<template id="report_saleorder_document">
<t t-call="report.external_layout">
<div class="page">
<div class="oe_structure"/>
@ -126,6 +124,12 @@
<div class="oe_structure"/>
</div>
</t>
</template>
<template id="report_saleorder">
<t t-call="report.html_container">
<t t-foreach="doc_ids" t-as="doc_id">
<t t-raw="translate_doc(doc_id, doc_model, 'partner_id.lang', 'sale.report_saleorder_document')"/>
</t>
</t>
</template>