From 03e7a79980c7d67c2b51c03067155e3883e4721a Mon Sep 17 00:00:00 2001
From: Jorrit Schaap <schaap@astron.nl>
Date: Fri, 26 Jun 2020 16:36:04 +0200
Subject: [PATCH] TMSS-207: moved allow_scheduling_observations setting from
 observation check to generic check

---
 SAS/TMSS/src/tmss/tmssapp/subtasks.py | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/SAS/TMSS/src/tmss/tmssapp/subtasks.py b/SAS/TMSS/src/tmss/tmssapp/subtasks.py
index 862f924c985..2c863220230 100644
--- a/SAS/TMSS/src/tmss/tmssapp/subtasks.py
+++ b/SAS/TMSS/src/tmss/tmssapp/subtasks.py
@@ -319,6 +319,12 @@ def check_prerequities_for_scheduling(subtask: Subtask) -> bool:
         if predecessor.state.value != SubtaskState.Choices.FINISHED.value:
             raise SubtaskSchedulingException("Cannot schedule subtask id=%d because its predecessor id=%s in not FINISHED but state=%s" % (subtask.pk, predecessor.pk, predecessor.state.value))
 
+    # check if settings allow scheduling observations
+    setting = Setting.objects.get(name='allow_scheduling_observations')
+    if not setting.value:
+        raise SubtaskSchedulingException("Cannot schedule subtask id=%d because setting %s=%s does not allow that." %
+                                         (subtask.pk, setting.name, setting.value))
+
     return True
 
 def schedule_qafile_subtask(qafile_subtask: Subtask):
@@ -434,13 +440,6 @@ def schedule_observation_subtask(observation_subtask: Subtask):
                                                                                                           observation_subtask.specifications_template.type,
                                                                                                           SubtaskType.Choices.OBSERVATION.value))
 
-    # check if settings allow scheduling observations
-    # (not sure if this should be in check_prerequities_for_scheduling() instead....?)
-    setting = Setting.objects.get(name='allow_scheduling_observations')
-    if not setting.value:
-        raise SubtaskSchedulingException("Cannot schedule subtask id=%d because setting %s=%s does not allow that." %
-                                         (observation_subtask.pk, setting.name, setting.value))
-
     # step 1: set state to SCHEDULING
     observation_subtask.state = SubtaskState.objects.get(value=SubtaskState.Choices.SCHEDULING.value)
     observation_subtask.save()
-- 
GitLab