Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
447 Weergaven

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
Annuleer
Beste antwoord

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
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
1
apr. 16
4112
1
jun. 15
3878
0
mrt. 15
3253
3
jun. 24
50740
1
dec. 19
4041