From ceefdeb72ff54b60c8a6a45a32dbbeb8c92bd69a Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Sat, 6 Mar 2021 19:19:53 +0100 Subject: [PATCH] Manage staging moves on shipment workflow Staging moves are automatically assigned when purchased so we should remove them when packing a shipment as they are not part of the shipment. We also skip moves with zero quantity because they will always succeed. issue9448 review313951002 --- move.py | 6 ++++-- shipment.py | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/move.py b/move.py index 5a9ed2410a..4dc3d9277d 100644 --- a/move.py +++ b/move.py @@ -474,10 +474,12 @@ class Move(Workflow, ModelSQL, ModelView): return ((from_type != 'storage' and to_type == 'storage') or (from_type == 'storage' and to_type != 'storage')) - @fields.depends('from_location') + @fields.depends('from_location', 'quantity') def on_change_with_assignation_required(self, name=None): if self.from_location: - return self.from_location.type in {'storage', 'view'} + return ( + self.quantity + and self.from_location.type in {'storage', 'view'}) @staticmethod def _get_shipment(): diff --git a/shipment.py b/shipment.py index 718642a4de..3558155449 100644 --- a/shipment.py +++ b/shipment.py @@ -1249,6 +1249,9 @@ class ShipmentOut(ShipmentAssignMixin, Workflow, ModelSQL, ModelView): def pick(cls, shipments): pool = Pool() Move = pool.get('stock.move') + Move.delete([ + m for s in shipments for m in s.inventory_moves + if m.state == 'staging']) Move.do([m for s in shipments for m in s.inventory_moves]) cls._sync_inventory_to_outgoing(shipments, quantity=True) @@ -1350,6 +1353,9 @@ class ShipmentOut(ShipmentAssignMixin, Workflow, ModelSQL, ModelView): Move = pool.get('stock.move') Date = pool.get('ir.date') + Move.delete([ + m for s in shipments for m in s.outgoing_moves + if m.state == 'staging']) Move.do([m for s in shipments for m in s.outgoing_moves]) cls.write([s for s in shipments if not s.effective_date], { 'effective_date': Date.today(),