【问题标题】:How to create odoo 9.0 QWeb reports step by step如何逐步创建 odoo 9.0 QWeb 报告
【发布时间】:2016-08-31 13:45:36
【问题描述】:

我花了 5 个多小时在 google 上搜索有关在 odoo 9.0 中创建报告的信息,但仍然一无所获,我想使用 Qweb 制作看起来像树形视图的报告,pdf 格式,我发现的所有东西都是发票,但我没有在我的例子中不知道如何制作报告。

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

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

感谢您的回答:)

【问题讨论】:

    标签: templates report openerp odoo-9 odoo-view


    【解决方案1】:

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

    1. 定义报告 xml 文件

      /addons/example/views/example_report.xml

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

      /addons/example/__openerp__.py

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

    'data': ['views/example_report.xml'],
    
    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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多