From 5cda753f9f27d99377c4dfd3f6cefa34f39789be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 26 Dec 2023 16:00:06 +0100 Subject: [PATCH] Allow assigned move of 0 quantity using view location and delete them This is needed to be able to ignore assignation of move from a view location, and to delete them before all moves are set to done. Closes #12870 --- modules/stock/move.py | 6 ++++-- modules/stock/shipment.py | 2 +- modules/stock/tests/scenario_stock_shipment_out.rst | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/stock/move.py b/modules/stock/move.py index b364c2d7f2..8fa7d8360f 100644 --- a/modules/stock/move.py +++ b/modules/stock/move.py @@ -28,7 +28,8 @@ STATES = { 'readonly': Eval('state').in_(['cancelled', 'assigned', 'done']), } LOCATION_DOMAIN = [ - If(Eval('state').in_(['staging', 'draft', 'cancelled']), + If(Eval('state').in_(['staging', 'draft', 'cancelled']) + | ((Eval('state') == 'assigned') & ~Eval('quantity')), ('type', 'not in', ['warehouse']), ('type', 'not in', ['warehouse', 'view'])), If(~Eval('state').in_(['done', 'cancelled']), @@ -927,7 +928,8 @@ class Move(Workflow, ModelSQL, ModelView): @classmethod def delete(cls, moves): for move in moves: - if move.state not in {'staging', 'draft', 'cancelled'}: + if (move.state not in {'staging', 'draft', 'cancelled'} + and move.quantity): raise AccessError( gettext('stock.msg_move_delete_draft_cancel', move=move.rec_name)) diff --git a/modules/stock/shipment.py b/modules/stock/shipment.py index 2cb4b8f676..5b09ac4454 100644 --- a/modules/stock/shipment.py +++ b/modules/stock/shipment.py @@ -1537,7 +1537,7 @@ class ShipmentOut( Move = pool.get('stock.move') Move.delete([ m for s in shipments for m in s.inventory_moves - if m.state == 'staging']) + if m.state == 'staging' or not m.quantity]) Move.do([m for s in shipments for m in s.inventory_moves]) Move.draft([m for s in shipments for m in s.outgoing_moves]) cls._sync_inventory_to_outgoing(shipments, quantity=True) diff --git a/modules/stock/tests/scenario_stock_shipment_out.rst b/modules/stock/tests/scenario_stock_shipment_out.rst index 9230a3bc57..63622bdebe 100644 --- a/modules/stock/tests/scenario_stock_shipment_out.rst +++ b/modules/stock/tests/scenario_stock_shipment_out.rst @@ -181,7 +181,7 @@ Ignore non assigned moves and pack shipment:: >>> len(shipment_out.outgoing_moves) 1 >>> len(shipment_out.inventory_moves) - 2 + 1 >>> shipment_out.inventory_moves[0].state 'done' >>> sum([m.quantity for m in shipment_out.inventory_moves]) == \ @@ -209,7 +209,7 @@ Set the state as Done:: >>> len(shipment_out.outgoing_moves) 1 >>> len(shipment_out.inventory_moves) - 2 + 1 >>> shipment_out.inventory_moves[0].state 'done' >>> sum([m.quantity for m in shipment_out.inventory_moves]) == \