From 498d983e6f7efe98a86660c51563573119f55e64 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 19 Oct 2026 23:03:58 +0330 Subject: [PATCH] fix --- .idea/cetana-backend.iml | 2 +- apps/orders/services.py | 41 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/.idea/cetana-backend.iml b/.idea/cetana-backend.iml index 0ae8197..94a09f4 100644 --- a/.idea/cetana-backend.iml +++ b/.idea/cetana-backend.iml @@ -16,7 +16,7 @@ - + diff --git a/apps/orders/services.py b/apps/orders/services.py index 4746ce1..8307cbb 100644 --- a/apps/orders/services.py +++ b/apps/orders/services.py @@ -78,4 +78,45 @@ class OrderService: order.confirmed_at = timezone.now() order.terms_accepted = True order.save(update_fields=["status", "confirmed_at", "terms_accepted"]) + + # ── Spawn one StepExecution per selected step ────────────────────── + # This is what makes records appear in the /processing/ page. + # We use get_or_create so re-confirming an order never duplicates rows. + self._spawn_step_executions(order) + return order + + def _spawn_step_executions(self, order) -> None: + """Create a StepExecution for every step the customer selected. + + The first step (lowest `order`) is set to READY so operators know + exactly where to begin. All subsequent steps stay PENDING until the + workflow engine or an operator explicitly advances them. + """ + from apps.processing.models import StepExecution + + if not order.selected_step_keys: + return + + steps = list( + order.workflow_version.steps + .filter(key__in=order.selected_step_keys, enabled=True) + .order_by("order") + ) + for index, step in enumerate(steps): + initial_state = ( + StepExecution.State.READY if index == 0 + else StepExecution.State.PENDING + ) + StepExecution.objects.get_or_create( + order=order, + step=step, + attempt=1, + defaults={"state": initial_state}, + ) + + # Move the order itself into PROCESSING so the orders list + # reflects the current reality. + ProcessingOrder.objects.filter(pk=order.pk).update( + status=ProcessingOrder.Status.PROCESSING + )