我花了5个多小时在google上搜索关于在odoo 9.0中创建报告但仍然没有,我想制作看起来像树视图的报告,pdf,使用Qweb,我找到的所有内容都是发票,但我不知道#39;我不知道如何在我的例子中做出报告。
让我们假设我在odoo插件中有文件夹'例如'使用model(example.py, init .py)和view(example_view.xml)文件夹和 init .py, openerp .py,你知道最简单的模块,我的问题是:告诉我必须要添加什么,在哪里,我必须写入XML以制作一个看起来像树视图的简单报告(此视图在视图文件夹中),仅此而已。
我是一个学习榜样的人,我需要一些例子才能理解。
感谢您的回答:)
答案 0 :(得分:8)
要创建简单报告,请执行以下操作。
定义报告xml文件
/addons/example/views/example_report.xml
通过在
中引用xml文件,将xml文件加载到插件中/ addons / example / __ openerp__.py
在数据部分中包含其他xml文件。
'data': ['views/example_report.xml'],
如果在您的列表视图中,您应该能够选择一条记录(选中该复选框),然后在更多下拉菜单中运行该报告。或者在模型的表单视图中,您还应该能够单击更多并从那里运行报表。
注意:必须正确安装wkhtmltopdf才能使其中任何一个工作。 wkhtmltopdf.org上有说明(确保至少版本为0.12.1)
这是一个简单的xml报告定义。让我们假设您有一个虚构的模型example.model_name,其名称(char)和子记录(one2many),子记录模型有id,name和date字段。
<openerp>
<data>
<report
id="report_example_model_name"
model="example.model_name"
string="Example Report"
name="example.report_example_report_view"
file="example.report_model_name"
report_type="qweb-pdf"/>
<template id="report_example_report_view">
<t t-call="report.html_container">
<!-- REMEMBER, docs is the selected records either in form view or checked in list view (usually). So the line below says use the following template for each record that has been selected. -->
<t t-foreach="docs" t-as="doc">
<t>
<div class="page">
<h1>Report For <t t-esc="doc.name"/></h1>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Date</th>
</tr>
<t t-foreach="doc.subrecord" t-as="o">
<tr>
<td><t t-esc="o.id"/></td>
<td><t t-esc="o.name"/></td>
<td><t t-esc="o.date"/></td>
</tr>
</t>
</table>
</div>
</t>
</t>
</t>
</template>
</data>
</openerp>