Show unqualified downtime for qualification
This commit is contained in:
@@ -554,27 +554,34 @@ 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()
|
||||
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
|
||||
return [_serialize_downtime_for_qualification(db, row) for row in rows]
|
||||
|
||||
|
||||
@app.get("/api/downtimes/unqualified")
|
||||
def get_unqualified_downtimes(db: Session = Depends(get_db)) -> list[dict]:
|
||||
rows = db.execute(
|
||||
select(Downtime).where(Downtime.reason_code.is_(None)).order_by(Downtime.start_time.desc()).limit(200)
|
||||
).scalars()
|
||||
return [_serialize_downtime_for_qualification(db, row) for row in rows]
|
||||
|
||||
|
||||
def _serialize_downtime_for_qualification(db: Session, row: Downtime) -> dict:
|
||||
machine = db.get(Machine, row.machine_id)
|
||||
order = db.get(ProductionOrder, row.production_order_id) if row.production_order_id else None
|
||||
return {
|
||||
"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": row.end_time.isoformat() if row.end_time else None,
|
||||
"duration_sec": row.duration_sec,
|
||||
"reason_code": row.reason_code,
|
||||
"comment": row.comment,
|
||||
"auto_detected": row.auto_detected,
|
||||
"qualified_by": row.qualified_by,
|
||||
}
|
||||
|
||||
|
||||
@app.post("/api/downtimes/{downtime_id}/qualify")
|
||||
|
||||
Reference in New Issue
Block a user