Skip to content
Permalink
Browse files

[FIX] stock: use float comparison to assign moves

We remove the remaining comparisons to use the precision rounding of the UoM.

opw 1969888
closes #32707
closes #32745

closes #32844

Signed-off-by: Nans Lefebvre (len) <len@odoo.com>
  • Loading branch information...
len-odoo committed Apr 19, 2019
1 parent 30e7a64 commit 0cce154794c8de945805d9b9acc4c33e5258191a
Showing with 8 additions and 6 deletions.
  1. +8 −6 addons/stock/models/stock_move.py
@@ -894,7 +894,9 @@ def _action_assign(self):
# Read the `reserved_availability` field of the moves out of the loop to prevent unwanted
# cache invalidation when actually reserving the move.
reserved_availability = {move: move.reserved_availability for move in self}
roundings = {move: move.product_id.uom_id.rounding for move in self}
for move in self.filtered(lambda m: m.state in ['confirmed', 'waiting', 'partially_available']):
rounding = roundings[move]
missing_reserved_uom_quantity = move.product_uom_qty - reserved_availability[move]
missing_reserved_quantity = move.product_uom._compute_quantity(missing_reserved_uom_quantity, move.product_id.uom_id, rounding_method='HALF-UP')
if move.location_id.should_bypass_reservation()\
@@ -922,7 +924,7 @@ def _action_assign(self):
continue
# If we don't need any quantity, consider the move assigned.
need = missing_reserved_quantity
if float_is_zero(need, precision_rounding=move.product_id.uom_id.rounding):
if float_is_zero(need, precision_rounding=rounding):
assigned_moves |= move
continue
# Reserve new quants and create move lines accordingly.
@@ -931,9 +933,9 @@ def _action_assign(self):
if available_quantity <= 0:
continue
taken_quantity = move._update_reserved_quantity(need, available_quantity, move.location_id, package_id=forced_package_id, strict=False)
if float_is_zero(taken_quantity, precision_rounding=move.product_id.uom_id.rounding):
if float_is_zero(taken_quantity, precision_rounding=rounding):
continue
if need == taken_quantity:
if float_compare(need, taken_quantity, precision_rounding=rounding) == 0:
assigned_moves |= move
else:
partially_available_moves |= move
@@ -996,12 +998,12 @@ def _keys_out_sorted(ml):
# this case `quantity` is directly the quantity on the quants themselves.
available_quantity = self.env['stock.quant']._get_available_quantity(
move.product_id, location_id, lot_id=lot_id, package_id=package_id, owner_id=owner_id, strict=True)
if float_is_zero(available_quantity, precision_rounding=move.product_id.uom_id.rounding):
if float_is_zero(available_quantity, precision_rounding=rounding):
continue
taken_quantity = move._update_reserved_quantity(need, min(quantity, available_quantity), location_id, lot_id, package_id, owner_id)
if float_is_zero(taken_quantity, precision_rounding=move.product_id.uom_id.rounding):
if float_is_zero(taken_quantity, precision_rounding=rounding):
continue
if need - taken_quantity == 0.0:
if float_is_zero(need - taken_quantity, precision_rounding=rounding):
assigned_moves |= move
break
partially_available_moves |= move

0 comments on commit 0cce154

Please sign in to comment.
You can’t perform that action at this time.