Skip to Content
Menu
This question has been flagged
2 Replies
13121 Views

Hi all,

On our Odoo instance, some articles are in kilograms, litters and units. We may sometime order/sale a few milliliters or grams of some articles. The Decimal Accuracy setting was adjusted to 4 digits for Product Unit of Measure. The drawback is that for articles in "Units", all values expected to be integers are also displayed with 4 digits after decimal. Ex. 20.0000 carrots for 20 carrots. For internal use, that's not a really issue. Nevertheless, be become an issue when dealing with order forms, invoices, etc.

To address this issue, I undertook to develop an add-on to modify the report_saleorder_document QWeb report defined for the template named sale.report_saleorder to display l.product_uom_qty as an integer when l.product_uom is set to "Unit(s)", else as a float.

My template.xml looks like :

<template id="report_saleorder_document" inherit_id="sale.report_saleorder_document">
<xpath expr="//span[@t-field='l.product_uom_qty']" position="replace">
<t t-set="unit" t-value="l.product_uom"/>
[<t t-esc="unit" />]
<span t-if="unit == 'product.uom(1,)'" t-esc="int(l.product_uom_qty)"/>
<span t-else="" t-field="l.product_uom_qty"/>
<!-- <span t-field="l.product_uom" groups="product.group_uom"/> -->
</xpath>
</template>

This display [product.uom(1,)] for [<t t-esc="unit" />]

But the test t-if="unit == 'product.uom(1,)'" fails. It seems QWeb tries to interpret/execute product.uom(1,) as it would do for any other function and do not use it as a literal string.

Would you have a solution in order address this simple need : display quantity as an integer when articles is in Units, display as a regular float else?

Thanks.

Maxime.

Avatar
Discard
Best Answer

 try:

<template id="report_saleorder_document" inherit_id="sale.report_saleorder_document">
<xpath expr="//span[@t-field='l.product_uom_qty']" position="replace">
         <t t-if="int(l.product_uom) == 1"> <!-- id of Unit(s) -->
             ...
         </t>
         <t t-if="int(l.product_uom) != 1">
             ...
         </t>
</template>

Avatar
Discard
Author Best Answer

Hi F.P.

Finally I gave up for an easier solution :

<span t-if="int(l.product_uom_qty) == l.product_uom_qty" t-esc="int(l.product_uom_qty)"/>
<span t-else="" t-field="l.product_uom_qty">

After all displaying 2.0000 L is the same as 2 L. But I'll try your solution too, it may be useful.

Thanks.

Avatar
Discard

there is uom_coeff column causing that 0000... have a look that one.

Related Posts Replies Views Activity
2
Dec 23
23593
1
Jan 20
4286
2
Jun 24
494
0
Oct 23
603
3
Jul 23
27790