Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

How can I calculate all discounts applied in an invoice and print the value as a separate field?

By
E.M.
on 10/18/15, 11:51 AM 692 views

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

3

Serpent Consulting Services Pvt. Ltd.

--Serpent Consulting Services Pvt. Ltd.--
4341
| 6 6 8
Gandhinagar, India
--Serpent Consulting Services Pvt. Ltd.--

Serpent Consulting Services Pvt. Ltd. Your Odoo/OpenERP Solution, just an email away!

Serpent Consulting Services Pvt. Ltd.
On 10/19/15, 1:59 AM

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.

E.M.
on 10/19/15, 2:43 PM

Good Answer Serpetnt......

Odoo
on 10/20/15, 12:57 AM

Good one :) +1 upvote

Akhil P Sivan
on 10/20/15, 1:51 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 10/18/15, 11:51 AM
Seen: 692 times
Last updated: 10/20/15, 12:48 AM