콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
4057 화면

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.

아바타
취소
베스트 답변

Try this one:


smile_decimal_precision

아바타
취소
작성자

This looks great, thanks!!

베스트 답변

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




아바타
취소
관련 게시물 답글 화면 활동
1
8월 21
8163
1
10월 19
31
1
9월 20
4789
0
2월 16
4109
0
7월 25
657