xmlodooinvisible

ODOO Use invisible attrs on field | Condition: If the number is 0.0


In Odoo when you have an xpath you can add "attrs" to a field invisible, when a condition is met. This works fine.

I have a field DISCOUNT that i want to display on INVOICE/QUOTATION report only if one of the products hold a DISCOUNT value more than 0.0 (i.e - that product has a discount given to it

CODE:

<td style="border: 0.5px solid black;background-color:#E6E6E6;">
    <span t-field="l.total_discount" /> 
</td>

I want to add:

attrs="{'invisible': [('total_discount','=',0.0)]}"

But i dont know if this is the correct code above.

Normally, this code should hide all tables of discount if they all equal zero (there's no use of placing a discount block if discount is zero)

REPORT-XML enter image description here

INVOICE_VIEW enter image description here

Please let me know if am somewhat unclear, in any aspect.

#

Thanks alot.!


Solution

  • To hide the whole discount column if there is no discount on the invoice at all would be to have a functional field define that evaluates a boolean, which will tell you if there is even one line in the invoice that has a discount. If there is one line then the boolean would be TRUE. If there is none with a discount then the boolean would be FALSE. Here is the sample code on how to do it.

    Define a new field on the model:

    display_discount_col = fields.Boolean(compute="_display_discount_col")
    
    @api.one
    def _display_discount_col(self)
       if line.discount > 0:
           self.display_discount_col = True
           break
    

    QWEB code:

    <t t-if="o.display_discount_col">
        <th>Discount</th>
    </t>
    
    <t t-if="o.display_discount_col">
        <td style="border: 0.5px solid black;background-color:#E6E6E6;">
            <span t-field="l.total_discount" /> 
        </td>
    </t>
    

    I'm not sure if the discount field or the invoice_line are called what I have mentioned above, you might have to look them up and substitute the correct field names in the above code.