Appearance
怎么定制财务报表?
概述
参考比利时(l10n_be_reports)和西班牙(l10n_es_reports)做法
重点
每张报表拆为 2 份,用 availability_condition=coa + chart_template 区分:
资产负债表 → 2个文件:
data/balance_sheet_cn.xml— chart_template=cn,root_report=balance_sheetdata/balance_sheet_cn_large_bis.xml— chart_template=cn_large_bis,root_report=balance_sheet
利润表 → 2个文件:
data/profit_loss_cn.xml— chart_template=cndata/profit_loss_cn_large_bis.xml— chart_template=cn_large_bis
现金流量表 → 2个文件:
data/cash_flow_cn.xml— chart_template=cndata/cash_flow_cn_large_bis.xml— chart_template=cn_large_bis
报表定义模板
每个报表 record 需包含:
xml
<record id="balance_sheet_cn" model="account.report">
<field name="name">资产负债表</field>
<field name="root_report_id" ref="account_reports.balance_sheet"/>
<field name="availability_condition">coa</field>
<field name="chart_template">cn</field>
<field name="country_id" ref="base.cn"/>
...
</record>使用 root_report_id 后,Odoo 框架会自动根据公司的 chart_template 选择正确的子报表
Step 1: 创建现金流标签
新建 data/account_cashflow_tags.xml
定义 account.account.tag 记录(applicability='accounts'),约 21 个标签:
经营活动(7): 销售收入、税费返还、其他收入、采购支出、职工薪酬、税费支出、其他支出 投资活动(7): 收回投资、投资收益、处置资产、其他收入、购建资产、对外投资、其他支出 筹资活动(6): 吸收投资、借款收入、其他收入、偿还债务、利息股利、其他支出 汇率(1): 汇率变动
Step 2: 科目表 CSV 关联标签
在三个 CSV 文件中为科目添加 tag_ids 列。注意 cn 和 cn_large_bis 的科目代码不同但标签可以共用。
Step 3: 重写 Python handler
现金流量表差异:
- handler 中
_get_layout_data()区分(cn 简化版 vs cn_large_bis 完整版) - 拆分后每个 XML 指定各自的 custom_handler,或在 handler 中保持 if/else
修改 models/account_cash_flow_report.py:
_get_tags_ids()— tag → layout_line 映射_get_cashflow_tag_ids()— 返回所有 tag ID_dispatch_aml_data()— 基于 tag 分派(参考 l10n_mn_reports)_get_layout_data()— 保持现有两套布局,添加 unclassified_activities 行
