기능 개선 — 조치 시작/완료 시각 직접 입력

정비사가 조치 입력 시 시작·완료 시각을 직접 수정할 수 있도록 변경.
현장 처리 후 나중에 입력하는 경우 실제 조치 시간을 정확히 기록 가능.

- repair.html: 자동기록 안내문구 → datetime-local 입력 필드 2개로 교체
  (페이지 로드 시 현재 시각 기본 설정, 편집 모드에서 기존 값 복원)
- repairs.py: POST/PUT 엔드포인트에 started_at_input / completed_at_input
  Form 파라미터 추가, 미입력 시 datetime.now() 유지

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
byun
2026-06-01 15:30:33 +09:00
parent 124ad0d165
commit d429ed627d
2 changed files with 40 additions and 6 deletions

View File

@@ -125,12 +125,21 @@ def get_repair(repair_id: int, db: Session = Depends(get_db),
return _fmt_repair(repair)
def _parse_dt(s: Optional[str]) -> Optional[datetime]:
if not s: return None
try:
return datetime.fromisoformat(s)
except Exception:
return None
@router.post("")
async def create_repair(
report_ids: str = Form(...),
repair_types: str = Form(...),
description: str = Form(...),
result_status: str = Form("done"),
started_at_input: Optional[str] = Form(None),
completed_at_input: Optional[str] = Form(None),
mechanic_lat: Optional[float] = Form(None),
mechanic_lng: Optional[float] = Form(None),
photos_before: List[UploadFile] = File(default=[]),
@@ -138,13 +147,14 @@ async def create_repair(
db: Session = Depends(get_db),
current_user: models.User = Depends(require_mechanic)
):
now = datetime.now()
rids = json.loads(report_ids)
repair = models.Repair(
mechanic_id=current_user.id,
repair_types=json.loads(repair_types),
description=description,
started_at=datetime.now(),
completed_at=datetime.now(),
started_at=_parse_dt(started_at_input) or now,
completed_at=_parse_dt(completed_at_input) or now,
result_status=result_status,
mechanic_lat=mechanic_lat,
mechanic_lng=mechanic_lng,
@@ -175,6 +185,8 @@ async def update_repair(
repair_types: str = Form(...),
description: str = Form(...),
result_status: str = Form("done"),
started_at_input: Optional[str] = Form(None),
completed_at_input: Optional[str] = Form(None),
mechanic_lat: Optional[float] = Form(None),
mechanic_lng: Optional[float] = Form(None),
photos_before: List[UploadFile] = File(default=[]),
@@ -192,7 +204,9 @@ async def update_repair(
repair.repair_types = json.loads(repair_types)
repair.description = description
repair.result_status = result_status
repair.completed_at = datetime.now()
if started_at_input:
repair.started_at = _parse_dt(started_at_input) or repair.started_at
repair.completed_at = _parse_dt(completed_at_input) or datetime.now()
if mechanic_lat is not None: repair.mechanic_lat = mechanic_lat
if mechanic_lng is not None: repair.mechanic_lng = mechanic_lng