feat: enhance project management by canceling pending actions for archived and on_hold projects
This commit is contained in:
@@ -342,6 +342,14 @@ async def update_project(
|
||||
project.description = data["description"]
|
||||
if "status" in data:
|
||||
project.status = data["status"]
|
||||
# Cancel pending scheduled actions when archiving
|
||||
if data["status"] == "archived":
|
||||
db.query(ScheduledAction).filter(
|
||||
and_(
|
||||
ScheduledAction.project_id == project_id,
|
||||
ScheduledAction.execution_status == "pending",
|
||||
)
|
||||
).update({"execution_status": "cancelled"})
|
||||
if "client_name" in data:
|
||||
project.client_name = data["client_name"]
|
||||
if "site_address" in data:
|
||||
@@ -374,6 +382,14 @@ async def delete_project(project_id: str, db: Session = Depends(get_db)):
|
||||
project.deleted_at = datetime.utcnow()
|
||||
project.updated_at = datetime.utcnow()
|
||||
|
||||
# Cancel all pending scheduled actions
|
||||
db.query(ScheduledAction).filter(
|
||||
and_(
|
||||
ScheduledAction.project_id == project_id,
|
||||
ScheduledAction.execution_status == "pending",
|
||||
)
|
||||
).update({"execution_status": "cancelled"})
|
||||
|
||||
db.commit()
|
||||
|
||||
return {"success": True, "message": "Project deleted. Data will be permanently removed after 60 days."}
|
||||
@@ -414,6 +430,15 @@ async def hold_project(project_id: str, db: Session = Depends(get_db)):
|
||||
|
||||
project.status = "on_hold"
|
||||
project.updated_at = datetime.utcnow()
|
||||
|
||||
# Cancel pending scheduled actions so they don't appear in dashboards or fire
|
||||
db.query(ScheduledAction).filter(
|
||||
and_(
|
||||
ScheduledAction.project_id == project_id,
|
||||
ScheduledAction.execution_status == "pending",
|
||||
)
|
||||
).update({"execution_status": "cancelled"})
|
||||
|
||||
db.commit()
|
||||
|
||||
return {"success": True, "message": "Project put on hold."}
|
||||
@@ -672,10 +697,14 @@ async def get_project_schedules(
|
||||
"result": result_data,
|
||||
})
|
||||
|
||||
project = db.query(Project).filter_by(id=project_id).first()
|
||||
project_status = project.status if project else "active"
|
||||
|
||||
return templates.TemplateResponse("partials/projects/schedule_list.html", {
|
||||
"request": request,
|
||||
"project_id": project_id,
|
||||
"schedules_by_date": schedules_by_date,
|
||||
"project_status": project_status,
|
||||
})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user