You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Odoo 15中如何通过上下文传递报表语言?设置无效求助

问题解决:Odoo 15报表动态设置语言不生效

核心问题原因

你的报表模板中直接使用t-lang="env.context.get('lang')"是错误写法——QWeb会把这个值当作字符串字面量处理,而非执行Odoo表达式获取上下文里的语言值,因此实际生效的是系统默认语言(西班牙语)。

修复步骤

1. 修改报表模板的动态语言绑定方式

将t-lang替换为t-att-lang,这是QWeb中绑定动态属性值的标准语法,会自动计算表达式结果:

<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-att-lang="env.context.get('lang')"/>
        </t>
    </t>
</template>

2. 确认上下文传递有效性

你的向导代码中两种上下文传递方式均有效,无需修改:

  • report.with_context(lang=self.lang).report_action(self.movement_id)
  • report.with_context({'lang': self.lang}).report_action(self.movement_id)

额外检查点

  • 确认系统已安装并启用目标语言(如en_US)的翻译包,可在设置 > 翻译 > 导入翻译中检查状态
  • 验证报表动作inc_trans_euconsa.action_report_unload_temp关联的模板确实是修改后的report_unload_order_template_lang
  • 可在模板中临时添加调试代码,确认上下文语言值是否正确传递:
    <!-- 在模板开头添加调试代码 -->
    <span t-esc="env.context.get('lang')"/>
    

内容的提问来源于stack exchange,提问作者tomasraigal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 02:50:00