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

ODOO 14.0自定义QWEB报表下载文件名不生效问题求助

解决Odoo 14.0自定义按钮下载QWEB PDF报表文件名问题

问题场景

系统默认打印按钮可正常使用报表动作中print_report_name定义的动态文件名,但通过自定义按钮调用报表时,下载文件名始终为报表动作的name字段值(即Generate Report.pdf)。

解决方案

方法1:在Python函数中手动指定文件名

修改自定义按钮对应的Python函数,在返回报表动作时直接设置download_filename参数,覆盖默认文件名:

def generate_report(self):
    data = {
        'blabla': self.employee_id.name,
        'bla': self.employee_id.place_of_birth
    }
    # 调用目标报表动作
    report_ref = self.env.ref('module.action_generate_report')
    report_action = report_ref.report_action(self, data=data)
    # 生成自定义文件名(与print_report_name规则保持一致)
    custom_filename = f"Report - {self.name}.pdf"
    # 强制设置下载文件名
    report_action['download_filename'] = custom_filename
    return report_action

方法2:适配数据驱动报表的文件名生成(可选)

如果文件名需要依赖传递的data参数内容,可直接基于业务数据动态生成文件名:

# 示例:用员工姓名作为文件名一部分
custom_filename = f"Report - {self.employee_id.name}.pdf"
report_action['download_filename'] = custom_filename

原因说明

当通过自定义按钮调用report_action并传递data参数时,Odoo会将报表识别为数据驱动报表,而非默认的对象驱动报表,此时报表动作中配置的print_report_name无法正确解析object变量,导致默认使用报表动作的name作为文件名。手动设置download_filename可以强制指定下载文件名,解决该问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 07:55:04