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

如何在Odoo中实现多产品同页打印,满页自动分页

解决Odoo报表单产品分页问题

问题根源在于你的模板将每个产品作为独立页面渲染:外层循环docs包裹了整个external_layout和page容器,导致每个产品生成一个全新页面。

修正后的模板代码

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <template id="stock_view_report_template">
            <t t-call="report.html_container">
                <t t-call="report.external_layout">
                    <div class="page">
                        <h2>Stock actuel</h2>
                        <table class="table table-condensed">
                            <thead>
                                <tr>
                                    <th>product</th>
                                    <th>Quantity</th>
                                    <th>Location</th>
                                    <th>Owner</th>
                                    <th>Lot</th>
                                    <th>Incoming Date</th>
                                    <th>Inventory Value</th>
                                </tr>
                            </thead>
                            <tbody>
                                <!-- 将循环移至tbody内部,为每个产品生成一行 -->
                                <t t-foreach="docs" t-as="o">
                                    <tr>
                                        <td><span t-field="o.product_id.name"/></td>
                                        <td><span t-field="o.qty"/></td>
                                        <td><span t-field="o.location_id.name"/></td>
                                        <td><span t-field="o.owner_id"/></td>
                                        <td><span t-field="o.lot_id"/></td>
                                        <td><span t-field="o.in_date"/></td>
                                        <td><span t-field="o.inventory_value"/></td>
                                    </tr>
                                </t>
                            </tbody>
                        </table>
                    </div>
                </t>
            </t>
        </template>
    </data>
</openerp>

关键修改点

  • 移除了包裹external_layout的外层docs循环,改为在表格的<tbody>内部循环产品数据
  • 为每个产品生成单独的<tr>行(修复原模板中缺失<tr>的HTML结构错误)
  • 整个报表只保留一个页面容器,表格会自动填充页面,内容超出时自动分页

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 05:16:23