From 71114e70c8d5ef23adad29a4173ddef43d497218 Mon Sep 17 00:00:00 2001 From: David Whittaker <84562015+whitdog47@users.noreply.github.com> Date: Fri, 13 Dec 2024 17:23:55 -0800 Subject: [PATCH] fix(case): close escalated case when associated incident is closed (#5618) --- src/dispatch/incident/flows.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/dispatch/incident/flows.py b/src/dispatch/incident/flows.py index 3dd476d5ae50..9288ec35acf5 100644 --- a/src/dispatch/incident/flows.py +++ b/src/dispatch/incident/flows.py @@ -4,7 +4,9 @@ from sqlalchemy.orm import Session +from dispatch.case import flows as case_flows from dispatch.case import service as case_service +from dispatch.case.enums import CaseResolutionReason, CaseStatus from dispatch.case.models import Case from dispatch.conference import flows as conference_flows from dispatch.conversation import flows as conversation_flows @@ -544,6 +546,19 @@ def incident_closed_status_flow(incident: Incident, db_session=None): document=document, db_session=db_session ) + for case in incident.cases: + try: + case.resolution = ( + f"Closed as part of incident {incident.name}. See incident for more details." + ) + case.resolution_reason = CaseResolutionReason.escalated + case.status = CaseStatus.closed + case_flows.case_closed_status_flow(case=case, db_session=db_session) + except Exception as e: + log.exception( + f"Failed to close case {case.name} while closing incident {incident.name}. Error: {str(e)}" + ) + # we send a direct message to the incident commander asking to review # the incident's information and to tag the incident if appropriate send_incident_closed_information_review_reminder(incident, db_session)