Improve downtime qualification visibility

This commit is contained in:
masterdev
2026-06-17 02:21:47 +01:00
parent c7c11d5060
commit 4e6286b1a3
4 changed files with 138 additions and 28 deletions

View File

@@ -440,6 +440,9 @@ def get_machine_cycles(machine_id: int, limit: int = Query(default=100, le=500),
@app.get("/api/machines/{machine_id}/downtimes")
def get_machine_downtimes(machine_id: int, limit: int = Query(default=100, le=500), db: Session = Depends(get_db)) -> list[dict]:
machine = db.get(Machine, machine_id)
if machine is None:
raise HTTPException(status_code=404, detail="Machine not found")
rows = db.execute(
select(Downtime).where(Downtime.machine_id == machine_id).order_by(Downtime.start_time.desc()).limit(limit)
).scalars()
@@ -449,6 +452,8 @@ def get_machine_downtimes(machine_id: int, limit: int = Query(default=100, le=50
"start_time": row.start_time.isoformat(),
"end_time": row.end_time.isoformat() if row.end_time else None,
"duration_sec": row.duration_sec,
"machine_id": row.machine_id,
"machine_code": machine.code,
"reason_code": row.reason_code,
"comment": row.comment,
"auto_detected": row.auto_detected,
@@ -549,19 +554,27 @@ def close_production_order(order_id: int, db: Session = Depends(get_db)) -> dict
@app.get("/api/downtimes/open")
def get_open_downtimes(db: Session = Depends(get_db)) -> list[dict]:
rows = db.execute(select(Downtime).where(Downtime.end_time.is_(None)).order_by(Downtime.start_time.asc())).scalars()
return [
{
"id": row.id,
"machine_id": row.machine_id,
"production_order_id": row.production_order_id,
"start_time": row.start_time.isoformat(),
"reason_code": row.reason_code,
"comment": row.comment,
"auto_detected": row.auto_detected,
"qualified_by": row.qualified_by,
}
for row in rows
]
result = []
for row in rows:
machine = db.get(Machine, row.machine_id)
order = db.get(ProductionOrder, row.production_order_id) if row.production_order_id else None
result.append(
{
"id": row.id,
"machine_id": row.machine_id,
"machine_code": machine.code if machine else None,
"production_order_id": row.production_order_id,
"order_number": order.order_number if order else None,
"start_time": row.start_time.isoformat(),
"end_time": None,
"duration_sec": row.duration_sec,
"reason_code": row.reason_code,
"comment": row.comment,
"auto_detected": row.auto_detected,
"qualified_by": row.qualified_by,
}
)
return result
@app.post("/api/downtimes/{downtime_id}/qualify")