如何逐步创建 odoo 9.0 QWeb 报告

How to create odoo 9.0 QWeb reports step by step

我花了 5 个多小时在 google 中搜索关于在 odoo 9.0 中创建报告但仍然一无所获,我想制作看起来像树视图的报告,在 pdf 中,使用 Qweb,我发现的一切是发票,但我不知道如何在我的示例中进行报告。

例如,假设我在 odoo 插件 'example' 中有文件夹,其中包含模型(example.py、init.py)和视图(example_view.xml) 文件夹和 init.py,openerp.py,你知道最简单的模块,我的问题是:告诉我我必须添加什么以及在哪里,我必须写什么到 XML 来制作一个看起来像树视图的简单报告(这个视图在视图文件夹中),仅此而已。

我是一个学习例子的人,我需要例子来理解一些东西。

感谢您的回答:)

要创建一个简单的报告,请执行以下操作。

  1. 定义报表xml文件

    /addons/example/views/example_report.xml

  2. 通过在

    中引用它,将 xml 文件加载到您的插件中

    /addons/example/__openerp__.py

在与其他 xml 文件的数据部分。

'data': ['views/example_report.xml'],
  1. 更新您的插件。

如果在您的插件的列表视图中,您应该能够 select 一条记录(选中复选框),然后在更多下拉列表中 运行 报告。或者在模型的表单视图中,您还应该能够单击更多并从那里单击 运行 报告。

注意:必须正确安装 wkhtmltopdf 才能使其正常工作。 wkhtmltopdf.org有说明(确保版本至少为0.12.1)

这是一个简单的 xml 报告定义。假设您有一个虚构的模型 example.model_name,它有一个名称 (char) 和子记录 (one2many),并且子记录模型有一个 id、名称和日期字段。

<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>