[Python] How to pass context to a report in odoo 15

Discussão em 'Python' iniciado por Stack, Maio 20, 2025.

  1. Stack

    Stack Membro Participativo

    i have this problem.

    I want to set the lang to a report through the context like this:

    from odoo import api, fields, models

    class IncLoadUnloadMovement(models.TransientModel):
    _name = 'inc.load.unload.movement'
    _description = 'Wizard para imprimir orden con selección de idioma'

    movement_id = fields.Many2one(
    comodel_name='inc.movement',
    string="Movimiento",
    required=True,
    default=lambda self: self.env.context.get('default_movement_id')
    )

    lang = fields.Selection(
    selection=lambda self: self._get_lang_selection(),
    string="Idioma",
    required=True,
    default=lambda self: self.env.user.lang
    )

    @api.model
    def _get_lang_selection(self):
    langs = self.env['res.lang'].search([('code', 'in', ['es_ES', 'en_US'])], order='name')
    return [(lang.code, lang.name) for lang in langs]

    def action_print_load(self):
    self.ensure_one()
    report = self.env.ref('inc_trans_euconsa.action_report_load_temp')
    return report.with_context(lang=self.lang).report_action(self.movement_id)

    def action_print_unload(self):
    self.ensure_one()
    report = self.env.ref('inc_trans_euconsa.action_report_unload_temp')
    return report.with_context({'lang': self.lang}).report_action(self.movement_id)


    But my reports are still downloading in Spanish.

    I tried this 2 ways to set the context but none works

    And, in my report I have this:

    <template id="report_load_order_template_lang">
    <t t-call="web.html_container">
    <t t-foreach="docs" t-as="o">
    <t t-call="inc_trans_euconsa.report_load_order_template" t-lang="en_US"/>
    </t>
    </t>
    </template>

    <template id="report_unload_order_template_lang">
    <t t-call="web.html_container">
    <t t-foreach="docs" t-as="o">
    <t t-call="inc_trans_euconsa.report_unload_order_template" t-lang="env.context.get('lang')"/>
    </t>
    </t>
    </template>


    The first report, obviously is downloaded in English, but the second one only in Spanish

    Continue reading...

Compartilhe esta Página