feat(vacation): 달력 공휴일 이름 · 잔여 연차를 옵션으로(참여자 표) · 연차 차감·12/31 소멸
- 쉬는 날 = 국경일·대체공휴일(project KR_HOLIDAYS, 2026~2030) + 휴가 설정 공휴일(덮어쓰기, 빨강 해제 = 근무일) — db.holiday_map 한 곳 (달력·날짜 팝업·일수 계산), 메인 달력은 날짜 아래 이름 + 그 주 막대 내림 - 잔여 연차 등록을 설정 → 옵션(관리자): 참여자 전원 아이콘·이름 미리 보여 주는 표, 사용·잔여·작년 참고, 한꺼번에 저장(save_balances) - 사용 연차 = 승인된 연차·오전반차·오후반차만(병가·경조·대체휴무·기타 제외), 해를 넘는 신청은 해마다 나눔, 연도별 12/31 소멸 안내 - 옵션 화면 카드가 화면 높이에 눌려 잘리던 것·입력 칸 최소 너비 수정 - 테스트: 실제 PG(holiday_map·used_days·save_balances), 실제 앱(옵션 표·저장 권한·설정 없음·달력 이름) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -204,14 +204,10 @@ def _build_calendar(
|
||||
range_start = weeks_dates[0][0]
|
||||
range_end = weeks_dates[-1][-1]
|
||||
|
||||
red_set = store.red_holiday_set(
|
||||
# 쉬는 날 = 국경일·대체공휴일 + 휴가 설정 공휴일(db.holiday_map) — 빨강 + 날짜 밑 이름(2026-10-27)
|
||||
holiday_names = store.holiday_map(
|
||||
date_from=range_start.isoformat(), date_to=range_end.isoformat()
|
||||
)
|
||||
holiday_names = {
|
||||
h["holiday_date"]: h["name"]
|
||||
for h in store.list_holidays()
|
||||
if h.get("is_red")
|
||||
}
|
||||
requests = store.list_overlapping(
|
||||
date_from=range_start.isoformat(), date_to=range_end.isoformat()
|
||||
)
|
||||
@@ -229,7 +225,7 @@ def _build_calendar(
|
||||
"is_selected": d.isoformat() == sel,
|
||||
"is_sunday": d.weekday() == 6,
|
||||
"is_saturday": d.weekday() == 5,
|
||||
"is_holiday": d.isoformat() in red_set,
|
||||
"is_holiday": d.isoformat() in holiday_names,
|
||||
"holiday_name": holiday_names.get(d.isoformat(), ""),
|
||||
}
|
||||
for d in week
|
||||
@@ -348,20 +344,15 @@ def _form_context(request: Request, user: dict[str, Any]) -> dict[str, Any]:
|
||||
|
||||
|
||||
def _red_holidays(request: Request) -> dict[str, str]:
|
||||
"""날짜 팝업 공휴일(빨강·이름) — 휴가 설정의 공휴일(is_red) 작년~내년. 일수 계산과 같은 표."""
|
||||
"""날짜 팝업 공휴일(빨강·이름) — 국경일·대체공휴일 + 휴가 설정 공휴일, 작년~내년. 일수 계산과 같은 표(db.holiday_map)."""
|
||||
st = _store(request)
|
||||
if st is None:
|
||||
return {}
|
||||
year = today_kst().year
|
||||
out: dict[str, str] = {}
|
||||
try:
|
||||
for y in (year - 1, year, year + 1):
|
||||
for h in st.list_holidays(year=y):
|
||||
if h.get("is_red", True):
|
||||
out[h["holiday_date"]] = h.get("name") or ""
|
||||
return st.holiday_map(date_from=f"{year - 1}-01-01", date_to=f"{year + 1}-12-31")
|
||||
except Exception: # noqa: BLE001 — 공휴일 표시가 신청 화면을 막지 않게
|
||||
return {}
|
||||
return out
|
||||
|
||||
|
||||
@router.get("/new", response_class=HTMLResponse)
|
||||
@@ -491,9 +482,6 @@ def settings_page(request: Request) -> HTMLResponse:
|
||||
year = int(request.query_params.get("year") or today.year)
|
||||
except ValueError:
|
||||
year = today.year
|
||||
balances = store.list_balances(year=year)
|
||||
for b in balances:
|
||||
b["used_days"] = store.used_days(user_email=b["user_email"], year=year)
|
||||
return render_template(
|
||||
request,
|
||||
"vacation/settings.html",
|
||||
@@ -503,10 +491,9 @@ def settings_page(request: Request) -> HTMLResponse:
|
||||
"is_approver": True,
|
||||
"nav_items": build_erp_nav(user, active="vacation"),
|
||||
"page_title": "휴가 — 설정",
|
||||
"page_subtitle": "공휴일 · 연차 잔여 관리",
|
||||
"page_subtitle": "공휴일 관리 (잔여 연차는 옵션)",
|
||||
"year": year,
|
||||
"holidays": store.list_holidays(year=year),
|
||||
"balances": balances,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -562,29 +549,67 @@ def holiday_delete(
|
||||
return RedirectResponse(url=f"/vacation/settings{suffix}", status_code=303)
|
||||
|
||||
|
||||
@router.post("/settings/balances")
|
||||
def balance_upsert(
|
||||
request: Request,
|
||||
user_email: str = Form(...),
|
||||
year: int = Form(...),
|
||||
total_days: float = Form(...),
|
||||
memo: str = Form(""),
|
||||
user: dict[str, Any] = Depends(_require_user),
|
||||
) -> RedirectResponse:
|
||||
@router.post("/options/balances")
|
||||
async def balances_save(request: Request) -> RedirectResponse:
|
||||
"""잔여 연차 한꺼번에(옵션, ERP 관리자) — 참여자 줄마다 email·total·memo. 연차 칸을 비운 줄은 그대로 둔다(새로 만들지 않음)."""
|
||||
from urllib.parse import urlencode # noqa: WPS433
|
||||
|
||||
from app.store import is_admin # noqa: WPS433
|
||||
|
||||
user = _require_user(request)
|
||||
if not is_admin(user):
|
||||
raise HTTPException(status_code=403, detail="관리자만 가능합니다.")
|
||||
raise HTTPException(status_code=403, detail="잔여 연차는 ERP 관리자만 등록할 수 있습니다.")
|
||||
store = _store(request)
|
||||
if store is None:
|
||||
raise HTTPException(status_code=503, detail="vacation_db 미설정")
|
||||
form = await request.form()
|
||||
try:
|
||||
store.upsert_balance(
|
||||
user_email=user_email, year=year, total_days=total_days, memo=memo
|
||||
)
|
||||
year = int(str(form.get("year") or ""))
|
||||
except ValueError:
|
||||
raise HTTPException(status_code=400, detail="연도가 올바르지 않습니다.")
|
||||
if not 2000 <= year <= 2100:
|
||||
raise HTTPException(status_code=400, detail="연도가 올바르지 않습니다.")
|
||||
emails, totals, memos = form.getlist("email"), form.getlist("total"), form.getlist("memo")
|
||||
if not (len(emails) == len(totals) == len(memos)):
|
||||
raise HTTPException(status_code=400, detail="잔여 연차 칸이 맞지 않습니다.")
|
||||
rows = []
|
||||
for email, total, memo in zip(emails, totals, memos):
|
||||
total = str(total).strip()
|
||||
if not total:
|
||||
continue
|
||||
try:
|
||||
rows.append({"user_email": email, "total_days": float(total), "memo": memo})
|
||||
except ValueError:
|
||||
raise HTTPException(status_code=400, detail=f"연차 일수가 숫자가 아닙니다: {email}")
|
||||
from starlette.concurrency import run_in_threadpool # noqa: WPS433 — 폼 배열을 읽으려 async, DB 는 동기라 스레드에서
|
||||
|
||||
try:
|
||||
n = await run_in_threadpool(store.save_balances, year=year, rows=rows)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc))
|
||||
return RedirectResponse(url=f"/vacation/settings?year={year}", status_code=303)
|
||||
return RedirectResponse(url="/vacation/options?" + urlencode({"year": year, "msg": f"{year}년 잔여 연차 {n}명을 저장했습니다."})
|
||||
+ "#balances", status_code=303)
|
||||
|
||||
|
||||
def _balance_rows(store: Any, year: int) -> list[dict[str, Any]]:
|
||||
"""옵션 잔여 연차 표 — 참여자(휴가 모듈 사용자) 전원 + 예전에 등록됐지만 지금 권한이 없는 사람.
|
||||
줄마다 그해 연차·사용(승인된 연차·반차)·잔여·메모, 아직 없으면 작년 연차를 참고로."""
|
||||
users = _vacation_users()
|
||||
this_year = {b["user_email"]: b for b in store.list_balances(year=year)}
|
||||
last_year = {b["user_email"]: b for b in store.list_balances(year=year - 1)}
|
||||
rows = []
|
||||
people = [(u["email"].lower(), u.get("name") or u["email"].split("@")[0], u.get("picture") or "", True) for u in users]
|
||||
known = {p[0] for p in people}
|
||||
people += [(e, e.split("@")[0], "", False) for e in sorted(this_year) if e not in known]
|
||||
for email, name, picture, active in people:
|
||||
bal = this_year.get(email)
|
||||
used = store.used_days(user_email=email, year=year)
|
||||
total = float(bal["total_days"]) if bal else None
|
||||
rows.append({"email": email, "name": name, "picture": picture, "active": active,
|
||||
"total": total, "used": used, "remaining": round(total - used, 2) if total is not None else None,
|
||||
"memo": (bal or {}).get("memo") or "",
|
||||
"last_total": float(last_year[email]["total_days"]) if email in last_year else None})
|
||||
return rows
|
||||
|
||||
|
||||
@router.get("/api/calendar")
|
||||
@@ -710,6 +735,11 @@ def options_page(request: Request) -> HTMLResponse:
|
||||
store, user = guard
|
||||
opts = _options(request)
|
||||
users = _vacation_users()
|
||||
today = today_kst()
|
||||
try:
|
||||
bal_year = int(request.query_params.get("year") or today.year)
|
||||
except ValueError:
|
||||
bal_year = today.year
|
||||
return render_template(
|
||||
request,
|
||||
"vacation/options.html",
|
||||
@@ -726,6 +756,8 @@ def options_page(request: Request) -> HTMLResponse:
|
||||
"effective_approvers": notify.approver_emails(opts, users),
|
||||
"gmail": _gmail_state(request, user),
|
||||
"msg": request.query_params.get("msg", ""),
|
||||
"bal_year": bal_year,
|
||||
"bal_rows": _balance_rows(store, bal_year) if is_admin(user) else [],
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user