Skip to Content
Menu
This question has been flagged
2 Replies
6468 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

Avatar
Discard
Author

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

Best Answer

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)

Avatar
Discard
Author

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

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

Best Answer

@zbik

I have same problem here in Odoo V15 Community , but the method translate_doc not work 

How can I set the lang of the report.

Thank you and regards,

Avatar
Discard