diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py b/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py index fe7a87aebd4fc5e0f5490cd823dc487d2fa6b048..f442f947609de3832d6a4c3057ed4d12f5244dd8 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py @@ -204,6 +204,7 @@ class SchedulingUnitStatus(AbstractChoice): # some common combinations of statuses PRE_ACTIVE_STATUS_VALUES = (Choices.DEFINED.value, Choices.SCHEDULABLE.value, Choices.UNSCHEDULABLE.value) + PRE_OBSERVING_STATUS_VALUES = PRE_ACTIVE_STATUS_VALUES + (Choices.SCHEDULED.value,) ACTIVE_STATUS_VALUES = (Choices.SCHEDULED.value, Choices.OBSERVING.value, Choices.OBSERVED.value, Choices.PROCESSING.value, Choices.PROCESSED.value, Choices.INGESTING.value, Choices.INGESTED.value) SCHEDULABLE_OR_ACTIVE_STATUS_VALUES = (Choices.SCHEDULABLE.value,) + ACTIVE_STATUS_VALUES ACTIVE_OR_FINISHED_STATUS_VALUES = (Choices.FINISHED.value,) + ACTIVE_STATUS_VALUES diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py b/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py index 4bc1ed194bec20ff59bab3f6573d9e7cf64464c0..6105317ffc7f0dce10a97a3d07a998772c0321c5 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py @@ -1639,7 +1639,7 @@ class SchedulingUnitBlueprintViewSet(LOFARViewSet): scheduling_unit_blueprint = get_object_or_404(models.SchedulingUnitBlueprint, pk=pk) - if scheduling_unit_blueprint.status.value not in models.SchedulingUnitStatus.PRE_ACTIVE_STATUS_VALUES: + if scheduling_unit_blueprint.status.value not in models.SchedulingUnitStatus.PRE_OBSERVING_STATUS_VALUES: return Response(f'Error: scheduling unit blueprint is already in status={scheduling_unit_blueprint.status.value}', status=400) with transaction.atomic(): @@ -1675,6 +1675,10 @@ class SchedulingUnitBlueprintViewSet(LOFARViewSet): # create a fresh blueprint from the updated draft with correct duration. new_blueprint = create_scheduling_unit_blueprint_and_tasks_and_subtasks_from_scheduling_unit_draft(new_draft) + # unschedule the old blueprint if needed + if scheduling_unit_blueprint.status.value == SchedulingUnitStatus.Choices.SCHEDULED.value: + scheduling_unit_blueprint = unschedule_subtasks_in_scheduling_unit_blueprint(scheduling_unit_blueprint) + # mark the old blueprint obsolete mark_scheduling_unit_blueprint_as_obsolete(scheduling_unit_blueprint)