From ceed27e09cc2e83c69ae1ebee551ee247652de73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 29 Dec 2022 18:19:37 +0100 Subject: [PATCH] Assign supplied outgoing moves instead of inventory moves If the output location is the same as the storage location, there is no inventory moves on the outgoing shipment, so the outgoing moves must be assigned. If the input location is the same as the storage location, there is neither inventory moves on the incoming shipment, so the quantity must be computed based on the incoming moves. Closes #11972 (grafted from e22f31a0163998902145ea47d76ded437e0c7ccf) --HG-- branch : 6.0 --- modules/sale_supply/sale.py | 11 ++++++++--- modules/sale_supply/stock.py | 6 +++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/sale_supply/sale.py b/modules/sale_supply/sale.py index f30847dffa..90c434d0a5 100644 --- a/modules/sale_supply/sale.py +++ b/modules/sale_supply/sale.py @@ -212,9 +212,14 @@ class Line(metaclass=PoolMeta): moves = set() for move in self.moves: - if isinstance(move.shipment, ShipmentOut): - for inv_move in move.shipment.inventory_moves: - if inv_move.product.id == self.product.id: + shipment = move.shipment + if isinstance(shipment, ShipmentOut): + if shipment.warehouse_storage == shipment.warehouse_output: + inventory_moves = shipment.outgoing_moves + else: + inventory_moves = shipment.inventory_moves + for inv_move in inventory_moves: + if inv_move.product == self.product: moves.add(inv_move) to_write = [] to_assign = [] diff --git a/modules/sale_supply/stock.py b/modules/sale_supply/stock.py index 4d2494489b..2dda3b319e 100644 --- a/modules/sale_supply/stock.py +++ b/modules/sale_supply/stock.py @@ -47,7 +47,11 @@ class ShipmentIn(metaclass=PoolMeta): ('purchase_request.origin', 'like', 'sale.sale,%'), ]) pbl = defaultdict(lambda: defaultdict(int)) - for move in filter(filter_func, self.inventory_moves): + if self.warehouse_storage == self.warehouse_input: + inventory_moves = self.incoming_moves + else: + inventory_moves = self.inventory_moves + for move in filter(filter_func, inventory_moves): pbl[move.product][get_key(move)] += move.internal_quantity for sale_line in sale_lines: sale_line.assign_supplied(