在模块中新建名为report的python文件
创建__main.xml 文件
<report
id = “account_invoices”
model = “account.invoice”
string = “Invoices”
report_type = “qweb-pdf”
name = “account.report_invoice”
file = “account.report_invoice”
attachment_use = “True”
attachment = “(object .state in('open','paid'))和 ('INV'+(object.number或'').replace('/','')+'。pdf')“
print_report_name="'跟随组- %s' %(object.name)"
/>
- Name (强制): 仅在某种列表中查找报表时存在,它仅用作报表的助记符/描述,
- Model(强制):您的报表将涉及的模型
- Report_type(强制):无论是qweb-pdf 对于PDF报告或qweb-html为html
- Prison_report_name :报告的名称(将是PDF输出的名称)
- Groups many2many.允许查看、使用当前报告的组的字段
- Attachment_use:如果设置为true,则报告将使用attachment表达式生成的名称储存为记录的附件;如果您只需要生成一次报告(例如出狱法律原因),您可以使用此方法
- Attachment:Python表达式,用于定义报告的名称; 该记录作为变量是可访问的object
- paperformat:您要使用的纸质格式的外部ID(如果未指定,则默认为公司的纸质格式)
例如:
<report
id="action_report_following_group"
string="打印"
model="prison.following.group"
report_type="qweb-pdf"
file="prison_system.prison_group_report"
name="prison_system.prison_group_report"
print_report_name="'跟随组- %s' %(object.name)"
/>
最小的可行性模板
在上述已经完成的情况下
<template id = “report_invoice” > // 与上面的name,file 一致
<t t-call = “web.html_container” >
<t t-foreach = “docs” t-as = “o” >
<t t-call = “web.**external_layout**” >
< div class = “page” >
<h2>报告标题</ h2>
<p>此对象的名称是<span t-field = “o.name” /> </ p>
</ div>
</ t>
</ t>
</ t> </ template>
调用external_layout将在报表上添加默认页眉和页脚。
PDF正文将是其中的内容<div class="page">
。
模板id必须是报告声明中指定的名称; 例如account.report_invoice,对于上述报告。由于这是一个QWeb模板,您可以访问docs模板接收的对象的所有字段 。
报告中可以访问一些特定变量,主要是:
- docs : 当前报告的记录
- doc_ids : docs记录的ID列表
- doc_model : docs记录模型
- time : time来自Python标准库的引用
- user : res.user 用户打印报告的记录
- res_company :记录当前user的公司
放置照片
<span t-field="media.image" t-field-options='{"widget": "image"}' />//media.image 放置的是调用字段名称
一张报表打印多行
<tbody t-foreach = “docs” t-as = “o”>
放字段
</tbody>