From aa20b2de71ef9f4bdac64a68cc84ae97b6f8b3b2 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 --- modules/production/production.py | 4 ++-- modules/stock/shipment.py | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/modules/production/production.py b/modules/production/production.py index ecbb257b83..c6b4e36874 100644 --- a/modules/production/production.py +++ b/modules/production/production.py @@ -682,14 +682,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 6f41766546..2cb4b8f676 100644 --- a/modules/stock/shipment.py +++ b/modules/stock/shipment.py @@ -570,7 +570,7 @@ class ShipmentIn( # 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: @@ -578,7 +578,7 @@ class ShipmentIn( '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: @@ -932,7 +932,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, { @@ -1703,7 +1703,7 @@ class ShipmentOut( 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, { @@ -1711,7 +1711,7 @@ class ShipmentOut( })) 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, { @@ -2088,14 +2088,14 @@ class ShipmentOutReturn( 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, { @@ -2924,7 +2924,7 @@ class ShipmentInternal( and shipment.state not in {'request', 'draft'}): 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) @@ -2932,7 +2932,7 @@ class ShipmentInternal( 'planned_date': outgoing_date, }) 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) @@ -2942,7 +2942,7 @@ class ShipmentInternal( else: planned_start_date = shipment.planned_start_date 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 != planned_start_date)] if moves: to_write.append(moves)