From ebb34ea32a247102a98ff3787c67c6fddefa1779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 23 Dec 2023 02:32:43 +0100 Subject: [PATCH] Update planned date of assigned move from shipment and production Closes #12867 (grafted from 1caa3667c8759bfd92c315d12aae4fb5f57ad587) --HG-- branch : 6.0 --- modules/production/production.py | 4 ++-- modules/stock/shipment.py | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/production/production.py b/modules/production/production.py index 4ca6ede401..ed2ece81ba 100644 --- a/modules/production/production.py +++ b/modules/production/production.py @@ -680,14 +680,14 @@ class Production(ShipmentAssignMixin, Workflow, ModelSQL, ModelView): dates = production._get_move_planned_date() input_date, output_date = dates inputs = [m for m in production.inputs - if m.state not in ('assigned', 'done', 'cancelled')] + if m.state not in {'done', 'cancelled'}] if inputs: to_write.append(inputs) to_write.append({ 'planned_date': input_date, }) outputs = [m for m in production.outputs - if m.state not in ('assigned', 'done', 'cancelled')] + if m.state not in {'done', 'cancelled'}] if outputs: to_write.append(outputs) to_write.append({ diff --git a/modules/stock/shipment.py b/modules/stock/shipment.py index 9f900d3fcc..2f4fcd0661 100644 --- a/modules/stock/shipment.py +++ b/modules/stock/shipment.py @@ -401,7 +401,7 @@ class ShipmentIn(ShipmentMixin, Workflow, ModelSQL, ModelView): # Update planned_date only for later to not be too optimistic if # the shipment is not directly received. incoming_moves_to_write = [m for m in shipment.incoming_moves - if (m.state not in ('assigned', 'done', 'cancelled') + if (m.state not in {'done', 'cancelled'} and ((m.planned_date or datetime.date.max) < (incoming_date or datetime.date.max)))] if incoming_moves_to_write: @@ -409,7 +409,7 @@ class ShipmentIn(ShipmentMixin, Workflow, ModelSQL, ModelView): 'planned_date': incoming_date, })) inventory_moves_to_write = [m for m in shipment.inventory_moves - if (m.state not in ('assigned', 'done', 'cancelled') + if (m.state not in {'done', 'cancelled'} and ((m.planned_date or datetime.date.max) < (inventory_date or datetime.date.max)))] if inventory_moves_to_write: @@ -756,7 +756,7 @@ class ShipmentInReturn(ShipmentAssignMixin, Workflow, ModelSQL, ModelView): to_write = [] for shipment in shipments: moves = [m for m in shipment.moves - if (m.state not in ('assigned', 'done', 'cancelled') + if (m.state not in {'done', 'cancelled'} and m.planned_date != shipment._move_planned_date)] if moves: to_write.extend((moves, { @@ -1459,7 +1459,7 @@ class ShipmentOut(ShipmentAssignMixin, Workflow, ModelSQL, ModelView): for shipment in shipments: outgoing_date, inventory_date = shipment._move_planned_date out_moves_to_write = [x for x in shipment.outgoing_moves - if (x.state not in ('assigned', 'done', 'cancelled') + if (x.state not in {'done', 'cancelled'} and x.planned_date != outgoing_date)] if out_moves_to_write: to_write.extend((out_moves_to_write, { @@ -1467,7 +1467,7 @@ class ShipmentOut(ShipmentAssignMixin, Workflow, ModelSQL, ModelView): })) inv_moves_to_write = [x for x in shipment.inventory_moves - if (x.state not in ('assigned', 'done', 'cancelled') + if (x.state not in {'done', 'cancelled'} and x.planned_date != inventory_date)] if inv_moves_to_write: to_write.extend((inv_moves_to_write, { @@ -1847,14 +1847,14 @@ class ShipmentOutReturn(ShipmentMixin, Workflow, ModelSQL, ModelView): dates = shipment._get_move_planned_date() incoming_date, inventory_date = dates incoming_moves_to_write = [x for x in shipment.incoming_moves - if (x.state not in ('assigned', 'done', 'cancelled') + if (x.state not in {'done', 'cancelled'} and x.planned_date != incoming_date)] if incoming_moves_to_write: to_write.extend((incoming_moves_to_write, { 'planned_date': incoming_date, })) inventory_moves_to_write = [x for x in shipment.inventory_moves - if (x.state not in ('assigned', 'done', 'cancelled') + if (x.state not in {'done', 'cancelled'} and x.planned_date != inventory_date)] if inventory_moves_to_write: to_write.extend((inventory_moves_to_write, { @@ -2640,7 +2640,7 @@ class ShipmentInternal(ShipmentAssignMixin, Workflow, ModelSQL, ModelView): dates = shipment._move_planned_date outgoing_date, incoming_date = dates outgoing_moves = [m for m in shipment.outgoing_moves - if (m.state not in ('assigned', 'done', 'cancelled') + if (m.state not in ('done', 'cancelled') and m.planned_date != outgoing_date)] if outgoing_moves: to_write.append(outgoing_moves) @@ -2649,7 +2649,7 @@ class ShipmentInternal(ShipmentAssignMixin, Workflow, ModelSQL, ModelView): }) if shipment.transit_location: incoming_moves = [m for m in shipment.incoming_moves - if (m.state not in ('assigned', 'done', 'cancelled') + if (m.state not in {'done', 'cancelled'} and m.planned_date != incoming_date)] if incoming_moves: to_write.append(incoming_moves)