[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,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,

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,131 +1,135 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="report_saleorder_document">
<t t-call="report.external_layout">
<div class="page">
<div class="oe_structure"/>
<div class="row">
<div class="col-xs-6">
<p t-if="o.partner_shipping_id == o.partner_invoice_id">Invoice and shipping address:</p>
<p t-if="o.partner_shipping_id != o.partner_invoice_id">Invoice address: </p>
<div t-field="o.partner_invoice_id"
t-field-options='{"widget": "contact", "fields": ["address", "name", "phone", "fax"], "no_marker": true}'/>
<p t-if="o.partner_id.vat">VAT: <span t-field="o.partner_id.vat"/></p>
<div t-if="o.partner_shipping_id != o.partner_invoice_id">
<p>Shipping address :</p>
<div t-field="o.partner_shipping_id"
t-field-options='{"widget": "contact", "fields": ["address", "name", "phone", "fax"], "no_marker": true}'/>
<p t-if="o.partner_id.vat">VAT: <span t-field="o.partner_id.vat"/></p>
</div>
</div>
<div class="col-xs-4 col-xs-offset-2">
<div t-field="o.partner_id"
t-field-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": true}' />
</div>
</div>
<h2>
<span t-if="o.state not in ['draft','sent']">Order N° </span>
<span t-if="o.state in ['draft','sent']">Quotation N° </span>
<span t-field="o.name"/>
</h2>
<div class="row mt32 mb32">
<div t-if="o.client_order_ref" class="col-xs-3">
<strong>Your Reference:</strong>
<p t-field="o.client_order_ref"/>
</div>
<div t-if="o.date_order" class="col-xs-3">
<strong t-if="o.state not in ['draft','sent']">Date Ordered:</strong>
<strong t-if="o.state in ['draft','sent']">Quotation Date:</strong>
<p t-field="o.date_order"/>
</div>
<div t-if="o.user_id.name" class="col-xs-3">
<strong>Salesperson:</strong>
<p t-field="o.user_id.name"/>
</div>
<div t-if="o.payment_term" class="col-xs-3">
<strong>Payment Term:</strong>
<p t-field="o.payment_term"/>
</div>
</div>
<table class="table table-condensed">
<thead>
<tr>
<th>Description</th>
<th>Taxes</th>
<th class="text-right">Quantity</th>
<th class="text-right">Unit Price</th>
<th groups="sale.group_discount_per_so_line">Disc.(%)</th>
<th class="text-right">Price</th>
</tr>
</thead>
<tbody class="sale_tbody">
<tr t-foreach="o.order_line" t-as="l">
<td>
<span t-field="l.name"/>
</td>
<td>
<span t-esc="', '.join(map(lambda x: x.name, l.tax_id))"/>
</td>
<td class="text-right">
<span t-field="l.product_uom_qty"/>
<span groups="product.group_uom" t-field="l.product_uom"/>
</td>
<td class="text-right">
<span t-field="l.price_unit"/>
</td>
<td groups="sale.group_discount_per_so_line">
<span t-field="l.discount"/>
</td>
<td class="text-right">
<span t-field="l.price_subtotal"
t-field-options='{"widget": "monetary", "display_currency": "o.pricelist_id.currency_id"}'/>
</td>
</tr>
</tbody>
</table>
<div class="row">
<div class="col-xs-4 pull-right">
<table class="table table-condensed">
<tr class="border-black">
<td><strong>Total Without Taxes</strong></td>
<td class="text-right">
<span t-field="o.amount_untaxed"
t-field-options='{"widget": "monetary", "display_currency": "o.pricelist_id.currency_id"}'/>
</td>
</tr>
<tr>
<td>Taxes</td>
<td class="text-right">
<span t-field="o.amount_tax"
t-field-options='{"widget": "monetary", "display_currency": "o.pricelist_id.currency_id"}'/>
</td>
</tr>
<tr class="border-black">
<td><strong>Total</strong></td>
<td class="text-right">
<span t-field="o.amount_total"
t-field-options='{"widget": "monetary", "display_currency": "o.pricelist_id.currency_id"}'/>
</td>
</tr>
</table>
</div>
</div>
<p t-field="o.note" />
<p t-if="o.payment_term">
<strong>Payment Term:</strong>
<span t-field="o.payment_term"/>
</p>
<div class="oe_structure"/>
</div>
</t>
</template>
<template id="report_saleorder">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="report.external_layout">
<div class="page">
<div class="oe_structure"/>
<div class="row">
<div class="col-xs-6">
<p t-if="o.partner_shipping_id == o.partner_invoice_id">Invoice and shipping address:</p>
<p t-if="o.partner_shipping_id != o.partner_invoice_id">Invoice address: </p>
<div t-field="o.partner_invoice_id"
t-field-options='{"widget": "contact", "fields": ["address", "name", "phone", "fax"], "no_marker": true}'/>
<p t-if="o.partner_id.vat">VAT: <span t-field="o.partner_id.vat"/></p>
<div t-if="o.partner_shipping_id != o.partner_invoice_id">
<p>Shipping address :</p>
<div t-field="o.partner_shipping_id"
t-field-options='{"widget": "contact", "fields": ["address", "name", "phone", "fax"], "no_marker": true}'/>
<p t-if="o.partner_id.vat">VAT: <span t-field="o.partner_id.vat"/></p>
</div>
</div>
<div class="col-xs-4 col-xs-offset-2">
<div t-field="o.partner_id"
t-field-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": true}' />
</div>
</div>
<h2>
<span t-if="o.state not in ['draft','sent']">Order N° </span>
<span t-if="o.state in ['draft','sent']">Quotation N° </span>
<span t-field="o.name"/>
</h2>
<div class="row mt32 mb32">
<div t-if="o.client_order_ref" class="col-xs-3">
<strong>Your Reference:</strong>
<p t-field="o.client_order_ref"/>
</div>
<div t-if="o.date_order" class="col-xs-3">
<strong t-if="o.state not in ['draft','sent']">Date Ordered:</strong>
<strong t-if="o.state in ['draft','sent']">Quotation Date:</strong>
<p t-field="o.date_order"/>
</div>
<div t-if="o.user_id.name" class="col-xs-3">
<strong>Salesperson:</strong>
<p t-field="o.user_id.name"/>
</div>
<div t-if="o.payment_term" class="col-xs-3">
<strong>Payment Term:</strong>
<p t-field="o.payment_term"/>
</div>
</div>
<table class="table table-condensed">
<thead>
<tr>
<th>Description</th>
<th>Taxes</th>
<th class="text-right">Quantity</th>
<th class="text-right">Unit Price</th>
<th groups="sale.group_discount_per_so_line">Disc.(%)</th>
<th class="text-right">Price</th>
</tr>
</thead>
<tbody class="sale_tbody">
<tr t-foreach="o.order_line" t-as="l">
<td>
<span t-field="l.name"/>
</td>
<td>
<span t-esc="', '.join(map(lambda x: x.name, l.tax_id))"/>
</td>
<td class="text-right">
<span t-field="l.product_uom_qty"/>
<span groups="product.group_uom" t-field="l.product_uom"/>
</td>
<td class="text-right">
<span t-field="l.price_unit"/>
</td>
<td groups="sale.group_discount_per_so_line">
<span t-field="l.discount"/>
</td>
<td class="text-right">
<span t-field="l.price_subtotal"
t-field-options='{"widget": "monetary", "display_currency": "o.pricelist_id.currency_id"}'/>
</td>
</tr>
</tbody>
</table>
<div class="row">
<div class="col-xs-4 pull-right">
<table class="table table-condensed">
<tr class="border-black">
<td><strong>Total Without Taxes</strong></td>
<td class="text-right">
<span t-field="o.amount_untaxed"
t-field-options='{"widget": "monetary", "display_currency": "o.pricelist_id.currency_id"}'/>
</td>
</tr>
<tr>
<td>Taxes</td>
<td class="text-right">
<span t-field="o.amount_tax"
t-field-options='{"widget": "monetary", "display_currency": "o.pricelist_id.currency_id"}'/>
</td>
</tr>
<tr class="border-black">
<td><strong>Total</strong></td>
<td class="text-right">
<span t-field="o.amount_total"
t-field-options='{"widget": "monetary", "display_currency": "o.pricelist_id.currency_id"}'/>
</td>
</tr>
</table>
</div>
</div>
<p t-field="o.note" />
<p t-if="o.payment_term">
<strong>Payment Term:</strong>
<span t-field="o.payment_term"/>
</p>
<div class="oe_structure"/>
</div>
</t>
<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>