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

Odoo16采购订单PDF报表多页时行项目表格竖边框重叠表头

Odoo 16采购订单PDF报表分页边框重叠问题解决方法

方案1:分离表头与表体的边框渲染

将表头(thead)和表体(tbody)拆分为独立表格,通过边框隐藏避免叠加冲突:

/* 表头表格样式 */
.header-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    border: 1px solid #000;
    border-bottom: none; /* 移除表头底部边框,避免和表体顶部边框重叠 */
}

/* 表体表格样式 */
.body-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    border: 1px solid #000;
    border-top: none; /* 移除表体顶部边框,避免和表头底部边框冲突 */
}

在QWeb模板中,表头和表体用独立表格包裹,中间添加一个不可见的隔离层:

<div style="height: 0; overflow: hidden; border-top: 1px solid #fff;"></div>

方案2:用伪元素遮挡溢出的竖边框

针对wkhtmltopdf重复表头时的边框溢出问题,给thead添加覆盖层隐藏多余竖线:

thead {
    position: relative;
}

thead::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 1px;
    background-color: #fff; /* 用报表背景色覆盖溢出的竖边框 */
}

方案3:强制精确的边框渲染规则

在全局CSS中添加wkhtmltopdf专属参数,强制边框计算精度:

@page {
    size: A4;
    margin: 1cm;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

table {
    border-collapse: collapse !important;
}

table th, table td {
    border: 1px solid #000 !important;
    padding: 8px;
    position: relative;
}

/* 分页后表体首行顶部边框加粗,覆盖可能的重叠 */
tbody tr:first-child td {
    border-top: 2px solid #000 !important;
}

方案4:手动拆分长表格避免自动分页

通过Odoo循环逻辑将行项目拆分为固定行数的分段表格,每个分段单独渲染表头:

<t t-set="page_capacity" t-value="20"/> <!-- 根据报表布局调整每页可容纳行数 -->
<t t-foreach="purchase_order.order_line" t-as="line" t-group="line_index // page_capacity">
    <table class="report-table">
        <thead>
            <tr>
                <th>产品名称</th>
                <th>数量</th>
                <th>单价</th>
                <th>金额</th>
            </tr>
        </thead>
        <tbody>
            <t t-foreach="group_value" t-as="item">
                <tr>
                    <td><t t-esc="item.product_id.name"/></td>
                    <td><t t-esc="item.product_qty"/></td>
                    <td><t t-esc="item.price_unit"/></td>
                    <td><t t-esc="item.price_subtotal"/></td>
                </tr>
            </t>
        </tbody>
    </table>
    <div style="page-break-after: always;" t-if="not last_group"/>
</t>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.11 13:33:14