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

如何在Odoo 17社区版(SaaS)中创建带自定义页眉的发票模板

Odoo 17 社区版(SaaS)自定义发票模板(带页眉)完成指南

基于你已完成的基础操作,接下来按以下步骤收尾:

1. 完善自定义页眉的QWEB实现

因为你仅修改了report_invoice_document_copySample的第一行,需要针对性重写页眉区块:

  • 如果你是继承原官方发票模板(推荐,避免重复编写主体内容),用xpath定位原页眉并替换:
    <template id="report_invoice_document_copySample" inherit_id="account.report_invoice_document">
        <!-- 替换原页眉 -->
        <xpath expr="//header" position="replace">
            <header>
                <div class="custom-header">
                    <!-- 插入公司Logo(可选) -->
                    <img t-if="docs[0].company_id.logo" t-att-src="image_data_uri(docs[0].company_id.logo)" 
                         style="max-height: 70px; margin-right: 20px;"/>
                    <!-- 公司信息 -->
                    <div class="company-details">
                        <h3 t-field="docs[0].company_id.name"/>
                        <p t-field="docs[0].company_id.street"/>
                        <p><span t-field="docs[0].company_id.city"/> - <span t-field="docs[0].company_id.zip"/></p>
                        <p>税号:<span t-field="docs[0].company_id.vat"/></p>
                    </div>
                </div>
            </header>
        </xpath>
        <!-- 如需修改其他区块,可继续添加xpath -->
    </template>
    
  • 如果你是独立模板(完全自定义),需包含外部布局并嵌入发票主体:
    <template id="report_invoice_copySample">
        <t t-call="web.external_layout">
            <t t-set="doc" t-value="docs[0]"/>
            <!-- 替换页眉 -->
            <xpath expr="//header" position="replace">
                <!-- 自定义页眉内容同上 -->
            </xpath>
            <!-- 调用官方发票主体内容,避免重复编写 -->
            <t t-call="account.report_invoice_document"/>
        </t>
    </template>
    

2. 绑定QWEB模板到Report记录

进入设置 > 技术 > 报表 > 报表,找到你创建的发票报表:

  • 确认QWeb视图字段已选择你的report_invoice_document_copySample模板;
  • 检查基础配置:模型为account.move,报表类型为QWeb PDF,纸张格式选A4(或你需要的格式);
  • 若要让该模板在发票打印菜单中显示,确保菜单字段关联到发票模块的打印菜单,且组字段添加了有权限打印发票的用户组(如Accounting & Finance / Billing)。

3. 调整页眉样式(可选)

如果需要美化页眉布局,继承原报表的样式模板并添加自定义CSS:

<template id="report_invoice_custom_style" inherit_id="account.report_invoice_document_style">
    <xpath expr="//style" position="append">
        <style>
            .custom-header {
                display: flex;
                align-items: center;
                justify-content: space-between;
                padding-bottom: 15px;
                border-bottom: 2px solid #333;
                margin-bottom: 20px;
            }
            .company-details {
                text-align: right;
                font-size: 12px;
                line-height: 1.5;
            }
            .company-details h3 {
                margin: 0 0 5px 0;
                font-size: 16px;
                color: #2c3e50;
            }
        </style>
    </xpath>
</template>

4. 同步带付款记录的模板

对于report_invoice_with_payments_copySample,同样用继承方式替换页眉:

<template id="report_invoice_with_payments_copySample" inherit_id="account.report_invoice_with_payments">
    <xpath expr="//header" position="replace">
        <!-- 直接复用之前定义的自定义页眉,或复制相同内容 -->
        <header t-call="your_module.report_invoice_document_copySample header"/>
    </xpath>
</template>

5. 测试验证

打开任意一张已确认的发票,点击打印按钮,选择你创建的新模板,生成PDF后检查:

  • 页眉是否正确显示自定义内容;
  • 发票主体内容完整无缺失;
  • 带付款记录的模板是否同步生效。

如果页眉未显示,排查以下点:

  • 模板中docs[0]是否正确获取到发票数据;
  • 公司Logo是否上传(如果用了图片);
  • 报表的权限组是否包含当前登录用户;
  • 清除浏览器缓存并重新生成报表(SaaS环境可能需要等待缓存刷新)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 08:25:10