Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
489 Vizualizări

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?

Imagine profil
Abandonează
Cel mai bun răspuns

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.


Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
apr. 16
4160
1
iun. 15
3902
0
mar. 15
3280
3
iun. 24
50740
1
dec. 19
4075