[FIX] stock: don't update a move line with qty=1 with serial product
Use case to reproduce: - create a product A with serial number - add 2 product A in stock - create a delivery order with this 4 product - Check Availability - add 2 more product A in stock - Check Availability - in the first line the quantity is now 3 It happens because _update_reserved_quantity on stock move try to add the quantity reserved on simililar move lines. Howevever in serial case we don't want to have a move line with a reserved quantity greater than 1.
This commit is contained in:
committed by
Arnold Moyaux
parent
c123049805
commit
ee7e9198f2
@@ -816,7 +816,8 @@ class StockMove(models.Model):
|
||||
|
||||
# Find a candidate move line to update or create a new one.
|
||||
for reserved_quant, quantity in quants:
|
||||
to_update = self.move_line_ids.filtered(lambda m: m.location_id.id == reserved_quant.location_id.id and m.lot_id.id == reserved_quant.lot_id.id and m.package_id.id == reserved_quant.package_id.id and m.owner_id.id == reserved_quant.owner_id.id)
|
||||
to_update = self.move_line_ids.filtered(lambda m: m.product_id.tracking != 'serial' and
|
||||
m.location_id.id == reserved_quant.location_id.id and m.lot_id.id == reserved_quant.lot_id.id and m.package_id.id == reserved_quant.package_id.id and m.owner_id.id == reserved_quant.owner_id.id)
|
||||
if to_update:
|
||||
to_update[0].with_context(bypass_reservation_update=True).product_uom_qty += self.product_id.uom_id._compute_quantity(quantity, self.product_uom, rounding_method='HALF-UP')
|
||||
else:
|
||||
|
||||
@@ -756,6 +756,28 @@ class StockMove(TransactionCase):
|
||||
self.assertEqual(customer_quants.quantity, 30)
|
||||
self.assertEqual(customer_quants.reserved_quantity, 0)
|
||||
|
||||
def test_availability_5(self):
|
||||
""" Check that rerun action assign only create new stock move
|
||||
lines instead of adding quantity in existing one.
|
||||
"""
|
||||
self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 2.0)
|
||||
# move from shelf1
|
||||
move = self.env['stock.move'].create({
|
||||
'name': 'test_edit_moveline_1',
|
||||
'location_id': self.stock_location.id,
|
||||
'location_dest_id': self.customer_location.id,
|
||||
'product_id': self.product2.id,
|
||||
'product_uom': self.uom_unit.id,
|
||||
'product_uom_qty': 4.0,
|
||||
})
|
||||
move._action_confirm()
|
||||
move._action_assign()
|
||||
|
||||
self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 4.0)
|
||||
move._action_assign()
|
||||
|
||||
self.assertEqual(len(move.move_line_ids), 4.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.
|
||||
|
||||
Reference in New Issue
Block a user