Fix: replace r.employee_name with r.submitter_email in accident references
After renaming Accident.employee_name -> submitter_email, four more references to r.employee_name / r.employee_id slipped through and caused 500 Internal Server Errors: 1. /api/attendance/records to_dict - was using r.submitter_email (wrong table!) (regression from earlier batch sed that hit too many matches) 2. /api/accident/dashboard/stats - emp = r.employee_name 3. /api/accident/export/excel to_dict 4. /api/accident/export/excel overview + detail sheet Fix: explicit context-aware replacements (only Accident-related sections) Verification: - /api/attendance/records: 200 OK (returns 110 records) - /api/accident/records: 200 OK (returns 342 records) - /api/accident/dashboard/summary: 200 OK - /api/accident/dashboard/stats: 200 OK (was 500) - /api/accident/export/excel: 200 OK + valid xlsx (78KB)
This commit is contained in:
+6
-6
@@ -1207,7 +1207,7 @@ async def attendance_records(
|
||||
return {
|
||||
"id": r.id,
|
||||
"staff": r.employee_name,
|
||||
"employee_name": r.submitter_email,
|
||||
"employee_name": r.employee_name,
|
||||
"company": r.company,
|
||||
"department": r.department,
|
||||
"date": r.date.isoformat() if r.date else None,
|
||||
@@ -2246,7 +2246,7 @@ async def accident_dashboard_stats(
|
||||
by_location[loc]["count"] += 1
|
||||
by_location[loc]["severity_sum"] += sev_weight
|
||||
|
||||
emp = r.employee_name or "未分類"
|
||||
emp = r.submitter_email or "未分類"
|
||||
by_employee.setdefault(emp, {"name": emp, "count": 0, "severity_sum": 0, "avg_severity": 0})
|
||||
by_employee[emp]["count"] += 1
|
||||
by_employee[emp]["severity_sum"] += sev_weight
|
||||
@@ -2949,8 +2949,8 @@ async def accident_export_excel(
|
||||
"date": r.date.isoformat() if r.date else "",
|
||||
"time": r.time or "",
|
||||
"location": r.location or "",
|
||||
"employee_name": r.employee_name or "",
|
||||
"employee_id": r.employee_id or "",
|
||||
"employee_name": r.submitter_email or "",
|
||||
"employee_id": r.injured_person_id or "",
|
||||
"department": r.department or "",
|
||||
"description": r.description or "",
|
||||
"severity": str(r.severity or ""),
|
||||
@@ -3319,7 +3319,7 @@ async def export_excel(
|
||||
overview.write(f"G{nav_start_row + 1}", "→ 查明細", header_fmt_ov)
|
||||
for idx, r in enumerate(rows):
|
||||
row_n = nav_start_row + 2 + idx
|
||||
overview.write(row_n, 1, r.employee_name or "", cell_fmt_ov)
|
||||
overview.write(row_n, 1, r.submitter_email or "", cell_fmt_ov)
|
||||
overview.write(row_n, 2, r.department or "", cell_fmt_ov)
|
||||
overview.write(row_n, 3, r.date.isoformat() if r.date else "", cell_fmt_ov)
|
||||
overview.write(row_n, 4, r.status_text or "", cell_fmt_ov)
|
||||
@@ -3378,7 +3378,7 @@ async def export_excel(
|
||||
for r_idx, r in enumerate(rows, start=1):
|
||||
sc = (r.status_code or "").lower()
|
||||
fmt = status_fmts.get(sc, status_fmts["default"])
|
||||
ws.write(r_idx, 0, r.employee_name or "")
|
||||
ws.write(r_idx, 0, r.submitter_email or "")
|
||||
ws.write(r_idx, 1, r.company or "")
|
||||
ws.write(r_idx, 2, r.department or "")
|
||||
ws.write(r_idx, 3, r.date.isoformat() if r.date else "")
|
||||
|
||||
Reference in New Issue
Block a user