Skip to content

Commit

Permalink
[FIX] stock : rounding in the traceability report
Browse files Browse the repository at this point in the history
- Call to float_round(3.570, precision_rounding=0.001) returns 3.5700000000000003 instead of returning 3.570 (in the _compute_quantity method).
- This report is all prepared server side so directly called value_to_html method to set the value of quantity with appropriate decimal precision to get proper value in Upstream Traceability report

Fixes #22815
Task #1817420
  • Loading branch information
kme-odoo authored and sle-odoo committed Mar 23, 2018
1 parent 8e56499 commit e3a0d92
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions addons/stock/models/stock_traceability.py
Expand Up @@ -145,6 +145,12 @@ def get_links(self, move_line):
ref = move_line.move_id.scrap_ids[0].name
return res_model, res_id, ref

@api.model
def _quantity_to_str(self, from_uom, to_uom, qty):
""" workaround to apply the float rounding logic of t-esc on data prepared server side """
qty = from_uom._compute_quantity(qty, to_uom, rounding_method='HALF-UP')
return self.env['ir.qweb.field.float'].value_to_html(qty, {'decimal_precision': 'Product Unit of Measure'})

def make_dict_move(self, level, parent_id, move_line, stream=False, unfoldable=False):
res_model, res_id, ref = self.get_links(move_line)
data = [{
Expand All @@ -155,7 +161,7 @@ def make_dict_move(self, level, parent_id, move_line, stream=False, unfoldable=F
'model_id': move_line.id,
'model':'stock.move.line',
'product_id': move_line.product_id.display_name,
'product_qty_uom': str(move_line.product_uom_id._compute_quantity(move_line.qty_done, move_line.product_id.uom_id, rounding_method='HALF-UP')) + ' ' + move_line.product_id.uom_id.name,
'product_qty_uom': "%s %s" % (self._quantity_to_str(move_line.product_uom_id, move_line.product_id.uom_id, move_line.qty_done), move_line.product_id.uom_id.name),
'location': move_line.location_id.name + ' -> ' + move_line.location_dest_id.name,
'reference_id': ref,
'res_id': res_id,
Expand All @@ -175,7 +181,7 @@ def make_dict_head(self, level, parent_id, model=False, stream=False, move_line=
'model': model or 'stock.move.line',
'product_id': move_line.product_id.display_name,
'lot_id': move_line.lot_id.name,
'product_qty_uom': str(move_line.product_uom_id._compute_quantity(move_line.qty_done, move_line.product_id.uom_id, rounding_method='HALF-UP')) + ' ' + move_line.product_id.uom_id.name,
'product_qty_uom': "%s %s" % (self._quantity_to_str(move_line.product_uom_id, move_line.product_id.uom_id, move_line.qty_done), move_line.product_id.uom_id.name),
'location': move_line.location_dest_id.name,
'stream': stream,
'reference_id': False}]
Expand All @@ -189,7 +195,7 @@ def make_dict_head(self, level, parent_id, model=False, stream=False, move_line=
'model': model or 'stock.quant',
'product_id': move_line.product_id.display_name,
'lot_id': move_line.lot_id.name,
'product_qty_uom': str(move_line.quantity) + ' ' + move_line.product_id.uom_id.name,
'product_qty_uom': "%s %s" % (self._quantity_to_str(move_line.product_uom_id, move_line.product_id.uom_id, move_line.quantity), move_line.product_id.uom_id.name),
'location': move_line.location_id.name,
'stream': stream,
'reference_id': False}]
Expand Down

0 comments on commit e3a0d92

Please sign in to comment.