Skip to Content
Menu
This question has been flagged

I have the following product unit prices:

10.00

12.375

15.4755

How can I show JUST the number of decimals in the amount?

If it is 2, I want to show 2.

If 3 or 4, show 3 or 4.

I don't want EVERY price to show the same number of decimals.

Is this possible?

Avatar
Discard
Best Answer

You will want to override how Odoo shows the data in the td_price_unit cell of the Invoice Lines:


Instead of this:

<td name="td_price_unit">
    <span class="text-nowrap" t-field="line.price_unit">9.00</span>
</td>


Do something like this:

<td name="td_price_unit">
    <t t-set="decimals"
       t-value="max(2, len(str(line.price_unit).split('.')[1]) if '.' in str(line.price_unit) and len(str(line.price_unit).split('.')) > 1 else 2)"/>
    <span class="text-nowrap" t-esc="('{:.' + str(decimals) + 'f}').format(line.price_unit)">9.00</span>
</td>

Note: the complex calculation ensures you never drop below 2 digits, so $10 even will show always as 10.00.


Avatar
Discard
Related Posts Replies Views Activity
1
Apr 16
4049
1
Jun 15
3858
0
Mar 15
3225
3
Jun 24
50740
1
Dec 19
4012