Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
888 Widoki

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?

Awatar
Odrzuć
Najlepsza odpowiedź

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.


Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
kwi 16
4479
1
cze 15
4357
0
mar 15
3727
3
cze 24
50740
1
gru 19
4586