From ae38618e2556b37a66d1173a482d2ebc0f5eba9c Mon Sep 17 00:00:00 2001
From: Jorrit Schaap <schaap@astron.nl>
Date: Tue, 22 Jun 2021 15:48:38 +0200
Subject: [PATCH] TMSS-854: added simple aggregation of obsolete states. ToDo
 in TMSS-850 implement the various conditional aggregations for the 'obsolete'
 vs 'finished' states

---
 .../backend/src/tmss/tmssapp/models/specification.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py b/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py
index 3866957e785..540dc4d8639 100644
--- a/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py
+++ b/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py
@@ -496,6 +496,7 @@ class SchedulingUnitBlueprint(ProjectPropertyMixin, TemplateSchemaMixin, NamedCo
         INGESTING = "ingesting"
         SCHEDULED = "scheduled"
         SCHEDULABLE = "schedulable"
+        OBSOLETE = "obsolete"
 
     # todo: are many of these fields supposed to be immutable in the database?
     #  Or are we fine to just not allow most users to change them?
@@ -652,6 +653,9 @@ class SchedulingUnitBlueprint(ProjectPropertyMixin, TemplateSchemaMixin, NamedCo
             return SchedulingUnitBlueprint.Status.CANCELLED.value
         elif self._any_task_error(status_overview_counter):
             return SchedulingUnitBlueprint.Status.ERROR.value
+        elif self._any_task_obsolete(status_overview_counter):
+            # TODO: in TMSS-850 implement the various conditional aggregations for the 'obsolete' vs 'finished' states
+            return SchedulingUnitBlueprint.Status.OBSOLETE.value
         elif self._any_task_started_observed_finished(status_overview_counter):
             if not self._all_observation_task_observed_finished(status_overview_counter_per_type):
                 return SchedulingUnitBlueprint.Status.OBSERVING.value
@@ -688,6 +692,10 @@ class SchedulingUnitBlueprint(ProjectPropertyMixin, TemplateSchemaMixin, NamedCo
     def _any_task_error(status_overview_counter):
         return status_overview_counter["error"] > 0
 
+    @staticmethod
+    def _any_task_obsolete(status_overview_counter):
+        return status_overview_counter["obsolete"] > 0
+
     @staticmethod
     def _any_task_started_observed_finished(status_overview_counter):
         return (status_overview_counter["started"] + status_overview_counter["observed"] + status_overview_counter["finished"]) > 0
@@ -1050,6 +1058,10 @@ class TaskBlueprint(ProjectPropertyMixin, TemplateSchemaMixin, NamedCommon):
         if any(s for s in subtasks if s['state'] == 'error'):
             return "error"
 
+        # TODO: in TMSS-850 implement the various conditional aggregations for the 'obsolete' vs 'finished' states
+        if any(s for s in subtasks if s['state'] == 'obsolete'):
+            return "obsolete"
+
         observations = [s for s in subtasks if s['specifications_template__type_id'] == 'observation']
         if observations and all(obs and obs['state'] in ('finishing', 'finished') for obs in observations):
             return "observed"
-- 
GitLab