[IMP] Replace translate_doc method by t-lang attribute as this method is deprecated

now that we have a cleaner system to switch translation when calling a qweb template.
      Update the docstring too.

  Replace :
    <t t-foreach="doc_ids" t-as="doc_id">
    <t t-raw="translate_doc(doc_id, doc_model, 'partner_id.lang', account.report_invoice_document')"/>
    </t>
  By :
    <t t-foreach="doc_ids" t-as="doc_id">
    <t t-call="'account.report_invoice_document" t-lang="doc_id.partner_id.lang"/>µ
    </t>

  Impacted modules : acccount, purchase, report_intrastat.
This commit is contained in:
Yannick Tivisse
2015-07-17 14:48:41 +02:00
parent f38ebb36b4
commit 09affe7cdf
7 changed files with 14 additions and 53 deletions
+5 -4
View File
@@ -3,6 +3,7 @@
<data>
<template id="report_invoice_document">
<t t-call="report.external_layout">
<t t-set="o" t-value="o.with_context({'lang':o.partner_id.lang})" />
<div class="page">
<div class="row">
<div class="col-xs-5 col-xs-offset-7">
@@ -152,8 +153,8 @@
<template id="report_invoice">
<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', 'account.report_invoice_document')"/>
<t t-foreach="docs" t-as="o">
<t t-call="account.report_invoice_document" t-lang="o.partner_id.lang"/>
</t>
</t>
</template>
@@ -169,8 +170,8 @@
<template id="account_invoice_report_duplicate_main">
<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', 'account.account_invoice_report_duplicate')"/>
<t t-foreach="docs" t-as="o">
<t t-call="account.account_invoice_report_duplicate" t-lang="o.partner_id.lang"/>
</t>
</t>
</template>
@@ -15,7 +15,6 @@ class PosInvoiceReport(osv.AbstractModel):
posorder_obj = self.pool['pos.order']
report = report_obj._get_report_from_name(cr, uid, 'account.report_invoice')
selected_orders = posorder_obj.browse(cr, uid, ids, context=context)
ids_to_print = []
invoiced_posorders_ids = []
for order in selected_orders:
@@ -3,6 +3,7 @@
<data>
<template id="report_purchaseorder_document">
<t t-call="report.external_layout">
<t t-set="o" t-value="o.with_context({'lang':o.partner_id.lang})"/>
<div class="page">
<div class="oe_structure"/>
<div class="row">
@@ -121,8 +122,8 @@
<template id="report_purchaseorder">
<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', 'purchase.report_purchaseorder_document')"/>
<t t-foreach="docs" t-as="o">
<t t-call="purchase.report_purchaseorder_document" t-lang="o.partner_id.lang"/>
</t>
</t>
</template>
@@ -3,6 +3,7 @@
<data>
<template id="report_purchasequotation_document">
<t t-call="report.external_layout">
<t t-set="o" t-value="o.with_context({'lang':o.partner_id.lang})"/>
<div class="page">
<div class="oe_structure"/>
@@ -61,8 +62,8 @@
<template id="report_purchasequotation">
<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', 'purchase.report_purchasequotation_document')"/>
<t t-foreach="docs" t-as="o">
<t t-call="purchase.report_purchasequotation_document" t-lang="o.partner_id.lang"/>
</t>
</t>
</template>
-28
View File
@@ -70,30 +70,6 @@ class Report(osv.Model):
# Extension of ir_ui_view.render with arguments frequently used in reports
#--------------------------------------------------------------------------
def translate_doc(self, cr, uid, doc_id, model, lang_field, template, values, context=None):
"""Helper used when a report should be translated into a specific lang.
<t t-foreach="doc_ids" t-as="doc_id">
<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 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)
qcontext = values.copy()
# Do not force-translate if we chose to display the report in a specific lang
if ctx.get('translatable') is True:
qcontext['o'] = doc
else:
# 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 self.pool['ir.ui.view'].render(cr, uid, template, qcontext, context=ctx)
def render(self, cr, uid, ids, template, values=None, context=None):
"""Allow to render a QWeb template python-side. This function returns the 'ir.ui.view'
render but embellish it with some variables/methods used in reports.
@@ -111,9 +87,6 @@ class Report(osv.Model):
view_obj = self.pool['ir.ui.view']
def translate_doc(doc_id, model, lang_field, template):
return self.translate_doc(cr, uid, doc_id, model, lang_field, template, values, context=context)
user = self.pool['res.users'].browse(cr, uid, uid)
website = None
if request and hasattr(request, 'website'):
@@ -124,7 +97,6 @@ class Report(osv.Model):
values.update(
time=time,
context_timestamp=lambda t: fields.datetime.context_timestamp(cr, uid, t, context),
translate_doc=translate_doc,
editable=True,
user=user,
res_company=user.company_id,
@@ -3,6 +3,7 @@
<data>
<template id="report_intrastatinvoice_document">
<t t-call="report.external_layout">
<t t-set="o" t-value="o.with_context({'lang':o.partner_id.lang})"/>
<div class="page">
<div class="row">
<div class="col-xs-5 col-xs-offset-7">
@@ -143,8 +144,8 @@
<template id="report_intrastatinvoice">
<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', 'report_intrastat.report_intrastatinvoice_document')"/>
<t t-foreach="docs" t-as="o">
<t t-call="report_intrastat.report_intrastatinvoice_document" t-lang="o.partner_id.lang"/>
</t>
</t>
</template>
-14
View File
@@ -8,20 +8,6 @@ from openerp.osv import osv
class Report(osv.Model):
_inherit = 'report'
def translate_doc(self, cr, uid, doc_id, model, lang_field, template, values, context=None):
if request and hasattr(request, 'website'):
if request.website is not None:
v = request.website.get_template(template)
request.session['report_view_ids'].append({
'name': v.name,
'id': v.id,
'xml_id': v.xml_id,
'inherit_id': v.inherit_id.id,
'header': False,
'active': v.active,
})
return super(Report, self).translate_doc(cr, uid, doc_id, model, lang_field, template, values, context=context)
def render(self, cr, uid, ids, template, values=None, context=None):
if request and hasattr(request, 'website'):
if request.website is not None: