From 8dbaaf896e060725307c3eaedbc5d99af7d78a4e Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Fri, 1 Jun 2018 10:47:16 +0200 Subject: [PATCH] [FIX] stock: assign move - Create a BOM for Product A, using Component B 1 Unit of a is built with 1 Unit of B - Update on hand quantity for B to 3.0 - Create a MO for 5 Units of A - Update the quantity to produce to 3.0 The button 'Check Availability' never disappears. The core of the problem is that the move remains "Partially Available". Indeed, if there is no product available (`available_quantity <= 0`), the stock move is skipped and its availability status is not updated. We slightly change the logic by first checking if we need any quantity. If not, the move can be considered as assigned. opw-1850499 --- addons/stock/models/stock_move.py | 6 +++++- addons/stock/tests/test_move.py | 26 +++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) 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) -