[FIX] stock: move the quantity reserved of another move

The condition in `_free_reservation` explicitely ignore move lines
having a done quantity. Let's imagine the scenrario where two stock
moves reserve all the quantity available and the user chose to process
all the quantity in a move while another user already set half the
quantity as reserved. In this case, we should keep the processed
quantity on the other move but correctly remove its reservation.
This commit is contained in:
Pierre Masereel
2017-12-15 13:22:21 +01:00
parent 9bc465988c
commit e794d80c98
2 changed files with 46 additions and 2 deletions
+4 -2
View File
@@ -473,7 +473,6 @@ class StockMoveLine(models.Model):
('owner_id', '=', owner_id.id if owner_id else False),
('package_id', '=', package_id.id if package_id else False),
('product_qty', '>', 0.0),
('qty_done', '=', 0.0),
('id', '!=', self.id),
]
oudated_candidates = self.env['stock.move.line'].search(oudated_move_lines_domain)
@@ -487,7 +486,10 @@ class StockMoveLine(models.Model):
if float_compare(candidate.product_qty, quantity, precision_rounding=rounding) <= 0:
quantity -= candidate.product_qty
move_to_recompute_state |= candidate.move_id
candidate.unlink()
if candidate.qty_done:
candidate.product_uom_qty = 0.0
else:
candidate.unlink()
else:
# split this move line and assign the new part to our extra move
quantity_split = float_round(
+42
View File
@@ -714,6 +714,48 @@ class StockMove(TransactionCase):
self.assertEqual(move1.state, 'assigned')
self.assertEqual(move1.reserved_availability, 1.0)
def test_availability_4(self):
self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 30.0)
move1 = self.env['stock.move'].create({
'name': 'test_availability_4',
'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': 15.0,
})
move1._action_confirm()
move1._action_assign()
self.assertEqual(move1.state, 'assigned')
move2 = self.env['stock.move'].create({
'name': 'test_availability_4',
'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': 15.0,
})
move2._action_confirm()
move2._action_assign()
# set 15 as quantity done for the first and 30 as the second
move1.move_line_ids.qty_done = 15
move2.move_line_ids.qty_done = 30
# validate the second, the first should be unreserved
move2._action_done()
self.assertEqual(move1.state, 'confirmed')
self.assertEqual(move1.move_line_ids.qty_done, 15)
self.assertEqual(move2.state, 'done')
stock_quants = self.env['stock.quant']._gather(self.product1, self.stock_location)
self.assertEqual(len(stock_quants), 0)
customer_quants = self.env['stock.quant']._gather(self.product1, self.customer_location)
self.assertEqual(customer_quants.quantity, 30)
self.assertEqual(customer_quants.reserved_quantity, 0)
def test_unreserve_1(self):
""" Check that unreserving a stock move sets the products reserved as available and
set the state back to confirmed.