Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
7869 Переглядів

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

Аватар
Відмінити
Найкраща відповідь

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




Аватар
Відмінити
Автор

I did a quick try and it works. Thanks.

Good Answer Serpetnt......

Good one :) +1 upvote

Related Posts Відповіді Переглядів Дія
0
квіт. 24
1853
1
серп. 23
5615
3
серп. 23
22174
2
груд. 22
8809
0
січ. 22
464