feat(vacation): 입사일(이름 옆 날짜) · 근로기준법 연차 자동 · 2026 시스템 전 사용 연차
- 잔여 연차 표 이름 옆 입사일 날짜 버튼(ErpDatePop.enhance, « » 1년씩) → vacation_employees(마이그레이션 002) - 법정 연차 = 근로기준법 제60조 입사일 기준(1년 미만 월 1일·최대 11, 근속 n년 min(25, 15+(n-1)//2)), 그해 생기는 날을 모음 (store.legal_annual_leave, 화면도 같은 계산으로 바로 표시) — 연차 칸을 비우면 법정, 숫자면 직접 입력(total_days NULL 허용) - 2026(도입 해)만 "시스템 전 사용"(prior_used) 칸 — 잔여 = 총 − 시스템 전 사용 − 승인된 연차·반차(db.balance_summary 한 곳) - 테스트: 법정 연차 규칙, 실제 PG(입사일·법정·직접·시스템 전·검증), 실제 앱 저장, 브라우저(입사일 버튼·바로 계산·전송) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -30,6 +30,21 @@ def main() -> None:
|
||||
html = env.get_template("vacation/form.html").render(**ctx)
|
||||
with open(os.path.join(OUT_DIR, "vac_form.html"), "w", encoding="utf-8") as f:
|
||||
f.write(html)
|
||||
# 옵션 — 잔여 연차 표(2026, 입사일·법정 연차·시스템 전 사용) → tests/js/.out/vac_options.html
|
||||
row = {"active": True, "picture": "", "service_years": 0, "legal": None, "legal_tip": "", "total": None, "effective_total": 0,
|
||||
"prior": 0.0, "used": 0.0, "remaining": None, "memo": "", "last_total": None, "hire_date": ""}
|
||||
octx = {**ctx, "page_title": "휴가 — 옵션", "is_admin": True, "can_edit": True, "msg": "",
|
||||
"options": {"approvers": [], "notifiers": [], "ready": True, "updated_by": "", "updated_at": ""},
|
||||
"candidates": [], "effective_approvers": [], "gmail": {"available": False, "connected": False, "smtp": True},
|
||||
"bal_year": 2026, "bal_prior_year": True, "hire_ready": True,
|
||||
"bal_rows": [
|
||||
{**row, "email": "lee@test.local", "name": "이팀장", "hire_date": "2020-03-02", "service_years": 6, "legal": 17.0,
|
||||
"legal_tip": "03-02 근속 6년 17일", "used": 4.5, "remaining": 12.5},
|
||||
{**row, "email": "kim@test.local", "name": "김철수", "used": 1.0},
|
||||
]}
|
||||
html = env.get_template("vacation/options.html").render(**octx)
|
||||
with open(os.path.join(OUT_DIR, "vac_options.html"), "w", encoding="utf-8") as f:
|
||||
f.write(html)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
// 휴가 옵션 잔여 연차 — 이름 옆 입사일 날짜 버튼 · 근로기준법 연차 바로 계산 · 시스템 전 사용(2026-10-27) — 실제 브라우저(Chromium).
|
||||
// python tests/js/render_vacation.py
|
||||
// NODE_PATH=<playwright 경로> PJ_TEST_BROWSER=<Chrome 경로> node tests/js/vacation_balances.browser.test.js
|
||||
const fs = require("fs"), path = require("path");
|
||||
const { chromium } = require("playwright");
|
||||
const ROOT = path.join(__dirname, "..", "..");
|
||||
const fails = [];
|
||||
function check(name, cond, extra) {
|
||||
if (cond) console.log("PASS " + name);
|
||||
else { console.log("FAIL " + name + (extra !== undefined ? " → " + JSON.stringify(extra) : "")); fails.push(name); }
|
||||
}
|
||||
|
||||
(async function () {
|
||||
const exe = process.env.PJ_TEST_BROWSER;
|
||||
const browser = await chromium.launch(exe ? { executablePath: exe } : {});
|
||||
const posts = [];
|
||||
try {
|
||||
const p = await (await browser.newContext({ viewport: { width: 1400, height: 900 } })).newPage();
|
||||
await p.route("**/*", function (r) {
|
||||
const req = r.request(), url = new URL(req.url()).pathname;
|
||||
if (url.startsWith("/static/")) {
|
||||
const f = path.join(ROOT, "app", url);
|
||||
if (!fs.existsSync(f)) return r.fulfill({ status: 404, body: "" });
|
||||
const type = f.endsWith(".css") ? "text/css" : f.endsWith(".js") ? "application/javascript" : "font/woff2";
|
||||
return r.fulfill({ status: 200, contentType: type, body: fs.readFileSync(f) });
|
||||
}
|
||||
if (req.method() === "POST") { posts.push(req.postData()); return r.fulfill({ status: 200, contentType: "text/html", body: "ok" }); }
|
||||
r.fulfill({ status: 200, contentType: "text/html; charset=utf-8", body: fs.readFileSync(path.join(__dirname, ".out", "vac_options.html"), "utf8") });
|
||||
});
|
||||
await p.goto("http://erp.test/vacation/options");
|
||||
await p.waitForTimeout(200);
|
||||
const rowState = function (email) {
|
||||
return p.evaluate(function (email) {
|
||||
const tr = document.querySelector('input[name="email"][value="' + email + '"]').closest("tr");
|
||||
const btn = tr.querySelector(".vac-hire-btn");
|
||||
return { btn: btn && btn.textContent.replace("calendar_month", "").trim(), nextToName: !!btn && btn.parentElement === tr.querySelector(".vac-bal-person"),
|
||||
hire: tr.querySelector('input[name="hire"]').value, hireShown: getComputedStyle(tr.querySelector('input[name="hire"]')).display !== "none",
|
||||
years: tr.querySelector(".vac-bal-years-cell").textContent.trim(), legal: tr.querySelector(".vac-bal-legal").textContent.trim(),
|
||||
placeholder: tr.querySelector('input[name="total"]').placeholder, remain: tr.querySelector(".vac-bal-remain").textContent.trim(),
|
||||
minus: tr.querySelector(".vac-bal-remain").classList.contains("is-minus") };
|
||||
}, email);
|
||||
};
|
||||
const lee = await rowState("lee@test.local");
|
||||
check("입사일 = 이름 옆 날짜 버튼(연도까지), 숨긴 input 이 값", lee.nextToName && !lee.hireShown && lee.btn === "2020.03.02(월)" &&
|
||||
lee.hire === "2020-03-02" && lee.legal === "17" && lee.remain === "12.5", lee);
|
||||
const kim0 = await rowState("kim@test.local");
|
||||
check("입사일 없음 = '입사일' 버튼, 근속·법정 —", kim0.btn === "입사일" && kim0.years === "—" && kim0.legal === "—" && kim0.remain === "—", kim0);
|
||||
// 김철수 입사일 2025-03-01 직접 입력(Enter) → 근속 1년 · 법정 17(1/1·2/1 월 1일 + 3/1 15일) · 잔여 17 − 1(사용)
|
||||
await p.click('tr:has(input[value="kim@test.local"]) .vac-hire-btn');
|
||||
const pop = await p.evaluate(function () {
|
||||
const el = document.querySelector(".pj-datepop");
|
||||
return el && { navs: el.querySelectorAll(".pj-dp-navbtn").length, field: el.querySelector(".pj-dp-field").placeholder,
|
||||
clear: !!el.querySelector(".pj-dp-clear") };
|
||||
});
|
||||
check("입사일 팝업 = 날짜 하나, « ‹ › » (1년씩 이동), 지우기", !!pop && pop.navs === 4 && pop.field === "입사일" && pop.clear, pop);
|
||||
await p.fill(".pj-dp-field", "2025-03-01");
|
||||
await p.press(".pj-dp-field", "Enter");
|
||||
const kim1 = await rowState("kim@test.local");
|
||||
check("입사일 고르면 근속·법정 연차·잔여 바로 계산(근로기준법)", kim1.btn === "2025.03.01(토)" && kim1.hire === "2025-03-01" &&
|
||||
kim1.years === "1년" && kim1.legal === "17" && kim1.placeholder === "17" && kim1.remain === "16", kim1);
|
||||
// 시스템 전 사용 3.5 → 잔여 12.5, 연차 직접 10 → 10 − 3.5 − 1 = 5.5, 20 넘게 쓰면 빨강
|
||||
await p.fill('tr:has(input[value="kim@test.local"]) input[name="prior"]', "3.5");
|
||||
check("시스템 전 사용 → 잔여에서 뺌", (await rowState("kim@test.local")).remain === "12.5");
|
||||
await p.fill('tr:has(input[value="kim@test.local"]) input[name="total"]', "10");
|
||||
check("연차 직접 입력이 법정보다 먼저", (await rowState("kim@test.local")).remain === "5.5");
|
||||
await p.fill('tr:has(input[value="kim@test.local"]) input[name="prior"]', "12");
|
||||
const kim2 = await rowState("kim@test.local");
|
||||
check("모자라면 잔여 빨강", kim2.remain === "-3" && kim2.minus, kim2);
|
||||
// 1년씩 이동 버튼 — 2025년 3월 → « → 2024년 3월
|
||||
await p.click('tr:has(input[value="lee@test.local"]) .vac-hire-btn');
|
||||
const t0 = await p.textContent(".pj-dp-title");
|
||||
await p.click('.pj-dp-navbtn[data-nav="-12"]');
|
||||
const t1 = await p.textContent(".pj-dp-title");
|
||||
check("« = 1년 전 달력", t0 === "2020년 3월" && t1 === "2019년 3월", [t0, t1]);
|
||||
await p.keyboard.press("Escape");
|
||||
// 저장 — 줄마다 email·hire·total·prior·memo
|
||||
await p.click('button[type="submit"]:has-text("잔여 연차 저장")');
|
||||
await p.waitForTimeout(200);
|
||||
const body = decodeURIComponent((posts[0] || "").replace(/\+/g, " "));
|
||||
check("저장 → 입사일·연차·시스템 전 사용이 줄마다 전송", /email=kim@test.local/.test(body) && /hire=2025-03-01/.test(body) &&
|
||||
/hire=2020-03-02/.test(body) && /total=10/.test(body) && /prior=12/.test(body) && (body.match(/hire=/g) || []).length === 2, body);
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
if (fails.length) { console.log("\n" + fails.length + " FAILED"); process.exit(1); }
|
||||
console.log("\nALL PASS");
|
||||
})().catch(function (e) { console.error(e); process.exit(1); });
|
||||
@@ -147,5 +147,72 @@ class VacationHolidayBalanceDBTests(unittest.TestCase):
|
||||
self.assertEqual(st.get_balance(user_email=a, year=2031)["total_days"], 20.0)
|
||||
|
||||
|
||||
class LegalAnnualLeaveTests(unittest.TestCase):
|
||||
"""근로기준법 제60조 — 입사일 기준으로 생기는 연차를 그해에 모은다(2026-10-27, DB 없음)."""
|
||||
|
||||
def test_rules(self):
|
||||
from datetime import date
|
||||
|
||||
from app.modules.vacation.store import add_months, legal_annual_leave as L
|
||||
|
||||
self.assertEqual(add_months(date(2026, 1, 31), 1), date(2026, 2, 28))
|
||||
self.assertEqual(add_months(date(2024, 2, 29), 12), date(2025, 2, 28))
|
||||
# 입사 1년 미만 = 1개월마다 1일, 입사일이 돌아오면 15일 — 2025-03-01 입사
|
||||
self.assertEqual(L(date(2025, 3, 1), 2025)["days"], 9.0) # 4/1 ~ 12/1
|
||||
r = L(date(2025, 3, 1), 2026)
|
||||
self.assertEqual((r["days"], r["service_years"]), (17.0, 1)) # 1/1·2/1(월 1일) + 3/1 근속 1년 15일
|
||||
self.assertEqual([i["date"] for i in r["items"]], ["2026-01-01", "2026-02-01", "2026-03-01"])
|
||||
self.assertEqual(L(date(2025, 3, 1), 2027)["days"], 15.0) # 근속 2년 = 15일
|
||||
# 3년 이상 = 최초 1년을 넘는 근속 2년마다 1일, 최대 25일
|
||||
self.assertEqual(L(date(2023, 5, 10), 2026)["days"], 16.0) # 근속 3년
|
||||
self.assertEqual(L(date(2020, 3, 2), 2026)["days"], 17.0) # 근속 6년 = 15 + 2
|
||||
self.assertEqual(L(date(2001, 1, 1), 2026)["days"], 25.0) # 근속 25년 → 한도 25
|
||||
self.assertEqual(L(date(2027, 1, 2), 2026)["days"], 0.0) # 아직 입사 전
|
||||
self.assertEqual(L(None, 2026)["days"], 0.0)
|
||||
|
||||
|
||||
@unittest.skipUnless(ENABLED, "VACATION_TEST_DB_URL(localhost) 미설정")
|
||||
class VacationHireDBTests(unittest.TestCase):
|
||||
"""002 — 입사일·시스템 전 사용·연차 비우면 법정(실제 PostgreSQL, 002 적용 DB)."""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
from app.modules.vacation.db import VacationDBStore
|
||||
|
||||
cls.st = VacationDBStore(DSN)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
cls.st.close()
|
||||
|
||||
def test_hire_legal_manual_prior(self):
|
||||
st = self.st
|
||||
self.assertTrue(st.hire_ready())
|
||||
a, b = f"h-{uuid.uuid4().hex[:6]}@test.local", f"h-{uuid.uuid4().hex[:6]}@test.local"
|
||||
n = st.save_balances(year=2026, by="admin@test.local", rows=[
|
||||
{"user_email": a, "total_days": None, "prior_used": 3.5, "memo": "", "hire_date": "2025-03-01"},
|
||||
{"user_email": b, "total_days": 20, "prior_used": None, "memo": "직접", "hire_date": "2020-03-02"},
|
||||
])
|
||||
self.assertEqual(n, 2)
|
||||
self.assertEqual(st.hire_dates()[a], "2025-03-01")
|
||||
sa = st.balance_summary(user_email=a, year=2026)
|
||||
self.assertEqual((sa["total_days"], sa["manual_total"], sa["legal_days"], sa["prior_used"], sa["remaining_days"]),
|
||||
(17.0, None, 17.0, 3.5, 13.5)) # 법정 17 − 시스템 전 3.5
|
||||
sb = st.balance_summary(user_email=b, year=2026)
|
||||
self.assertEqual((sb["total_days"], sb["legal_days"], sb["remaining_days"], sb["service_years"]), (20.0, 17.0, 20.0, 6))
|
||||
# 2027 — 아무것도 등록 안 해도 입사일로 법정 연차(이월 없음)
|
||||
self.assertEqual(st.balance_summary(user_email=a, year=2027)["total_days"], 15.0)
|
||||
# 입사일 지우기("") · 키 없으면 그대로 · 틀린 입사일은 전부 저장 안 함
|
||||
st.save_balances(year=2026, rows=[{"user_email": a, "total_days": None, "prior_used": 0, "memo": ""}])
|
||||
self.assertEqual(st.hire_dates()[a], "2025-03-01")
|
||||
with self.assertRaises(ValueError):
|
||||
st.save_balances(year=2026, rows=[{"user_email": a, "total_days": None, "hire_date": ""},
|
||||
{"user_email": b, "total_days": None, "hire_date": "2020-13-01"}])
|
||||
self.assertEqual(st.hire_dates()[a], "2025-03-01")
|
||||
st.save_balances(year=2026, rows=[{"user_email": a, "total_days": None, "hire_date": ""}])
|
||||
self.assertNotIn(a, st.hire_dates())
|
||||
self.assertEqual(st.balance_summary(user_email=a, year=2026)["total_days"], 0.0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -201,6 +201,18 @@ class Store:
|
||||
return []
|
||||
def used_days(self, user_email, year):
|
||||
return 0.0
|
||||
def hire_ready(self):
|
||||
return True
|
||||
def hire_dates(self):
|
||||
return {}
|
||||
def balance_summary(self, user_email, year, hire_date=None):
|
||||
bal = {b["user_email"]: b for b in self.list_balances(year)}.get(user_email)
|
||||
used = self.used_days(user_email, year)
|
||||
manual = bal["total_days"] if bal else None
|
||||
total = manual if manual is not None else 0.0
|
||||
return {"year": year, "total_days": total, "manual_total": manual, "legal_days": None, "legal_items": [],
|
||||
"service_years": 0, "hire_date": hire_date or "", "prior_used": 0.0, "erp_used": used,
|
||||
"used_days": used, "remaining_days": total - used, "memo": bal["memo"] if bal else ""}
|
||||
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)}
|
||||
|
||||
@@ -356,8 +368,10 @@ class Store2(Store):
|
||||
[{"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 save_balances(self, year, rows, by=""):
|
||||
saved.update(year=year, rows=rows, by=by); return len(rows)
|
||||
def hire_dates(self):
|
||||
return {"lee@test.local": "2020-03-02"}
|
||||
def list_holidays(self, year=None):
|
||||
return []
|
||||
def holiday_map(self, date_from, date_to):
|
||||
@@ -365,8 +379,6 @@ class Store2(Store):
|
||||
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()
|
||||
@@ -383,26 +395,38 @@ def body(c):
|
||||
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]
|
||||
row = t[i:i + 1800]
|
||||
h = t.rfind('name="hire"', 0, i)
|
||||
assert 'value="2020-03-02"' in t[h:i], t[h:i] # 입사일 = 이름 옆 날짜 칸(값 저장소)
|
||||
assert "법정 연차" in t and "시스템 전 사용" in t and "근로기준법 제60조" in t
|
||||
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"]})
|
||||
"hire": ["2020-03-02", "", "2025-03-01"], "total": ["16", "", ""],
|
||||
"prior": ["", "2.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
|
||||
assert saved == {"year": 2026, "by": "admin@test.local", "rows": [
|
||||
{"user_email": "lee@test.local", "total_days": 16.0, "prior_used": None, "memo": "a", "hire_date": "2020-03-02"},
|
||||
{"user_email": "kim@test.local", "total_days": None, "prior_used": 2.5, "memo": "b", "hire_date": ""},
|
||||
{"user_email": "chip@test.local", "total_days": None, "prior_used": None, "memo": "c", "hire_date": "2025-03-01"}]}, saved
|
||||
bad = {"year": "2026", "email": ["lee@test.local"], "hire": [""], "prior": [""], "memo": [""]}
|
||||
assert c.post("/vacation/options/balances", data=dict(bad, total=["x"])).status_code == 400
|
||||
assert c.post("/vacation/options/balances", data={"year": "2026", "email": ["lee@test.local"], "total": ["1"], "memo": [""]}).status_code == 400 # 칸 수
|
||||
assert "시스템 전 사용</th>" not in c.get("/vacation/options?year=2027").text # 도입 해(2026)만
|
||||
# 승인자(옵션 미지정 → 휴가 승인 권한 chip)는 잔여 연차도 보고 저장
|
||||
who["u"] = chip
|
||||
assert 'id="balances"' in c.get("/vacation/options").text
|
||||
assert c.post("/vacation/options/balances", data={"year": "2026", "email": ["kim@test.local"], "total": ["14"], "memo": [""]}).status_code == 303
|
||||
assert c.post("/vacation/options/balances", data={"year": "2026", "email": ["kim@test.local"], "hire": [""], "total": ["14"],
|
||||
"prior": [""], "memo": [""]}).status_code == 303
|
||||
# 관리자·승인자·통보자 아님 — 표 안 보임, 저장 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
|
||||
assert c.post("/vacation/options/balances", data={"year": "2026", "email": ["kim@test.local"], "hire": [""], "total": ["30"],
|
||||
"prior": [""], "memo": [""]}).status_code == 403
|
||||
# 설정 화면 삭제 — 예전 주소는 옵션으로, 공휴일·잔여 연차 저장 주소 없음
|
||||
who["u"] = admin
|
||||
r = c.get("/vacation/settings?year=2026")
|
||||
|
||||
Reference in New Issue
Block a user