Pick only from children location when assigned stock move from supplied sale line

Closes #12812
(grafted from dd0350421ca455db89819c786330738cfce2b602)

--HG--
branch : 6.0
This commit is contained in:
Cédric Krier committed 2023-12-08 12:53:16 +01:00
1 parent 9b73ee7bdb
commit 5c3d63a4c4
1 file changed
+23
+23
View File
@@ -182,6 +182,7 @@ class Line(metaclass=PoolMeta):
Uom = pool.get('product.uom')
Move = pool.get('stock.move')
ShipmentOut = pool.get('stock.shipment.out')
Location = pool.get('stock.location')
if self.supply_state != 'supplied':
return
@@ -221,11 +222,33 @@ class Line(metaclass=PoolMeta):
for inv_move in inventory_moves:
if inv_move.product == self.product:
moves.add(inv_move)
child_locations = {}
to_write = []
to_assign = []
for move in moves:
if move.state != 'draft':
continue
childs = child_locations.get(move.from_location)
if childs is None:
childs = Location.search([
('parent', 'child_of', [move.from_location.id]),
('type', '!=', 'view'),
])
child_locations[move.from_location] = childs
# Prevent picking from the destination location
try:
childs.remove(move.to_location)
except ValueError:
pass
# Try first to pick from source location
try:
childs.remove(move.from_location)
childs.insert(0, move.from_location)
except ValueError:
# from_location may be a view
pass
qties_converted = []
for key, quantity in quantities.items():
move_key = get_key(move, key[0])