K.ju
K.ju

Reputation: 593

How to display fields with decimal precision defined ? Odoo 14

In 'purchase.order.line' model , I want to change the decimal precision for the 'unit_price' and 'price_subtotal' fields

These fields should have a precision of 4 digits and are displayed in the purchase order_line.

Here is my code :

class PurchaseOrderLine(models.Model):
    _inherit = "purchase.order.line"
    price_unit = fields.Float(string='Unit Price', required=True, digits=(16, 4))
    price_subtotal = fields.Monetary(compute='_compute_amount', string='Subtotal', store=True, digits = (16, 4))

I only got the field 'price_unit' with 4 digits , but nothing changing for 'price_subtotal'. Is it because of computed field?

How can I fix it please?

Thanks.

Upvotes: 1

Views: 1939

Answers (2)

Sabah HM
Sabah HM

Reputation: 81

If you only want the price_subtotal field precision as desired, then you will have to declare it as Float instead of Monetary , you will lose certain advanced things [such as showing the currency].

Yet if you want to change the whole precision in the subtotals, you can change the precision of the currency.

Upvotes: 0

Kerrim
Kerrim

Reputation: 523

This happens because its a Monetary field and it gets its decimal precision from the currency not the digits argument. The field that relates to the currency can be set by using currency_field as attribute of the Monetary field and defaults to currency_id.

Upvotes: 1

Related Questions