user7897726
user7897726

Reputation:

Account invoice report

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

i added field to invoice report inside tax table. but how can i make tax table visible only if there is note field, and hide if note is empty.

i trying something with t-if but my goal is to show tax table not to hide it when note field is not empy. is there any kind of t-ifnot?

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

            </xpath>

Upvotes: 4

Views: 855

Answers (2)

Mayur Vora
Mayur Vora

Reputation: 942

Hello An..,

Best Learning Tutorial

If you want use any types of condition so QWeb is provides many types of inbuilt functionality. More information for read below link,
1) https://www.odoo.com/documentation/8.0/reference/qweb.html

Solution

Account invoice base/odoo table is below,

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

Now you want to show the table when t.note field is not empty so odoo XML provides if condition to check the anything.

Now try this below code for your problem,

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

I hope my answer is helpful.
If any query so comment please.

Upvotes: 0

Bhavesh Odedra
Bhavesh Odedra

Reputation: 11143

Yes. We can achieve it with following example:

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

EDIT

Design your table in one of condition.

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

Upvotes: 2

Related Questions