feat(project): manual monthly sales target with weekly diff
Week target popup now has its own "month total" input at the top; the monthly target is saved as entered instead of being the sum of weeks. Bottom shows week sum and diff (month target - week sum), colored for remaining / over / even. Requests without `month` (stale cached JS) still fall back to the week sum. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3090,7 +3090,7 @@ class ProjectStore:
|
||||
return {"sales_unit": head["sales_unit"] if head else "", "sales_target": vals.get(("sales", "target")),
|
||||
"sales_actual": vals.get(("sales", "actual")), "roas_target": vals.get(("roas", "target"))}
|
||||
|
||||
# ── 주차별 매출 목표(020) — 목표 표 매출 단위 그대로, 월 목표 = 그 달 주차 합계 ──
|
||||
# ── 주차별 매출 목표(020) — 목표 표 매출 단위 그대로, 월 목표는 따로 직접 입력(주차 합계와 다를 수 있음) ──
|
||||
def week_targets_enabled(self) -> bool:
|
||||
with self._pool.connection() as conn:
|
||||
return self._table_exists(conn, "goal_week_targets")
|
||||
@@ -3107,10 +3107,13 @@ class ProjectStore:
|
||||
return {r["week_start"].isoformat(): float(r["value"]) for r in rows}
|
||||
|
||||
def set_goal_week_targets(
|
||||
self, *, year: int, month: int, values: dict[date, float | None], updated_by: str = ""
|
||||
self, *, year: int, month: int, values: dict[date, float | None], month_value: float | None,
|
||||
updated_by: str = ""
|
||||
) -> float | None:
|
||||
"""그 달 주차별 목표 저장(None = 지움) → 그 달 주차 합계를 매출 목표(goal_metrics sales/target)로.
|
||||
주차가 모두 비면 월 목표도 지운다(월 목표 = 주차 합계). 합계를 돌려준다(없으면 None)."""
|
||||
"""그 달 주차별 목표 저장(None = 지움) + 월 매출 목표(goal_metrics sales/target)는 month_value 그대로
|
||||
(None = 지움). 월 목표는 주차 합계와 따로 — 차이는 화면이 계산한다. 그 달 주차 합계를 돌려준다(없으면 None)."""
|
||||
if month_value is not None and month_value < 0:
|
||||
raise ValueError("월 목표는 0 이상이어야 합니다.")
|
||||
m = store.validate_goal_month(month)
|
||||
periods = {a for a, _ in store.month_weeks(year, m)}
|
||||
if any(d not in periods for d in values):
|
||||
@@ -3139,7 +3142,7 @@ class ProjectStore:
|
||||
(year, m),
|
||||
).fetchone()
|
||||
total = float(row["total"]) if row["n"] else None
|
||||
if total is None:
|
||||
if month_value is None:
|
||||
conn.execute("DELETE FROM goal_metrics WHERE year=%s AND metric='sales' AND kind='target' AND month=%s",
|
||||
(year, m))
|
||||
else:
|
||||
@@ -3147,7 +3150,7 @@ class ProjectStore:
|
||||
"INSERT INTO goal_metrics (year, metric, kind, month, value, updated_by) "
|
||||
"VALUES (%s,'sales','target',%s,%s,%s) ON CONFLICT (year, metric, kind, month) DO UPDATE "
|
||||
"SET value = EXCLUDED.value, updated_by = EXCLUDED.updated_by, updated_at = now()",
|
||||
(year, m, total, who),
|
||||
(year, m, month_value, who),
|
||||
)
|
||||
return total
|
||||
|
||||
|
||||
Reference in New Issue
Block a user