如何在Odoo中移除报表页眉页脚及使用纸张格式?
在Odoo中移除报表页眉页脚及使用纸张格式的方法
一、移除报表页眉页脚
如果切换basic和external布局无效,可尝试以下几种方式:
1. 自定义空白布局模板
直接创建一个不含页眉页脚的极简布局,在报表中调用该布局:
<!-- 定义空白布局 --> <template id="report_empty_layout"> <t t-call="web.html_container"> <t t-foreach="docs" t-as="doc"> <div class="page"> <!-- 嵌入你的报表内容模板 --> <t t-call="your_module.your_report_content_template"/> </div> </t> </t> </template> <!-- 报表主模板调用空白布局 --> <template id="your_main_report_template"> <t t-call="your_module.report_empty_layout"/> </template>
2. 覆盖默认布局的页眉页脚
继承web.report_layout_basic布局,清空页眉页脚部分:
<template id="custom_basic_layout" inherit_id="web.report_layout_basic"> <!-- 替换为空的页眉 --> <xpath expr="//div[@class='header']" position="replace"> <div class="header"></div> </xpath> <!-- 替换为空的页脚 --> <xpath expr="//div[@class='footer']" position="replace"> <div class="footer"></div> </xpath> </template>
之后在报表定义中指定使用这个自定义布局。
3. 检查报表模板硬编码内容
部分报表可能在自身模板中直接写了页眉页脚代码,而非依赖布局。此时需直接打开报表模板,找到<header>、<footer>标签或对应代码块,直接删除即可。
二、使用纸张格式
1. 后台配置纸张格式
进入Odoo后台,依次点击设置 > 技术 > 报表 > 纸张格式:
- 可新建格式:设置纸张大小(如A4、Letter)、方向(纵向/横向)、边距、页眉页脚高度、DPI等参数。
- 或修改现有格式:调整已有格式的参数以满足需求。
2. 关联报表与纸张格式
方式一:后台直接设置
打开目标报表的配置页面(设置 > 技术 > 报表 > 报表),在纸张格式字段选择已配置好的格式。
方式二:XML代码关联
在报表的XML定义中指定纸张格式:
<!-- 新建报表时指定 --> <report id="your_report_action" string="自定义报表" model="your.model.name" report_type="qweb-pdf" name="your_module.your_report_template" paperformat_id="your_module.custom_paperformat"/> <!-- 修改现有报表的纸张格式 --> <record id="existing_report_action_id" model="ir.actions.report"> <field name="paperformat_id" ref="your_module.custom_paperformat"/> </record>
3. XML自定义纸张格式
如需更精细的控制,可直接用XML定义纸张格式:
<record id="custom_paperformat" model="report.paperformat"> <field name="name">横向A4(自定义边距)</field> <field name="default" eval="False"/> <field name="format">A4</field> <field name="orientation">Landscape</field> <field name="margin_top">8</field> <field name="margin_bottom">8</field> <field name="margin_left">12</field> <field name="margin_right">12</field> <field name="header_line" eval="False"/> <field name="header_spacing">0</field> <field name="dpi">96</field> </record>
内容的提问来源于stack exchange,提问作者djouher
相关产品推荐
相关产品推荐

