Odoo Help


How to hide "discount" columns on saleorders/invoices if there are none?

Malte Jörgens
on 4/2/15, 7:54 AM 1,618 views

I found this old thread discussing the same question:


However, the solution suggested is outdated and doesn't apply to the new QWeb-based reporting engine. I just wondered, if there is a better/easier solution by now to automatically determine, whether the "discount" column should be displayed or not. Also, it would be nice to hide the discount in an invoice line, if there is none given or it is negative.

On 4/2/15, 8:23 AM

Modifications in Qweb report:

<t t-set="is_discount" t-value="0"/>
<t t-foreach="o.invoice_line" t-as="l">
<t t-if="l.discount"><t t-set="is_discount" t-value="1"/></t>
<t t-if="is_discount">
<th class="text-right" groups="sale.group_discount_per_so_line">Discount (%)</th>
<t t-if="is_discount">
<td class="text-right" groups="sale.group_discount_per_so_line"><span t-field="l.discount"/></td>

Malte Jörgens
On 4/7/15, 11:46 AM

Sorry for the wait, I didn't have time until now to test the propsed solution.

With the answer of zbik pointing me in the direction, but the proposed solution not working, i had to modify it in two places to get it working:

<t t-set="is_discount" t-value="False"/>
<!-- This is important, otherwise is_discount will only be visible inside the foreach-loop and be undefined thereafter -->

<t t-foreach="o.order_line" t-as="l">
<t t-if="l.discount"><t t-set="is_discount" t-value="True"/></t>

<!-- Table headers -->
<t t-if="is_discount">
<th class="text-right">Discount</th>

<!-- Actual table row -->
<t t-if="is_discount"> <!-- Instead of l.discount, otherwise there is a cell missing and following columns will be shifted -->
<td class="text-right" groups="sale.group_discount_per_so_line"><t t-if="l.discount"><span t-field="l.discount"/>&#160;%</t></td>

Which works very well altogether now.

PS: Sorry for posting this as answer, my karma doesn't allow me to comment yet :(

Yes you are right,

on 4/8/15, 6:34 AM

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 4/2/15, 7:54 AM
Seen: 1618 times
Last updated: 4/8/15, 6:37 AM