fix
This commit is contained in:
Generated
+1
-1
@@ -16,7 +16,7 @@
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="J:\Projects\02_Cetana_Backend\.venv" jdkType="Python SDK" />
|
||||
<orderEntry type="jdk" jdkName="I:\Project\02_Cetana_Backend\.venv" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="TemplatesService">
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user