1

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.

Jesse
  • 727
  • 13
  • 44

2 Answers2

2

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
Bhoomi Vaishnani
  • 718
  • 4
  • 19
Pranjal Gami
  • 214
  • 2
  • 15
0

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)
forvas
  • 9,801
  • 7
  • 62
  • 158