Skip to Content
Menu
This question has been flagged
1 Reply
1354 Views

How to sum value if value < 0 if > 0 Subtract the value

span t-if="move.forecast availability < 0 == 'move.product_uom_qty+move.forecast_availabilty'" 
Avatar
Discard
Best Answer

Hi Ahmed Mokhtar, 

Your Description is too short, but as per my understanding, please try with below code

< t t-set="subtotal" t-value="move.product_uom_qty" / >


< t t-if="move.forecast availability < 0 >
< t t-set="subtotal" t-value="subtotal + move.forecast_availabilty" / >
< /t >


< t t-if="move.forecast availability > 0 >
< t t-set="subtotal" t-value="subtotal - move.forecast_availabilty" / >
< /t >

Please Vote for the Answer if it helps.

Avatar
Discard
Author

it's give me

lxml.etree.XMLSyntaxError: error parsing attribute name

in line

< t t-if="move.forecast availability < 0 >
i think < or > not working in the code

Yes, you need to use &lt; for < and &gt; for >

Author

is this code is right
<t t-set="subtotal" t-value="move.product_uom_qty" />
<t t-if="move.forecast availability &lt; 0" >
<t t-set="subtotal" t-value="subtotal + move.forecast_availabilty" />
</t>

<t t-if="move.forecast availability &gt; 0">
<t t-set="subtotal" t-value="subtotal - move.forecast_availabilty" />
</t>
it's give me error

Error when compiling xml template
SyntaxError: invalid syntax (<>, line 1)
Template: stock.report_delivery_document_copy_3
Path: /t/t/t/div/table[1]/tbody/tr[1]/td[4]/t[2]/t
Node: < t t-set="subtotal" t-value="subtotal + move.forecast_availabilty"/>

Please check the syntax and spaces.