跳至内容
菜单
此问题已终结
2 回复
13989 查看

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.

形象
丢弃
最佳答案

 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>

形象
丢弃
编写者 最佳答案

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.

形象
丢弃

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

相关帖文 回复 查看 活动
2
12月 23
24700
1
1月 20
5176
2
6月 24
1465
0
10月 23
1393
3
7月 23
30705