feat(project): 연간 목표 — 사이드바 "목표" → 연도 → 그해 전체 목표 표
- 사이드바 휴지통 아래 "목표": 누르면 연도 목록이 펼쳐지고(올해는 항상), 관리자는 + 연도 추가
- /project/goals/{연도}: 매출(목표·실적·달성)·로아스(목표·실적) 월별 숫자 + 업무 영역
(상품·마케팅·컨텐츠·유통[콜라보·인플·쿠팡·기타])별 연간·월별 글을 스프레드시트처럼 한 표에
- 매출 연간 합계·달성률은 화면에서 계산, 칸별 즉시 저장, 영역 이름·색·순서·줄 추가/삭제
- 입력·구조 변경은 관리자만, 조회는 project 권한자 전원
- 새 연도는 가장 가까운 이전 연도의 영역 구성을 복사(처음이면 기본 4개 영역)
- DB 마이그레이션 013(goal_years·goal_metrics·goal_areas·goal_rows·goal_cells), 문서·도움말 갱신
- project.js/css 캐시 버전 20260930a
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -42,7 +42,7 @@ from fastapi.responses import (
|
||||
JSONResponse,
|
||||
RedirectResponse,
|
||||
)
|
||||
from psycopg.errors import UndefinedColumn
|
||||
from psycopg.errors import UndefinedColumn, UndefinedTable
|
||||
|
||||
from app.timezone import KST, now_kst, today_kst
|
||||
|
||||
@@ -393,6 +393,22 @@ def _nav_projects(st: Any, user: dict[str, Any], admin: bool) -> list[dict[str,
|
||||
]
|
||||
|
||||
|
||||
def _goal_years_nav(st: Any) -> list[int]:
|
||||
"""좌측 사이드바 "목표" 아래 연도 목록(최근 연도 먼저). 올해는 목표를 아직 안
|
||||
만들었어도 항상 보인다(누르면 관리자에게 "목표 만들기"). 013 미적용이면 올해만."""
|
||||
this_year = today_kst().year
|
||||
try:
|
||||
years = st.list_goal_years()
|
||||
except UndefinedTable:
|
||||
years = []
|
||||
except Exception: # noqa: BLE001 — 사이드바 때문에 화면 전체가 죽지 않게
|
||||
logger.exception("goal years 조회 실패")
|
||||
years = []
|
||||
if this_year not in years:
|
||||
years.append(this_year)
|
||||
return sorted(set(years), reverse=True)
|
||||
|
||||
|
||||
def _build_tree(projects: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
||||
"""평면 프로젝트 목록 → parent_id 기준 트리(children 키)."""
|
||||
by_id: dict[int, dict[str, Any]] = {}
|
||||
@@ -582,6 +598,7 @@ def my_tasks_page(request: Request) -> HTMLResponse:
|
||||
"page_subtitle": "내가 담당자인 작업을 한 곳에서 봅니다.",
|
||||
"force_sidebar_collapsed": True,
|
||||
"nav_projects": nav_projects,
|
||||
"goal_years": _goal_years_nav(st),
|
||||
"my_tasks": my_tasks,
|
||||
"my_open_total": my_open_total,
|
||||
"mention_unread": _safe_mention_unread(st, user["email"]),
|
||||
@@ -791,6 +808,7 @@ def project_page(request: Request, project_id: int) -> HTMLResponse:
|
||||
"my_open_total": my_open_total,
|
||||
"mention_unread": mention_unread,
|
||||
"nav_projects": nav_projects,
|
||||
"goal_years": _goal_years_nav(st),
|
||||
"stages": stages,
|
||||
"tasks": all_tasks,
|
||||
"members": members,
|
||||
@@ -2067,6 +2085,7 @@ def trash_page(request: Request) -> HTMLResponse:
|
||||
"is_admin": True,
|
||||
"nav_items": build_erp_nav(user, active="project"),
|
||||
"nav_projects": _nav_projects(st, user, True),
|
||||
"goal_years": _goal_years_nav(st),
|
||||
"my_open_total": st.count_my_open(assignee_email=user["email"]),
|
||||
"mention_unread": _safe_mention_unread(st, user["email"]),
|
||||
"page_title": "휴지통",
|
||||
@@ -2162,6 +2181,7 @@ def inbox_page(request: Request) -> HTMLResponse:
|
||||
"is_admin": admin,
|
||||
"nav_items": build_erp_nav(user, active="project"),
|
||||
"nav_projects": nav_projects,
|
||||
"goal_years": _goal_years_nav(st),
|
||||
"my_open_total": my_open_total,
|
||||
"page_title": "수신함",
|
||||
"page_subtitle": "나를 태그한 작업과 프로젝트 알림",
|
||||
@@ -2173,3 +2193,207 @@ def inbox_page(request: Request) -> HTMLResponse:
|
||||
"mention_unread": _safe_mention_unread(st, user["email"]),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
# ────────────────────────────────────────────────────────────
|
||||
# 연간 목표 (마이그레이션 013) — 사이드바 "목표" → 연도 → 목표 표
|
||||
# 조회: project 권한자 전원 · 입력/구조 변경: 관리자(is_admin) 전용
|
||||
# ────────────────────────────────────────────────────────────
|
||||
_GOALS_MIGRATION_MSG = "연간 목표 기능이 아직 준비되지 않았습니다(DB 마이그레이션 013 필요)."
|
||||
|
||||
|
||||
def _fmt_goal_num(v: float | None) -> str:
|
||||
"""지표 숫자 표시 — 천 단위 쉼표, 소수는 필요한 만큼만(12.50 → 12.5)."""
|
||||
if v is None:
|
||||
return ""
|
||||
if float(v).is_integer():
|
||||
return f"{int(v):,}"
|
||||
return f"{v:,.2f}".rstrip("0").rstrip(".")
|
||||
|
||||
|
||||
def _goal_call(fn: Any, *args: Any, **kwargs: Any) -> Any:
|
||||
"""목표 DB 호출 공통 — 013 미적용 503, 없는 대상 404, 입력 오류 400."""
|
||||
try:
|
||||
return fn(*args, **kwargs)
|
||||
except UndefinedTable:
|
||||
raise HTTPException(status_code=503, detail=_GOALS_MIGRATION_MSG)
|
||||
except KeyError:
|
||||
raise HTTPException(status_code=404, detail="대상을 찾을 수 없습니다. 새로고침해 주세요.")
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc))
|
||||
|
||||
|
||||
@router.get("/goals")
|
||||
def goals_home(request: Request) -> RedirectResponse:
|
||||
"""사이드바 "목표" 자체 주소 — 가장 최근 연도(없으면 올해)로."""
|
||||
_require_user(request)
|
||||
st = _store(request)
|
||||
years = _goal_years_nav(st) if st is not None else [today_kst().year]
|
||||
return RedirectResponse(url=f"/project/goals/{years[0]}", status_code=303)
|
||||
|
||||
|
||||
@router.get("/goals/{year}", response_class=HTMLResponse)
|
||||
def goals_page(request: Request, year: int) -> HTMLResponse:
|
||||
"""한 해 전체 목표 — 매출(목표·실적·달성)·로아스(목표·실적) 월별 숫자 +
|
||||
업무 영역(상품·마케팅·컨텐츠·유통 …)별 연간·월별 글. 입력은 관리자만."""
|
||||
from app.main import build_erp_nav, render_template # noqa: WPS433
|
||||
from app.store import is_admin # noqa: WPS433
|
||||
|
||||
user = _require_user(request)
|
||||
st = _store(request)
|
||||
if st is None:
|
||||
return _render_config_needed(request, user)
|
||||
if not 2000 <= year <= 2100:
|
||||
raise HTTPException(status_code=404, detail="연도가 올바르지 않습니다.")
|
||||
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()
|
||||
return render_template(
|
||||
request,
|
||||
"project/goals.html",
|
||||
{
|
||||
"user": user,
|
||||
"is_admin": admin,
|
||||
"nav_items": build_erp_nav(user, active="project"),
|
||||
"nav_projects": _nav_projects(st, user, admin),
|
||||
"goal_years": _goal_years_nav(st),
|
||||
"goal_year_active": year,
|
||||
"my_open_total": st.count_my_open(assignee_email=user["email"]),
|
||||
"mention_unread": _safe_mention_unread(st, user["email"]),
|
||||
"page_title": f"{year}년 목표",
|
||||
"page_subtitle": "한 해 전체 목표와 업무 영역별 계획",
|
||||
"force_sidebar_collapsed": True,
|
||||
"color_palette": list(store.COLOR_PALETTE),
|
||||
"project_icons": list(store.PROJECT_ICONS),
|
||||
"goals_enabled": enabled,
|
||||
"goal_year": year,
|
||||
"board": board,
|
||||
"months": list(range(1, 13)),
|
||||
"this_month": today.month if today.year == year else 0,
|
||||
"goal_area_colors": list(store.GOAL_AREA_COLORS),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@router.post("/api/goals/years")
|
||||
def api_create_goal_year(request: Request, payload: dict[str, Any] = Body(...)) -> JSONResponse:
|
||||
"""연도 추가(관리자) — 가장 가까운 이전 연도의 영역·줄 구조를 글 없이 복사."""
|
||||
user = _require_admin(request)
|
||||
st = _db_or_503(request)
|
||||
y = _goal_call(store.validate_goal_year, payload.get("year"))
|
||||
_goal_call(st.create_goal_year, year=y, created_by=user["email"])
|
||||
return JSONResponse({"ok": True, "year": y}, status_code=201)
|
||||
|
||||
|
||||
@router.put("/api/goals/{year}")
|
||||
def api_update_goal_year(request: Request, year: int, payload: dict[str, Any] = Body(...)) -> JSONResponse:
|
||||
_require_admin(request)
|
||||
st = _db_or_503(request)
|
||||
_goal_call(st.update_goal_year, year=year, sales_unit=payload.get("sales_unit", ""))
|
||||
return JSONResponse({"ok": True})
|
||||
|
||||
|
||||
@router.delete("/api/goals/{year}")
|
||||
def api_delete_goal_year(request: Request, year: int) -> JSONResponse:
|
||||
_require_admin(request)
|
||||
st = _db_or_503(request)
|
||||
_goal_call(st.delete_goal_year, year=year)
|
||||
return JSONResponse({"ok": True})
|
||||
|
||||
|
||||
@router.put("/api/goals/{year}/metrics")
|
||||
def api_set_goal_metric(request: Request, year: int, payload: dict[str, Any] = Body(...)) -> JSONResponse:
|
||||
"""매출/로아스 목표·실적 한 칸 — {metric, kind, month, value}. value 빈값 = 지움."""
|
||||
user = _require_admin(request)
|
||||
st = _db_or_503(request)
|
||||
value = _goal_call(store.validate_goal_value, payload.get("value"))
|
||||
_goal_call(
|
||||
st.set_goal_metric, year=year, metric=str(payload.get("metric") or ""),
|
||||
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)})
|
||||
|
||||
|
||||
@router.post("/api/goals/{year}/areas")
|
||||
def api_add_goal_area(request: Request, year: int, payload: dict[str, Any] = Body(...)) -> JSONResponse:
|
||||
_require_admin(request)
|
||||
st = _db_or_503(request)
|
||||
aid = _goal_call(st.add_goal_area, year=year, name=payload.get("name", ""), color=payload.get("color", ""))
|
||||
return JSONResponse({"ok": True, "id": aid}, status_code=201)
|
||||
|
||||
|
||||
@router.put("/api/goals/areas/{area_id}")
|
||||
def api_update_goal_area(request: Request, area_id: int, payload: dict[str, Any] = Body(...)) -> JSONResponse:
|
||||
_require_admin(request)
|
||||
st = _db_or_503(request)
|
||||
fields = {k: payload[k] for k in ("name", "color") if k in payload}
|
||||
_goal_call(st.update_goal_area, area_id=area_id, fields=fields)
|
||||
return JSONResponse({"ok": True})
|
||||
|
||||
|
||||
@router.delete("/api/goals/areas/{area_id}")
|
||||
def api_delete_goal_area(request: Request, area_id: int) -> JSONResponse:
|
||||
_require_admin(request)
|
||||
st = _db_or_503(request)
|
||||
_goal_call(st.delete_goal_area, area_id=area_id)
|
||||
return JSONResponse({"ok": True})
|
||||
|
||||
|
||||
@router.post("/api/goals/areas/{area_id}/move")
|
||||
def api_move_goal_area(request: Request, area_id: int, payload: dict[str, Any] = Body(...)) -> JSONResponse:
|
||||
_require_admin(request)
|
||||
st = _db_or_503(request)
|
||||
_goal_call(st.move_goal_area, area_id=area_id, direction=int(payload.get("direction") or 0))
|
||||
return JSONResponse({"ok": True})
|
||||
|
||||
|
||||
@router.post("/api/goals/areas/{area_id}/rows")
|
||||
def api_add_goal_row(request: Request, area_id: int, payload: dict[str, Any] = Body(...)) -> JSONResponse:
|
||||
_require_admin(request)
|
||||
st = _db_or_503(request)
|
||||
rid = _goal_call(st.add_goal_row, area_id=area_id, label=payload.get("label", ""))
|
||||
return JSONResponse({"ok": True, "id": rid}, status_code=201)
|
||||
|
||||
|
||||
@router.put("/api/goals/rows/{row_id}")
|
||||
def api_update_goal_row(request: Request, row_id: int, payload: dict[str, Any] = Body(...)) -> JSONResponse:
|
||||
_require_admin(request)
|
||||
st = _db_or_503(request)
|
||||
_goal_call(st.update_goal_row, row_id=row_id, label=payload.get("label", ""))
|
||||
return JSONResponse({"ok": True})
|
||||
|
||||
|
||||
@router.delete("/api/goals/rows/{row_id}")
|
||||
def api_delete_goal_row(request: Request, row_id: int) -> JSONResponse:
|
||||
_require_admin(request)
|
||||
st = _db_or_503(request)
|
||||
_goal_call(st.delete_goal_row, row_id=row_id)
|
||||
return JSONResponse({"ok": True})
|
||||
|
||||
|
||||
@router.post("/api/goals/rows/{row_id}/move")
|
||||
def api_move_goal_row(request: Request, row_id: int, payload: dict[str, Any] = Body(...)) -> JSONResponse:
|
||||
_require_admin(request)
|
||||
st = _db_or_503(request)
|
||||
_goal_call(st.move_goal_row, row_id=row_id, direction=int(payload.get("direction") or 0))
|
||||
return JSONResponse({"ok": True})
|
||||
|
||||
|
||||
@router.put("/api/goals/rows/{row_id}/cells/{month}")
|
||||
def api_set_goal_cell(
|
||||
request: Request, row_id: int, month: int, payload: dict[str, Any] = Body(...)
|
||||
) -> JSONResponse:
|
||||
"""업무 영역 칸 글 — month 0 = 연간, 1~12 = 월. 빈 글 = 지움."""
|
||||
user = _require_admin(request)
|
||||
st = _db_or_503(request)
|
||||
_goal_call(
|
||||
st.set_goal_cell, row_id=row_id, month=month,
|
||||
body=payload.get("body", ""), updated_by=user["email"],
|
||||
)
|
||||
return JSONResponse({"ok": True})
|
||||
|
||||
Reference in New Issue
Block a user