Skip to content

Commit

Permalink
extra robustness when loading operationplan hierarchies
Browse files Browse the repository at this point in the history
  • Loading branch information
jdetaeye committed Feb 11, 2022
1 parent 07c9091 commit ca09ef5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion freppledb/input/commands/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down
10 changes: 10 additions & 0 deletions freppledb/input/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit ca09ef5

Please sign in to comment.