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:
2026-10-26 15:06:15 +09:00
parent 6a1c9f4434
commit 36d000eb17
15 changed files with 400 additions and 99 deletions
+79
View File
@@ -71,5 +71,84 @@ class VacationOptionsDBTests(unittest.TestCase):
self.st.save_options(approvers=[], notifiers=[], by="admin@test.local")
@unittest.skipUnless(ENABLED, "VACATION_TEST_DB_URL(localhost) 미설정")
class VacationHolidayBalanceDBTests(unittest.TestCase):
"""2026-10-27 — 쉬는 날 = 국경일·대체공휴일 + 설정 공휴일, 연차 = 승인된 연차·반차만·해마다 나눠 셈, 잔여 연차 한꺼번에 저장."""
@classmethod
def setUpClass(cls):
from app.modules.vacation.db import VacationDBStore
cls.st = VacationDBStore(DSN)
@classmethod
def tearDownClass(cls):
cls.st.close()
def test_holiday_map_national_plus_settings(self):
st = self.st
m = st.holiday_map(date_from="2027-10-01", date_to="2027-10-31") # 설정에 2027 없음 → 국경일 표
self.assertEqual(m, {"2027-10-03": "개천절", "2027-10-04": "개천절 대체", "2027-10-09": "한글날", "2027-10-11": "한글날 대체"})
self.assertEqual(st.holiday_map(date_from="2026-07-17", date_to="2026-07-17"), {"2026-07-17": "제헌절"}) # seed 에 없던 날
# 설정이 덮어쓴다 — 회사 휴일 추가, 이름 바꾸기, 빨강 해제 = 근무일
st.upsert_holiday(holiday_date="2027-10-08", name="창립기념일", kind="company", is_red=True)
st.upsert_holiday(holiday_date="2027-10-09", name="한글날(회사)", kind="public", is_red=True)
st.upsert_holiday(holiday_date="2027-10-11", name="한글날 대체", kind="substitute", is_red=False)
try:
m = st.holiday_map(date_from="2027-10-01", date_to="2027-10-31")
self.assertEqual(m, {"2027-10-03": "개천절", "2027-10-04": "개천절 대체", "2027-10-08": "창립기념일",
"2027-10-09": "한글날(회사)"})
self.assertEqual(st.red_holiday_set(date_from="2027-10-01", date_to="2027-10-31"), set(m))
finally:
for h in st.list_holidays(year=2027):
if h["holiday_date"] in ("2027-10-08", "2027-10-09", "2027-10-11"):
st.delete_holiday(holiday_id=h["id"])
def _approved(self, owner, vtype, start, end, sh="full", eh="full"):
req = self.st.create_request(owner=owner, owner_name="테스트", status="제출",
payload={"vacation_type": vtype, "start_date": start, "end_date": end,
"start_half": sh, "end_half": eh, "reason": ""})
self.st.approve(request_id=req["id"], approver_email="lee@test.local")
return req
def test_used_days_only_annual_types_and_split_by_year(self):
st = self.st
owner = f"bal-{uuid.uuid4().hex[:6]}@test.local"
made = [
self._approved(owner, "연차", "2026-11-02", "2026-11-03"), # 2
self._approved(owner, "오전반차", "2026-11-04", "2026-11-04"), # 0.5
self._approved(owner, "병가", "2026-11-05", "2026-11-06"), # 차감 안 함
self._approved(owner, "경조", "2026-11-09", "2026-11-09"), # 차감 안 함
self._approved(owner, "연차", "2026-12-30", "2027-01-04"), # 12/30·31 = 2, 1/4 = 1 (1/1 신정·주말 뺌)
]
st.create_request(owner=owner, owner_name="테스트", status="제출", # 제출(승인 전)은 차감 안 함
payload={"vacation_type": "연차", "start_date": "2026-11-10", "end_date": "2026-11-10",
"start_half": "full", "end_half": "full", "reason": ""})
try:
self.assertEqual(st.used_days(user_email=owner, year=2026), 4.5)
self.assertEqual(st.used_days(user_email=owner, year=2027), 1.0)
st.save_balances(year=2026, rows=[{"user_email": owner, "total_days": 15, "memo": "입사 2020"}])
s26 = st.balance_summary(user_email=owner, year=2026)
self.assertEqual((s26["total_days"], s26["used_days"], s26["remaining_days"]), (15.0, 4.5, 10.5))
s27 = st.balance_summary(user_email=owner, year=2027) # 다음 해로 넘어가지 않음(등록 전 = 0)
self.assertEqual((s27["total_days"], s27["remaining_days"]), (0.0, -1.0))
finally:
for r in st.list_for(owner):
st.hard_delete(request_id=r["id"], user_email=owner, is_admin=True)
def test_save_balances_validates_all_or_nothing(self):
st = self.st
a, b = f"a-{uuid.uuid4().hex[:6]}@test.local", f"b-{uuid.uuid4().hex[:6]}@test.local"
with self.assertRaises(ValueError):
st.save_balances(year=2031, rows=[{"user_email": a, "total_days": 15}, {"user_email": b, "total_days": 15.3}])
self.assertIsNone(st.get_balance(user_email=a, year=2031)) # 한 줄이라도 틀리면 전부 저장 안 함
self.assertEqual(st.save_balances(year=2031, rows=[{"user_email": a.upper(), "total_days": 15.5, "memo": " x "},
{"user_email": b, "total_days": 0}]), 2)
self.assertEqual((st.get_balance(user_email=a, year=2031)["total_days"], st.get_balance(user_email=a, year=2031)["memo"]),
(15.5, "x"))
st.save_balances(year=2031, rows=[{"user_email": a, "total_days": 20, "memo": ""}]) # 덮어쓰기
self.assertEqual(st.get_balance(user_email=a, year=2031)["total_days"], 20.0)
if __name__ == "__main__":
unittest.main()
+78 -3
View File
@@ -197,9 +197,12 @@ class Store:
self.req.update(status="반려", reject_reason=reason); return dict(self.req)
def list_mail_log(self, request_id):
return []
def list_holidays(self, year=None):
return [{"holiday_date": f"{year}-10-09", "name": "한글날", "is_red": True},
{"holiday_date": f"{year}-05-01", "name": "근로자의날(회사)", "is_red": False}]
def list_balances(self, year):
return []
def used_days(self, user_email, year):
return 0.0
def holiday_map(self, date_from, date_to): # 국경일 + 설정 공휴일(db.holiday_map) — 해마다 한글날만
return {f"{y}-10-09": "한글날" for y in range(int(date_from[:4]), int(date_to[:4]) + 1)}
st = Store()
@@ -330,5 +333,77 @@ run(body)
self.assertIn("OK", res.stdout)
def test_balances_in_options_settings_and_calendar_holidays(self):
"""2026-10-27 — 잔여 연차는 옵션(관리자, 참여자 전원 아이콘·이름 미리), 설정엔 없음, 달력 공휴일 이름."""
res = _run('''
lee["picture"] = "https://img.test/lee.png"
saved = {}
class Store2(Store):
def list_balances(self, year):
return [{"user_email": "lee@test.local", "year": year, "total_days": 15, "memo": "입사 2020"},
{"user_email": "gone@test.local", "year": year, "total_days": 10, "memo": ""}] if year == 2026 else \
[{"user_email": "kim@test.local", "year": year, "total_days": 12, "memo": ""}]
def used_days(self, user_email, year):
return {"lee@test.local": 4.5}.get(user_email, 0.0)
def save_balances(self, year, rows):
saved.update(year=year, rows=rows); return len(rows)
def list_holidays(self, year=None):
return []
def holiday_map(self, date_from, date_to):
return {d: n for d, n in {"2026-10-03": "개천절", "2026-10-05": "개천절 대체", "2026-10-09": "한글날"}.items()
if date_from <= d <= date_to}
def list_overlapping(self, date_from, date_to):
return []
def balance_summary(self, user_email, year):
return {"year": year, "total_days": 15.0, "used_days": 4.5, "remaining_days": 10.5, "memo": ""}
def list_pending(self):
return []
st2 = Store2()
def body(c):
main.app.state.vacation_store = st2
who["u"] = admin
r = c.get("/vacation/options?year=2026")
assert r.status_code == 200, r.status_code
t = r.text
assert 'id="balances"' in t and "2026년 · 참여자 4명" in t, t[t.find("잔여 연차"):t.find("잔여 연차") + 200]
for u in users: # 참여자 전원 미리(이름 + 이메일 + 줄마다 칸)
assert f'name="email" value="{u["email"]}"' in t, u["email"]
assert 'src="https://img.test/lee.png"' in t # 사진 있으면 사진, 없으면 첫 글자
assert '<span class="vac-opt-face is-ini">k</span>' in t
assert "gone@test.local · 휴가 권한 없음" in t # 예전에 등록된 사람도 보여 줌
i = t.index('name="email" value="lee@test.local"')
row = t[i:i + 900]
assert 'value="15"' in row and ">4.5<" in row and ">10.5<" in row and 'value="입사 2020"' in row, row
j = t.index('name="email" value="kim@test.local"')
assert 'placeholder="12"' in t[j:j + 600], t[j:j + 600] # 올해 없음 → 작년 연차를 회색 참고
assert "2026.12.31 에 소멸" in t and "승인되면" in t
# 저장 — 빈 칸은 건너뜀, 연도·이메일·메모 그대로
r = c.post("/vacation/options/balances", data={"year": "2026", "email": ["lee@test.local", "kim@test.local", "chip@test.local"],
"total": ["16", "", "15.5"], "memo": ["a", "b", "c"]})
assert r.status_code == 303 and "year=2026" in r.headers["location"], r.status_code
assert saved == {"year": 2026, "rows": [{"user_email": "lee@test.local", "total_days": 16.0, "memo": "a"},
{"user_email": "chip@test.local", "total_days": 15.5, "memo": "c"}]}, saved
assert c.post("/vacation/options/balances", data={"year": "2026", "email": ["lee@test.local"], "total": ["x"], "memo": [""]}).status_code == 400
# 관리자 아님 — 표 안 보임, 저장 403
who["u"] = kim
assert 'id="balances"' not in c.get("/vacation/options").text
assert c.post("/vacation/options/balances", data={"year": "2026", "email": ["kim@test.local"], "total": ["30"], "memo": [""]}).status_code == 403
# 설정 — 잔여 연차 입력 없음(옵션 안내)
who["u"] = admin
t = c.get("/vacation/settings?year=2026").text
assert "/vacation/settings/balances" not in t and "/vacation/options?year=2026#balances" in t
assert c.post("/vacation/settings/balances", data={"user_email": "a@test.local", "year": "2026", "total_days": "1"}).status_code in (404, 405)
# 달력 — 국경일·대체공휴일 이름이 날짜 아래, 그 주는 has-hol, 잔여 옆 12/31 소멸
t = c.get("/vacation/?year=2026&month=10").text
assert '<span class="vac-hol-name">개천절</span>' in t and '<span class="vac-hol-name">개천절 대체</span>' in t
assert '<span class="vac-hol-name">한글날</span>' in t and t.count("has-hol") == 2, t.count("has-hol")
assert "2026.12.31 소멸" in t
print("OK")
run(body)
''')
self.assertEqual(res.returncode, 0, res.stdout + res.stderr)
self.assertIn("OK", res.stdout)
if __name__ == "__main__":
unittest.main()