diff --git a/modules/sale_supply/sale.py b/modules/sale_supply/sale.py index 90c434d0a5..d3c96a40d0 100644 --- a/modules/sale_supply/sale.py +++ b/modules/sale_supply/sale.py @@ -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])