Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
4041 Weergaven

I'm currently using Odoo Enterprise v16 and need to adjust the decimal precision of our product prices to 4 digits for accurate purchase order calculations. However, this causes our online sales orders, viewed by customers via the web portal, to display unit prices with 4 decimal places. This looks very unprofessional / janky, especially when the total is in 2 decimal places. 


In applications like Excel, you can type in a number with multiple decimal points (e.g., 2.76348) and format it to display just 2 decimal places without losing the original data. Excel still calculates the on the full number even though only two decimals are displayed. Ideally, I want the same behavior applied globally in Odoo.


Is there a widget or customization I can do to force both float and monetary fields to display in two decimals while retaining 4 decimal places of data?


If not, is there a workaround for the specific issue above?

Thanks in advance for the help.

Avatar
Annuleer
Beste antwoord

Try this one:


smile_decimal_precision

Avatar
Annuleer
Auteur

This looks great, thanks!!

Beste antwoord

Hi Robbie,

A solution is to have two fields:

price = fields.Float(string='Price', digits=(10, 4))

price_char = fields.Char(string='Price', compute='_compute_price_char')


def _compute_price_char(self):

    for r in self:

        r.price_char = compute_char(r.price)

def compute_char(price):

    price_char = str(price)

    price_char += '0000'

    p = price_char.find('.')

    begin = price_char[:p+1]

    end = price_char[p+1:]

    while end.endswith('0') and len(end) >= 2:

        price_char = price_char[:-1]


    return begin + end


In this case, if e.g. price = 1.2345

                       then price_char = '1.2345'

And if price = 1.2300

Then price_char = '1.23'


Boris




Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
1
aug. 21
8160
1
okt. 19
31
1
sep. 20
4788
0
feb. 16
4108
0
jul. 25
654