コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
4044 ビュー

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
8160
1
10月 19
31
1
9月 20
4788
0
2月 16
4108
0
7月 25
654