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

Odoo14自动保存PDF报告至附件报错问题求助

Odoo14 报表PDF自动保存附件报错解决

报错信息

报表模板'test'存在错误,请联系管理员。

无法将文件分离保存为附件,因为报表模板中带有'article'类的div未包含'data-oe-model'和'data-oe-id'属性。

现有代码

报表动作定义

<report id="report_action_test"
        string="test"
        model="stock.picking"
        report_type="qweb-pdf"
        name="Vija_waybill_stock_picking_report.new_report_stock_waybill"
        file="Vija_waybill_stock_picking_report.new_report_stock_waybill"
        attachment_use="True"
        attachment="'test-' + object.name + '.pdf'"
/>

报表模板

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
    <template id="new_report_stock_waybill">
        <t t-call="web.html_container">
            <t t-call="web.basic_layout">
                <div class="page" t-att-data-oe-model="o and o._name" t-att-data-oe-id="o and o.id">
                    <t t-raw="0"/>
                    <span>
                        this is a test
                    </span>
                </div>
            </t>
        </t>
    </template>
</odoo>

问题原因

Odoo自动保存报表PDF为附件时,依赖模板中带有article类的div元素,通过该元素的data-oe-model和data-oe-id属性关联对应业务记录。当前模板里的div仅包含page类,缺少article类,导致系统无法识别关联的模型与记录ID。

解决方法

修改报表模板中的div,在保留page类(保证页面布局正常)的同时添加article类,属性绑定逻辑保持不变:

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
    <template id="new_report_stock_waybill">
        <t t-call="web.html_container">
            <t t-call="web.basic_layout">
                <div class="page article" t-att-data-oe-model="o and o._name" t-att-data-oe-id="o and o.id">
                    <t t-raw="0"/>
                    <span>
                        this is a test
                    </span>
                </div>
            </t>
        </t>
    </template>
</odoo>

修改后重新升级模块,再次打印报表即可自动将PDF保存为对应stock.picking记录的附件。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.16 22:10:29