When printing invoices and order documents, I would like to remove trailing zeros, in order to get the following results:
- Odoo quantity: 1.000 -> printed quantity: 1
- Odoo quantity: 1.500 -> printed quantity: 1.5
- Odoo quantity: 2.750 -> printed quantity: 2.75
Based on Steve Mack's answer I tried the following in my QWeb amendment of the invoice document:
<xpath expr="//span[@t-field='l.quantity']" position="replace">
<t>
<t t-set="mod_qty">
formatLang(l.quantity, digit=0)
</t>
<t t-if="mod_qty == l.quantity">
<span><t t-esc="mod_qty"/></span>
</t>
<t t-if="mod_qty != l.quantity">
<span><t t-esc="(l.quantity * 1)"/></span>
</t>
</t>
</xpath>
But the result is not as desired, instead of "1", I receive "1.0", the other examples work properly. My result is:
Hii,try this
you will get wot u need :)
create new field 'quantity_new' and give onchange function for quantity
@api.onchange('quantity')
def onchange_quantity_for_demo(self):
a = self.quantity
b = str(a)
x=b.split(".")
if int(x[1])>0:
self.quantity_new = b
else:
self.quantity_new = str(x[0])
thank you