feat(project): 연간 목표 상·하반기 칸·반기 접기·이름 바로 수정·월 칸 병합·로아스 %

- 6월·12월 오른쪽에 상반기·하반기 칸 추가. 매출 목표·실적은 반기 합계,
  달성률은 연간과 같은 규칙, 업무 영역 글 칸은 month 13·14 로 저장
- 반기 칸 머리 버튼으로 1~6월 / 7~12월 칸을 접었다 펴기(너비 애니메이션,
  localStorage pj_goal_fold). 표를 width:1px + table-layout:fixed 로 바꿔
  펼칠 때도 애니메이션이 적용되게 함
- 업무 영역·줄 이름을 눌러 그 자리에서 수정(✎ 버튼 제거)
- 월 칸 가로 병합(goal_cell_merges, 반기 안에서만): Shift+클릭 선택 후
  병합 버튼, 우클릭 메뉴로 좌/우 병합·해제. 병합 시 글은 월 순서대로 첫 칸에 모음
- 로아스 목표·실적 칸 % 표기
- 마이그레이션 014 (goal_cells month CHECK 0~14, goal_cell_merges)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 08:24:13 +09:00
parent 91bdc12e78
commit 5d07770ce2
15 changed files with 750 additions and 88 deletions
+62 -7
View File
@@ -2514,6 +2514,7 @@ def inbox_page(request: Request) -> HTMLResponse:
# 조회: project 권한자 전원 · 입력/구조 변경: 관리자(is_admin) 전용
# ────────────────────────────────────────────────────────────
_GOALS_MIGRATION_MSG = "연간 목표 기능이 아직 준비되지 않았습니다(DB 마이그레이션 013 필요)."
_GOALS_014_MSG = "상·하반기 칸과 칸 병합은 DB 마이그레이션 014 가 필요합니다."
def _fmt_goal_num(v: float | None) -> str:
@@ -2525,10 +2526,37 @@ def _fmt_goal_num(v: float | None) -> str:
return f"{v:,.2f}".rstrip("0").rstrip(".")
def _goal_label(metric: str, v: float | None) -> str:
"""지표 칸 표기 — 로아스는 % 단위(499 → "499%"). 입력칸도 이 표기로 보이고, 저장 때 % 는 떼고 읽는다."""
s = _fmt_goal_num(v)
return f"{s}%" if s and metric == "roas" else s
def _goal_row_layout(merges: dict[int, int], this_month: int) -> list[dict[str, Any]]:
"""업무 영역 한 줄의 칸 배치 — 연간 · 1~6월 · 상반기 · 7~12월 · 하반기 순서.
월 칸은 병합(시작 월 → 칸 수)을 반영해 {"m", "span", "h"(1|2), "now"}, 연간·반기 칸은 {"m": 0|13|14}.
병합 정보가 반기를 넘거나 겹치면(있을 수 없지만) 그 병합은 무시한다."""
out: list[dict[str, Any]] = [{"m": store.GOAL_YEAR, "kind": "year"}]
for h, (lo, hi, half_m) in enumerate(((1, 6, store.GOAL_H1), (7, 12, store.GOAL_H2)), start=1):
mo = lo
while mo <= hi:
span = int(merges.get(mo, 1) or 1)
if span < 1 or mo + span - 1 > hi:
span = 1
out.append({"m": mo, "span": span, "h": h, "kind": "month",
"now": mo <= this_month <= mo + span - 1})
mo += span
out.append({"m": half_m, "kind": "half", "h": h})
return out
def _goal_call(fn: Any, *args: Any, **kwargs: Any) -> Any:
"""목표 DB 호출 공통 — 013 미적용 503, 없는 대상 404, 입력 오류 400."""
try:
return fn(*args, **kwargs)
except store.GoalMigration014Needed:
raise HTTPException(status_code=503, detail=_GOALS_014_MSG)
except UndefinedTable:
raise HTTPException(status_code=503, detail=_GOALS_MIGRATION_MSG)
except KeyError:
@@ -2562,11 +2590,15 @@ def goals_page(request: Request, year: int) -> HTMLResponse:
admin = is_admin(user)
enabled = st.goals_enabled()
board = st.get_goal_board(year=year) if enabled else None
if board:
for m in board["metrics"].values():
for kind in list(m):
m[kind + "_label"] = {mo: _fmt_goal_num(v) for mo, v in m[kind].items()}
today = today_kst()
this_month = today.month if today.year == year else 0
if board:
for metric, m in board["metrics"].items():
for kind in list(m):
m[kind + "_label"] = {mo: _goal_label(metric, v) for mo, v in m[kind].items()}
for area in board["areas"]:
for row in area["rows"]:
row["layout"] = _goal_row_layout(row.get("merges") or {}, this_month)
return render_template(
request,
"project/goals.html",
@@ -2588,7 +2620,9 @@ def goals_page(request: Request, year: int) -> HTMLResponse:
"goal_year": year,
"board": board,
"months": list(range(1, 13)),
"this_month": today.month if today.year == year else 0,
"halves": [(1, list(range(1, 7)), store.GOAL_H1, "상반기"),
(2, list(range(7, 13)), store.GOAL_H2, "하반기")],
"this_month": this_month,
"goal_area_colors": list(store.GOAL_AREA_COLORS),
},
)
@@ -2631,7 +2665,7 @@ def api_set_goal_metric(request: Request, year: int, payload: dict[str, Any] = B
kind=str(payload.get("kind") or ""), month=payload.get("month"),
value=value, updated_by=user["email"],
)
return JSONResponse({"ok": True, "value": value, "label": _fmt_goal_num(value)})
return JSONResponse({"ok": True, "value": value, "label": _goal_label(str(payload.get("metric") or ""), value)})
@router.post("/api/goals/{year}/areas")
@@ -2703,7 +2737,7 @@ def api_move_goal_row(request: Request, row_id: int, payload: dict[str, Any] = B
def api_set_goal_cell(
request: Request, row_id: int, month: int, payload: dict[str, Any] = Body(...)
) -> JSONResponse:
"""업무 영역 칸 글 — month 0 = 연간, 1~12 = 월. 빈 글 = 지움."""
"""업무 영역 칸 글 — month 0 = 연간, 1~12 = 월, 13 = 상반기, 14 = 하반기(014). 빈 글 = 지움."""
user = _require_admin(request)
st = _db_or_503(request)
_goal_call(
@@ -2711,3 +2745,24 @@ def api_set_goal_cell(
body=payload.get("body", ""), updated_by=user["email"],
)
return JSONResponse({"ok": True})
@router.post("/api/goals/rows/{row_id}/merge")
def api_merge_goal_cells(request: Request, row_id: int, payload: dict[str, Any] = Body(...)) -> JSONResponse:
"""월 칸 가로 병합 {start, end}(반기 안, 2칸 이상) — 걸친 병합은 흡수, 글은 이어서 시작 월 칸에."""
user = _require_admin(request)
st = _db_or_503(request)
start, span = _goal_call(
st.merge_goal_cells, row_id=row_id, start=payload.get("start"), end=payload.get("end"),
updated_by=user["email"],
)
return JSONResponse({"ok": True, "start": start, "span": span})
@router.delete("/api/goals/rows/{row_id}/merge/{start}")
def api_unmerge_goal_cells(request: Request, row_id: int, start: int) -> JSONResponse:
"""병합 해제 — 글은 시작 월 칸에 남는다."""
_require_admin(request)
st = _db_or_503(request)
_goal_call(st.unmerge_goal_cells, row_id=row_id, start=start)
return JSONResponse({"ok": True})