Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
7727 Zobrazení

In an invoice we have the following item lines:

<tbody class="invoice_tbody">
    <tr t-foreach="o.invoice_line" t-as="l">
        <td><span t-field="l.name"/></td>
        <td>
            <span t-field="l.quantity"/>
            <span t-field="l.uos_id" groups="product.group_uom"/>
        </td>
        <td class="text-right">
            <span t-field="l.price_unit"/>
        </td>
        <td class="text-right" groups="sale.group_discount_per_so_line"><span t-field="l.discount"/></td>
        <td class="text-right">
            <span t-esc="', '.join(map(lambda x: x.description, l.invoice_line_tax_id))"/>
        </td>
        <td class="text-right">
            <span t-field="l.price_subtotal" t-field-options="{&quot;widget&quot;: &quot;monetary&quot;, &quot;display_currency&quot;: &quot;o.currency_id&quot;}"/>
        </td>
    </tr>
</tbody>

The maths for working out the total discount applied are simple: qty*unitaryPrice*discount for all items in the invoice.

Is it possible to do that simple math in QWeb or do I need a backend python parser? In order words, is there something like a variable I can set up to zero and iterate adding each item discount?

Thanks

Avatar
Zrušit
Nejlepší odpověď

Hello E.M.

In a Qweb report, you can define a variable and use it for computation same as we can do it in python code.

<tbody class="invoice_tbody">
<t t-set="total_discount" t-value="0"/>
<tr t-foreach="o.invoice_line" t-as="l">
<t t-set="total_discount" t-value="total_discount + (l.price_unit * l.quantity * l.discount)"/>
<td><span t-field="l.name"/></td>
<td>
<span t-field="l.quantity"/>
<span t-field="l.uos_id" groups="product.group_uom"/>
</td>
<td class="text-right">
<span t-field="l.price_unit"/>
</td>
<td class="text-right" groups="sale.group_discount_per_so_line"><span t-field="l.discount"/></td>
<td class="text-right">
<span t-esc="', '.join(map(lambda x: x.description, l.invoice_line_tax_id))"/>
</td>
<td class="text-right">
<span t-field="l.price_subtotal" t-field-options="{&quot;widget&quot;: &quot;monetary&quot;, &quot;display_currency&quot;: &quot;o.currency_id&quot;}"/>
</td>
</tr>
Total Discount: <span t-esc="total_discount"/>
</tbody>

As you can see in the code (highlighted code), using t-set you can define a variable and can assign or add the value based on calculation.

Documentation: Set a variable in Qweb reports




Avatar
Zrušit
Autor

I did a quick try and it works. Thanks.

Good Answer Serpetnt......

Good one :) +1 upvote

Related Posts Odpovědi Zobrazení Aktivita
0
dub 24
1588
1
srp 23
5076
3
srp 23
21926
2
pro 22
8576
0
led 22
464