如何创建odoo 9.0 QWeb报告一步一步

4C5*_*04C 2 templates report openerp odoo-9 odoo-view

我花了5个多小时在谷歌搜索关于在odoo 9.0中创建报告但仍然没有,我想制作看起来像树视图的报告,用pdf,使用Qweb,我发现的所有东西都是发票,但我不知道如何在我的例子中做报告.

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

我是榜样学习者,我需要一些例子来理解某些东西.

谢谢你的回答:)

Phi*_*ack 8

要创建简单报告,请执行以下操作.

  1. 定义报告xml文件

    /addons/example/views/example_report.xml

  2. 通过引用它来加载插件中的xml文件

    /addons/example/__openerp__.py

在数据部分与其他xml文件.

'data': ['views/example_report.xml'],
Run Code Online (Sandbox Code Playgroud)
  1. 更新你的插件.

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

注意:必须正确安装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>
Run Code Online (Sandbox Code Playgroud)