diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 2aa5f4326ee..393b0a31c28 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -918,11 +918,15 @@ class StockMove(models.Model): if not move.move_orig_ids: if move.procure_method == 'make_to_order': continue + # If we don't need any quantity, consider the move assigned. + need = move.product_qty - move.reserved_availability + if float_is_zero(need, precision_rounding=move.product_id.uom_id.rounding): + assigned_moves |= move + continue # Reserve new quants and create move lines accordingly. available_quantity = self.env['stock.quant']._get_available_quantity(move.product_id, move.location_id) if available_quantity <= 0: continue - need = move.product_qty - move.reserved_availability taken_quantity = move._update_reserved_quantity(need, available_quantity, move.location_id, strict=False) if float_is_zero(taken_quantity, precision_rounding=move.product_id.uom_id.rounding): continue diff --git a/addons/stock/tests/test_move.py b/addons/stock/tests/test_move.py index df57065b8d7..8326328bc95 100644 --- a/addons/stock/tests/test_move.py +++ b/addons/stock/tests/test_move.py @@ -925,6 +925,31 @@ class StockMove(TransactionCase): self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.customer_location), 12.0) self.assertEqual(len(self.env['stock.quant']._gather(self.product2, self.customer_location)), 12) + def test_availability_8(self): + """ Test the assignment mechanism when the product quantity is decreased on a partially + reserved stock move. + """ + # make some stock + self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 3.0) + self.assertAlmostEqual(self.product1.qty_available, 3.0) + + move_partial = self.env['stock.move'].create({ + 'name': 'test_partial', + 'location_id': self.stock_location.id, + 'location_dest_id': self.customer_location.id, + 'product_id': self.product1.id, + 'product_uom': self.uom_unit.id, + 'product_uom_qty': 5.0, + }) + + move_partial._action_confirm() + move_partial._action_assign() + self.assertAlmostEqual(self.product1.virtual_available, -2.0) + self.assertEqual(move_partial.state, 'partially_available') + move_partial.product_uom_qty = 3.0 + move_partial._action_assign() + self.assertEqual(move_partial.state, 'assigned') + def test_unreserve_1(self): """ Check that unreserving a stock move sets the products reserved as available and set the state back to confirmed. @@ -3767,4 +3792,3 @@ class StockMove(TransactionCase): picking.button_validate() self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.customer_location), 2) -