[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
This commit is contained in:
Nicolas Martinelli
2018-06-04 08:32:39 +02:00
committed by Nicolas Martinelli
parent 395459d077
commit 8dbaaf896e
2 changed files with 30 additions and 2 deletions
+5 -1
View File
@@ -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
+25 -1
View File
@@ -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)