2

odoo 9.0 でレポートを作成する方法について Google で 5 時間以上検索しましたが、まだ何もありません。Qweb を使用して、ツリー ビューのようなレポートを PDF で作成したいと考えています。見つけたのはすべて請求書でしたが、わかりません私の例でレポートを作成する方法。

たとえば、モデル(example.py、 init .py)およびビュー(example_view.xml)フォルダーとinit .py、openerp .pyを含むodooアドオンの「example」フォルダーにフォルダーがあると仮定しましょう。最も単純なモジュールと私の質問を知っています: ツリー ビュー (このビューはビュー フォルダーにあります) のように見える単純なレポートを作成するには、何をどこに追加する必要があるか、XML に何を書き込む必要があるかを教えてください。

私は例を学ぶ人で、何かを理解するには例が必要です。

ご回答ありがとうございます :)

4

1 に答える 1

8

簡単なレポートを作成するには、次の手順を実行します。

  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 レポート定義を次に示します。名前 (char) とサブレコード (one2many) を持つ架空のモデル example.model_name があり、サブレコード モデルには 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>
于 2016-08-31T16:01:23.397 に答える