【问题标题】:Account invoice report帐户发票报告
【发布时间】:2017-07-11 14:10:17
【问题描述】:
<openerp>
<data>

    <template id="report_invoice_document" inherit_id="account.report_invoice_document">

        <xpath expr="//span[@t-field='t.amount']" position="after">
            <span t-field="t.note"/>
        </xpath>
        </template>
    </data>
</openerp>

我在税表内的发票报告中添加了字段。但是我怎样才能使税表只有在有注释字段时才可见,如果注释为空则隐藏。

我尝试使用 t-if 进行某些操作,但我的目标是在注释字段不为空时显示税表而不是隐藏它。有没有任何类型的 t-ifnot?

<xpath expr="//span[@t-field='t.amount']/../../../../thead/tr" position="replace">
                <th t-if="o.notes"

            </xpath>

【问题讨论】:

    标签: openerp odoo-8 odoo-9


    【解决方案1】:

    是的。我们可以通过下面的例子来实现:

    <t t-if="o.notes">
        <!-- Fields visible if Notes has value-->
    </t>
    
    <t t-if="not o.notes">
        <!-- Fields visible if Notes has no value-->
    </t>
    

    编辑

    在其中一种条件下设计您的桌子。

    <t t-if="o.notes">
        <table style="border:1px solid; width:100%">
            <thead>
                <tr>
                    <th></th>
                    <th></th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
            </tbody>
        </table>
    </t>
    

    【讨论】:

    • 但如果我想显示所有税表,而不是特定字段,我该怎么做?
    【解决方案2】:

    你好,安..,

    最佳学习教程

    如果您想使用任何类型的条件,那么QWeb 提供了多种类型的内置功能。更多信息请阅读以下链接,
    1)https://www.odoo.com/documentation/8.0/reference/qweb.html

    解决方案

    账户发票基数/odoo 表如下,

    <div class="row" t-if="len(o.tax_line_ids) > 0">
        <div class="col-xs-6">
            <table class="table table-condensed">
            <thead>
                <tr>
                    <th>Tax</th>
                    <th class="text-right">Base</th>
                    <th class="text-right">Amount</th>
                </tr>
            </thead>
            <tbody>
                <tr t-foreach="o.tax_line_ids" t-as="t">
                    <td><span t-field="t.tax_id.description"/></td>
                    <td class="text-right">
                        <span t-field="t.base" t-options='{"widget": "monetary", "display_currency": o.currency_id}'/>
                    </td>
                    <td class="text-right">
                        <span t-field="t.amount" t-options='{"widget": "monetary", "display_currency": o.currency_id}'/>
                    </td>
                </tr>
            </tbody>
            </table>
        </div>
    </div>
    

    现在您想在t.note 字段不为空时显示表格,因此 odoo XML 提供了 if 条件来检查任何内容。

    现在试试下面的代码来解决你的问题,

    <openerp>
        <data>
            <template id="report_invoice_document" inherit_id="account.report_invoice_document">
            <xpath expr="//span[@t-field='t.amount']" position="after">
                <t t-if="t.note">           
                    <span t-field="t.note"/>
                    <!-- For example i add one new table -->
                    <table class="table table-condensed">
                        <thead>
                            <tr>
                            <th>Tax</th>
                            <th class="text-right">Base</th>
                            <th class="text-right">Amount</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr t-foreach="o.tax_line_ids" t-as="t">
                            <td><span t-field="t.name"/></td>
                            <td class="text-right">
                                <span t-field="t.base"
                                t-field-options='{"widget": "monetary", "display_currency": "o.currency_id"}'/>
                            </td>
                            <td class="text-right">
                                <span t-field="t.amount"
                                t-field-options='{"widget": "monetary", "display_currency": "o.currency_id"}'/>
                            </td>
                            </tr>
                        </tbody>
                    </table>
    
                </t>
                <t t-if="not t.note">           
                    <!-- If empty t.note so not show tax table -->
                </t>
            </xpath>
            </template>
        </data>
    </openerp>
    

    希望我的回答对你有所帮助。
    如有任何疑问,请发表评论。

    【讨论】:

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