Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
3337 Vistas

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
Descartar
Mejor respuesta

Try this one:


smile_decimal_precision

Avatar
Descartar
Autor

This looks great, thanks!!

Mejor respuesta

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
ago 21
7582
1
oct 19
31
1
sept 20
4337
0
feb 16
3832
0
abr 25
237