Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

setLang in new reporting engine (QWeb/Twitter Bootstrap/Wkhtmltopdf)

By
Giulio Marcon
on 12/27/14, 4:45 PM 1,892 views

Dear experts,

I was using setLang in the old RML based reporting engine to force the locale of the printed reports, but I cannot use it anymore on the new reporting engine.

I tried with <t t-esc="setLang('de_DE')"/> but I get the error:

QWebException: ""'NoneType' object is not callable" while evaluating
"setLang('de_DE')""

How can I set the locale with the new reporting engine?

 

Thank you and regards,

Giulio

Hi zbik, thank you for your answer. How can I force a language for translate_doc though? I would like for instance to force the document to be produced always with the German (de_DE) locale. Any parameter I pass as the third parameter to translate_doc is used as an accessor to a field of the object doc. I see in the coding of translate_doc that it checks for a translatable value in the context (if false, apparently the language can be forced), but I do not understand how this value in the context could be set.. Thank you and regards, Giulio

Giulio Marcon
on 12/28/14, 11:22 AM
1

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 12/28/14, 10:50 AM

See example in report_invoice.xml:

<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>
</template>

translate_doc() - is a helper used when a report should be translated into a specific lang

A generic report use the default rendering context. If you want a new rendering context containing anything you want to process your data Odoo AbstractModel, a custom module is needed, like this:

from openerp import api, models

class ParticularReport(models.AbstractModel):
    _name = 'report.<<module.reportname>>'
    @api.multi
    def render_html(self, data=None):
        report_obj = self.env['report']
        report = report_obj._get_report_from_name('<<module.reportname>>')
        docargs = {
            'doc_ids': self._ids,
            'doc_model': report.model,
            'docs': self,
        }
        
        ctx = dict(self._context)
        ctx['translatable'] = True
        report_obj = report_obj.with_context(ctx)
        
        return report_obj.render('<<module.reportname>>', docargs)

Hi zbik, thank you for your answer. How can I force a language for translate_doc though? I would like for instance to force the document to be produced always with the German (de_DE) locale. Any parameter I pass as the third parameter to translate_doc is used as an accessor to a field of the object doc. I see in the coding of translate_doc that it checks for a translatable value in the context (if false, apparently the language can be forced), but I do not understand how this value in the context could be set.. Thank you and regards, Giulio

Giulio Marcon
on 12/28/14, 11:23 AM

It use 'partner_id.lang'. If someone have other field, how language is set for any other field?

Ubaid
on 12/22/15, 1:23 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

4 follower(s)

Stats

Asked: 12/27/14, 4:45 PM
Seen: 1892 times
Last updated: 3/16/15, 8:10 AM