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

如何在Odoo中移除Sale Order Report页眉页脚,生成空白头尾自定义报表

Hey there! I’ve tackled this exact requirement before, so here’s a practical, step-by-step solution to build a custom report that mirrors the sale.order report’s structure but has completely empty headers and footers:

1. Create a Custom QWeb Report Template (Inherit from Sale Order Report)

The easiest way to match the sale.order report’s look while stripping headers/footers is to inherit the existing sale order report template and override its header/footer sections. Add this XML to your custom module’s report file:

<odoo>
    <template id="custom_sale_order_no_header_footer" inherit_id="sale.report_saleorder">
        <!-- Replace existing header with empty content -->
        <xpath expr="//div[@class='header']" position="replace">
            <div class="header"></div>
        </xpath>
        <!-- Replace existing footer with empty content -->
        <xpath expr="//div[@class='footer']" position="replace">
            <div class="footer"></div>
        </xpath>
    </template>
</odoo>

This keeps all the core sale order report logic intact while removing any header/footer content.

2. Define the Report Action

Next, link your custom template to the sale.order model by adding a report action in your module’s XML:

<odoo>
    <report
        id="report_custom_sale_order"
        model="sale.order"
        string="Custom Sale Order (No Header/Footer)"
        report_type="qweb-pdf"
        name="your_module_name.custom_sale_order_no_header_footer"
        file="your_module_name.custom_sale_order_no_header_footer"
        attachment_use="False"
    />
</odoo>

Replace your_module_name with the actual name of your custom module. This adds a new print option to the sale order form view.

3. Fix PDF Margins (Critical for Clean Output)

Even with empty headers/footers, wkhtmltopdf (Odoo’s default PDF renderer) might leave default margins or placeholder content. Add this style template to eliminate those:

<odoo>
    <template id="custom_sale_order_report_styles" inherit_id="web.report_assets_common">
        <xpath expr="." position="inside">
            <style>
                @page {
                    /* Remove default header/footer content */
                    @top-left { content: none; }
                    @top-right { content: none; }
                    @bottom-left { content: none; }
                    @bottom-right { content: none; }
                    /* Adjust page margins to remove empty header/footer space */
                    margin-top: 0.5cm;
                    margin-bottom: 0.5cm;
                }
                .page {
                    padding: 0;
                }
            </style>
        </xpath>
    </template>
</odoo>

This ensures no leftover header/footer elements appear in the final PDF.

4. Activate Your Custom Report

  1. Install or update your custom module in Odoo.
  2. Navigate to any sale order, click the Print button, and select your new report option ("Custom Sale Order (No Header/Footer)").
  3. The generated PDF will match the standard sale order report’s layout but have completely empty headers and footers.

Alternative: Build a Full Custom Template (If Inheritance Isn’t Ideal)

If you need full control over the report structure, you can copy the entire sale.report_saleorder template code into your custom module, then manually delete all header and footer sections. Just make sure to update the report action to point to your full template instead of the inherited one.

内容的提问来源于stack exchange,提问作者Djamel-eddine Bouzegzeg

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.09 16:42:46