From ca09ef573bc86048bda44525fa33b67f4d8a93cf Mon Sep 17 00:00:00 2001 From: Johan De Taeye Date: Thu, 10 Feb 2022 17:56:40 +0100 Subject: [PATCH] extra robustness when loading operationplan hierarchies --- freppledb/input/commands/load.py | 10 +++++++++- freppledb/input/models.py | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/freppledb/input/commands/load.py b/freppledb/input/commands/load.py index 1d918b51b5..c7e08e643a 100644 --- a/freppledb/input/commands/load.py +++ b/freppledb/input/commands/load.py @@ -1668,7 +1668,15 @@ def run(cls, database=DEFAULT_DB_ALIAS, **kwargs): == "true" ) if "supply" in os.environ: - confirmed_filter = " and operationplan.status in ('confirmed', 'approved', 'completed')" + confirmed_filter = """ and ( + operationplan.status in ('confirmed', 'approved', 'completed') + or exists ( + select 1 from operationplan as child_opplans + where child_opplans.owner_id = operationplan.reference + and child_opplans.status in ('approved', 'confirmed', 'completed') + ) + ) + """ create_flag = True else: confirmed_filter = "" diff --git a/freppledb/input/models.py b/freppledb/input/models.py index 140ccd99ef..079a521d87 100644 --- a/freppledb/input/models.py +++ b/freppledb/input/models.py @@ -1907,6 +1907,16 @@ def propagateStatus(self): subop.status = self.status subop.save(update_fields=["status"]) + # A parent operationplan can't be proposed when it's children already have a different status + if ( + self.type == "MO" + and self.owner + and self.status != "proposed" + and self.owner.status == "proposed" + ): + self.owner.status = "approved" + self.owner.save(update_fields=["status"]) + if self.status not in ("completed", "closed"): return