Odoo decimal precision based on Unit Of Measure

1.6k Views Asked by At

Anybody an idea how to set the decimal precision of a product based on the unit of measure it is sold it. For example product X sold in Kg has a decimal precision of 3 => Qty: 10.000Kg Product Y sold in Unit(s) had a decimal precision of 0 -> Qty: 10 Unit(s)

Thanks in advance.

2

There are 2 best solutions below

1
forvas On

Import this at the top of your .py file:

from openerp.tools.float_utils import float_round

Now, imagine you have a product recordset (object/group of objects of products) in self:

your_quantity = 10.000
rounding = self.uom_id.rounding
qty = float_round(your_quantity, precision_rounding=rounding)
0
Pranjal Gami On

Try this code.

import odoo.addons.decimal_precision as dp
lost_qty = fields.Float('Lost Qty',  compute = '_compute_lost_qty',  digits = dp.get_precision('Product Unit of Measure'))
  • You can also find these decimal precision in Odoo configuration Settings -> Database Structure -> Decimal Accuracy