feat(실적): 카페24(실적) 열·합계 기준 통일·공통 보기 설정·일 합계 고정
매출 실적 - "카페24" 열 → "카페24(전체)", 바로 오른쪽 "카페24(실적)" = 전체 − 자사몰(공동구매), 광고비 줄은 카페24(전체)의 구글·메타 그대로 (예전 "공구 제외" 열 대체) - 합계 기준 통일: 일 합계·ROAS·KPI·추이·비중·월/연 누적 = 카페24(실적) + 공동구매 + 나머지 (카페24(전체)에 공동구매가 들어 있어 이중 합산 제거, 그래프·누적의 카페24 줄 = 카페24(실적)) - 실적 설정 "공통 보기 설정"(관리자, perf_settings, 모든 사용자 적용): 매출 단위(예전 브라우저 쿠키 perf_unit 대체), 표 열 숨기기(열만, 합계 그대로) 표 열 너비는 사람(브라우저)마다 그대로 매출 실적·광고비 공통 - 일 합계 열을 날짜 오른쪽으로, 날짜와 함께 가로 고정 - 이전달·다음달 = 날짜 바로 옆 진한 회색 화살표 SVG(글자 높이) - 광고비 탭 매출 대비 광고비·합계 ROAS 도 공동구매 이중 합산 제거 CSS·JS 캐시 버전 20261102a. 새 마이그레이션 없음(011 perf_settings 사용). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -57,27 +57,44 @@ def _group_columns(store_rows: Sequence[Mapping[str, Any]], codes: Sequence[str]
|
||||
return cols, members
|
||||
|
||||
|
||||
# 카페24 − 카페24 공동구매 열(2026-10-30) — 직접 추가 쇼핑몰 "카페24 공동구매" 바로 오른쪽, 표 열만(일 합계·그래프·누적엔 안 더함).
|
||||
# shortcut: 공동구매 쇼핑몰은 이름(띄어쓰기 무시)으로 찾는다 — 설정에서 이름을 바꾸면 이 열이 사라진다, 자주 바뀌면 설정 값으로.
|
||||
CAFE24_GB_NAME = "카페24공동구매"
|
||||
# 카페24(실적) 열(2026-11-02, 예전 "공구 제외") — 카페24(전체) 바로 오른쪽, 카페24 − 공동구매. 표 열만(일 합계·그래프·누적엔 안 더함).
|
||||
# shortcut: 공동구매 쇼핑몰은 이름(띄어쓰기 무시)으로 찾는다 — 설정에서 다른 이름으로 바꾸면 빼지 않아 실적 = 전체가 된다, 자주 바뀌면 설정 값으로.
|
||||
CAFE24_GB_NAMES = ("자사몰(공동구매)", "카페24공동구매")
|
||||
CAFE24_EX_GB = "cafe24_ex_gb"
|
||||
CAFE24_REAL_NAME = "카페24(실적)"
|
||||
|
||||
|
||||
def _cafe24_ex_gb_column(markets: Sequence[Mapping[str, Any]], codes: Sequence[str], cols: list[dict[str, Any]],
|
||||
names: dict[str, str], short: dict[str, str], table: list[dict[str, Any]]) -> None:
|
||||
"""카페24·공동구매 둘 다 보일 때만 공동구매 열 뒤에 차이 열(kind diff — 공동구매가 그룹 하위면 같은 그룹으로 접힘)."""
|
||||
gb = next((m["code"] for m in markets
|
||||
if m["name"].replace(" ", "") == CAFE24_GB_NAME and m["code"] in codes), None)
|
||||
if gb is None or "cafe24" not in codes:
|
||||
def groupbuy_code(markets: Sequence[Mapping[str, Any]]) -> str:
|
||||
"""공동구매 쇼핑몰 코드, 없으면 빈 값."""
|
||||
return next((m["code"] for m in markets if m["name"].replace(" ", "") in CAFE24_GB_NAMES), "")
|
||||
|
||||
|
||||
def total_sales_codes(markets: Sequence[Mapping[str, Any]]) -> list[str]:
|
||||
"""전체 매출에 더할 쇼핑몰 — 카페24(전체)에 공동구매가 들어 있어 카페24 가 있으면 공동구매는 뺀다(광고비 탭 매출 대비 광고비·합계 ROAS)."""
|
||||
codes = [m["code"] for m in markets]
|
||||
gb = groupbuy_code(markets)
|
||||
return [c for c in codes if c != gb] if "cafe24" in codes else codes
|
||||
|
||||
|
||||
def _summary_cells(cells: Mapping[tuple[date, str], calc.Money], gb: str) -> dict[tuple[date, str], calc.Money]:
|
||||
"""합계용 칸(2026-11-02) — 카페24 칸 = 카페24(실적)(카페24 − 공동구매). 일 합계·KPI·그래프·누적은 이 값으로 더해 공동구매가 두 번 안 들어간다."""
|
||||
out = dict(cells)
|
||||
for (d, c), m in cells.items():
|
||||
if c == gb:
|
||||
a = cells.get((d, "cafe24"), calc.Money())
|
||||
out[(d, "cafe24")] = calc.Money(gross=a.gross - m.gross, commission=a.commission - m.commission)
|
||||
return out
|
||||
|
||||
|
||||
def _cafe24_real_column(cols: list[dict[str, Any]], names: dict[str, str], short: dict[str, str], gb: str) -> None:
|
||||
"""카페24(실적) 열 머리 — 공동구매가 없으면(gb 빈 값) 전체와 같은 값이고 화면 즉시 계산도 없다."""
|
||||
col = next((c for c in cols if c["code"] == CAFE24_EX_GB), None)
|
||||
if col is None:
|
||||
return
|
||||
i = next(i for i, col in enumerate(cols) if col["code"] == gb)
|
||||
# base·minus = 화면이 공동구매 칸 저장 때 이 줄 차이 칸을 바로 다시 계산할 때 씀(performance.js saveManual)
|
||||
cols.insert(i + 1, {"code": CAFE24_EX_GB, "kind": "diff", "group": cols[i]["group"], "base": "cafe24", "minus": gb})
|
||||
names[CAFE24_EX_GB] = f"{names['cafe24']} − {names[gb]}"
|
||||
short[CAFE24_EX_GB] = f"{short['cafe24']}(공구 제외)"
|
||||
for r in table:
|
||||
a, b = r["cells"]["cafe24"], r["cells"][gb]
|
||||
r["cells"][CAFE24_EX_GB] = {k: a[k] - b[k] for k in ("gross", "commission", "net")}
|
||||
# base·minus = 화면이 공동구매 칸 저장 때 이 줄 칸을 바로 다시 계산할 때 씀(performance.js saveManual)
|
||||
col.update(kind="diff", base="cafe24", minus=gb)
|
||||
names[CAFE24_EX_GB] = f"{names['cafe24']} − {names[gb]}" if gb else CAFE24_REAL_NAME
|
||||
short[CAFE24_EX_GB] = CAFE24_REAL_NAME
|
||||
|
||||
|
||||
def display_status(marketplace: Mapping[str, Any], status_row: Mapping[str, Any] | None,
|
||||
@@ -92,9 +109,9 @@ def display_status(marketplace: Mapping[str, Any], status_row: Mapping[str, Any]
|
||||
return (status_row or {}).get("status") or "unknown"
|
||||
|
||||
|
||||
# 매출 단위(2026-10-19, 실적 설정 "보기 설정" — 이 브라우저 쿠키 perf_unit) — (나누는 수, 소수 자리, 단위 이름)
|
||||
# 매출 단위(2026-10-19, 11-02 실적 설정 "공통 보기 설정" — 모든 사용자 같음, 마이그레이션 011 perf_settings) — (나누는 수, 소수 자리, 단위 이름)
|
||||
UNITS: dict[str, tuple[int, int, str]] = {"won": (1, 0, "원"), "thousand": (1000, 0, "천원"), "million": (1_000_000, 1, "백만원")}
|
||||
UNIT_COOKIE = "perf_unit"
|
||||
UNIT_SETTING = "display_unit"
|
||||
|
||||
|
||||
def normalize_unit(value: Any) -> str:
|
||||
@@ -109,6 +126,29 @@ def normalize_colw(value: Any) -> str:
|
||||
return "manual" if value == "manual" else "auto"
|
||||
|
||||
|
||||
# 매출 실적 표 열 숨기기(2026-11-02, 실적 설정 "공통 보기 설정" — 관리자가 정하면 모든 사용자에게 적용, 마이그레이션 011 perf_settings) — 코드 목록, 열만 숨김
|
||||
HIDDEN_SETTING = "hidden_marketplaces"
|
||||
|
||||
|
||||
def _shared_setting(store: Any, key: str) -> Any:
|
||||
"""모든 사용자 공통 설정 값. 저장 값 없음·011 미적용이면 None(화면은 그대로 열린다)."""
|
||||
from .db import SettingsMigrationNeeded # noqa: WPS433
|
||||
|
||||
reader = getattr(store, "get_setting", None)
|
||||
try:
|
||||
return reader(key) if reader else None
|
||||
except SettingsMigrationNeeded:
|
||||
return None
|
||||
|
||||
|
||||
def load_hidden(store: Any) -> set[str]:
|
||||
return set(_shared_setting(store, HIDDEN_SETTING) or ())
|
||||
|
||||
|
||||
def load_unit(store: Any) -> str:
|
||||
return normalize_unit(_shared_setting(store, UNIT_SETTING))
|
||||
|
||||
|
||||
def amount_text(value: Any, unit: str = "won") -> str:
|
||||
"""금액 → 화면 글자(쉼표). 천원은 정수, 백만원은 소수 한 자리(반올림)."""
|
||||
div, places, _ = UNITS[normalize_unit(unit)]
|
||||
@@ -198,7 +238,10 @@ def build_dashboard(store: Any, *, kind: str, anchor: date, today: date,
|
||||
names = {m["code"]: m["name"] for m in markets}
|
||||
short = {c: _short_name(names[c]) for c in all_codes}
|
||||
# 그룹(009) — 그룹 열 = 보이는 하위 쇼핑몰 합계(표 열만, 합계·그래프·누적은 쇼핑몰 기준 그대로)
|
||||
cols, group_members = _group_columns(store_rows, codes)
|
||||
# 표에 그릴 열 = 고른 쇼핑몰 + 카페24 바로 뒤 카페24(실적) − 숨긴 열(합계·그래프·누적은 codes 그대로)
|
||||
hidden = load_hidden(store)
|
||||
shown = [x for c in codes for x in ((c, CAFE24_EX_GB) if c == "cafe24" else (c,)) if x not in hidden]
|
||||
cols, group_members = _group_columns(store_rows, shown)
|
||||
for m in store_rows:
|
||||
if m["code"] in group_members:
|
||||
names[m["code"]] = short[m["code"]] = m["name"]
|
||||
@@ -220,7 +263,11 @@ def build_dashboard(store: Any, *, kind: str, anchor: date, today: date,
|
||||
|
||||
q_start = min(period.start, cmp_start, m_cmp_start, y_cmp_start)
|
||||
q_end = max(period.end, year_period.end)
|
||||
cells = calc.build_cells(store.daily_amounts(q_start, q_end, codes), store.rate_table())
|
||||
gb = groupbuy_code(markets)
|
||||
# 공동구매를 필터로 뺐어도 카페24(실적) 계산엔 필요 — 합계·그래프는 아래에서 codes 만 더한다
|
||||
cells = calc.build_cells(store.daily_amounts(q_start, q_end, codes if not gb or gb in codes else [*codes, gb]),
|
||||
store.rate_table())
|
||||
summary = _summary_cells(cells, gb)
|
||||
# 수동 입력(설정에서 켠 쇼핑몰) — 일자별 표의 날짜 칸을 눌러 입력. 값이 있는 칸은 표시(API 값 대신 쓰는 중)
|
||||
manual_codes = [m["code"] for m in markets if m.get("manual_input") and m["code"] in codes]
|
||||
manual_amounts = getattr(store, "manual_amounts", None)
|
||||
@@ -232,8 +279,8 @@ def build_dashboard(store: Any, *, kind: str, anchor: date, today: date,
|
||||
(manual_formulas(period.start, period.end, manual_codes) if manual_formulas and manual_codes else {}).items()
|
||||
if f"{d.isoformat()}|{c}" in manual_cells}
|
||||
|
||||
cur = calc.sum_range(cells, codes, period.start, period.end)
|
||||
prev = calc.sum_range(cells, codes, cmp_start, cmp_end)
|
||||
cur = calc.sum_range(summary, codes, period.start, period.end)
|
||||
prev = calc.sum_range(summary, codes, cmp_start, cmp_end)
|
||||
|
||||
period_word = {"day": "오늘" if period.start == today else "해당일", "week": "이번주" if period.start <= today <= period.end else "해당 주",
|
||||
"month": "이번달" if period.start <= today <= period.end else "해당 월",
|
||||
@@ -246,7 +293,9 @@ def build_dashboard(store: Any, *, kind: str, anchor: date, today: date,
|
||||
"delta": calc.pct_change(cur.net, prev.net), "cmp": cmp_label},
|
||||
]
|
||||
|
||||
share = calc.by_code(cells, codes, period.start, period.end)
|
||||
share = calc.by_code(summary, codes, period.start, period.end)
|
||||
# 비중 그래프·월 누적 표의 카페24 줄 = 카페24(실적) — 줄을 더하면 합계와 같다
|
||||
summary_names = {**names, "cafe24": CAFE24_REAL_NAME}
|
||||
statuses = store.statuses()
|
||||
configured = configured or {}
|
||||
problems = []
|
||||
@@ -260,12 +309,18 @@ def build_dashboard(store: Any, *, kind: str, anchor: date, today: date,
|
||||
|
||||
m_qs = "" if len(codes) == len(all_codes) else "".join(f"&m={c}" for c in codes)
|
||||
table = calc.main_table(period, codes, cells, today=today, holidays=holidays)
|
||||
# 일 합계 = 카페24(실적) + 공동구매 + 나머지(2026-11-02) — 공동구매를 필터로 뺐으면 실적 + 나머지.
|
||||
# 일 합계 ROAS 도 이 값 기준이라 _ad_lines 앞에서.
|
||||
for r, s in zip(table, calc.main_table(period, codes, summary, today=today, holidays=holidays)):
|
||||
r["total"] = s["total"]
|
||||
if "cafe24" in codes:
|
||||
r["cells"][CAFE24_EX_GB] = s["cells"]["cafe24"]
|
||||
_ad_lines(store, table, codes, cells, period, q_start, q_end)
|
||||
for r in table:
|
||||
for g, members in group_members.items():
|
||||
r["cells"][g] = calc.total(calc.Money(gross=r["cells"][c]["gross"], commission=r["cells"][c]["commission"])
|
||||
for c in members).as_dict()
|
||||
_cafe24_ex_gb_column(markets, codes, cols, names, short, table)
|
||||
_cafe24_real_column(cols, names, short, gb)
|
||||
|
||||
def url(kind: str, anchor_d: date | None = None, start: date | None = None, end: date | None = None) -> str:
|
||||
if kind == "custom":
|
||||
@@ -305,10 +360,11 @@ def build_dashboard(store: Any, *, kind: str, anchor: date, today: date,
|
||||
"selected_all": len(codes) == len(all_codes),
|
||||
"kpis": kpis,
|
||||
"table": table,
|
||||
"month": calc.month_summary(month_period.start.year, month_period.start.month, codes, cells),
|
||||
"year": calc.year_months(year_period.start.year, codes, cells, today=today),
|
||||
"chart_daily": calc.daily_series(period, codes, cells),
|
||||
"chart_share": [{"code": c, "name": names[c], **share[c].as_dict()} for c in codes],
|
||||
"summary_names": summary_names,
|
||||
"month": calc.month_summary(month_period.start.year, month_period.start.month, codes, summary),
|
||||
"year": calc.year_months(year_period.start.year, codes, summary, today=today),
|
||||
"chart_daily": calc.daily_series(period, codes, summary),
|
||||
"chart_share": [{"code": c, "name": summary_names[c], **share[c].as_dict()} for c in codes],
|
||||
"problems": problems,
|
||||
"manual_codes": manual_codes,
|
||||
"manual_cells": manual_cells,
|
||||
@@ -325,7 +381,7 @@ def build_dashboard(store: Any, *, kind: str, anchor: date, today: date,
|
||||
|
||||
|
||||
def _short_name(name: str) -> str:
|
||||
return {"네이버 스마트스토어": "네이버", "토스쇼핑": "토스"}.get(name, name)
|
||||
return {"네이버 스마트스토어": "네이버", "토스쇼핑": "토스", "카페24": "카페24(전체)"}.get(name, name)
|
||||
|
||||
|
||||
def build_settings(store: Any, *, configured: Mapping[str, bool], key_info: Mapping[str, Any],
|
||||
@@ -381,7 +437,14 @@ def build_settings(store: Any, *, configured: Mapping[str, bool], key_info: Mapp
|
||||
else:
|
||||
blocks.append({"row": r, "children": []})
|
||||
stale = {v: n for v, n in key_versions_in_use.items() if key_info.get("current_version") and v != key_info["current_version"]}
|
||||
return {"rows": rows, "blocks": blocks, "groups": groups,
|
||||
# "매출 실적 표 열 숨기기" 목록 = 매출 실적 표에 나오는 열(그룹 열은 하위를 다 숨기면 사라진다)
|
||||
hide_options: list[dict[str, str]] = []
|
||||
for r in rows:
|
||||
if not r["is_group"] and r["enabled"] and r["include_in_sales"]:
|
||||
hide_options.append({"code": r["code"], "name": _short_name(r["name"])})
|
||||
if r["code"] == "cafe24":
|
||||
hide_options.append({"code": CAFE24_EX_GB, "name": CAFE24_REAL_NAME})
|
||||
return {"rows": rows, "blocks": blocks, "groups": groups, "hide_options": hide_options, "hidden_codes": load_hidden(store),
|
||||
"custom_ready": bool(store_rows) and "is_custom" in store_rows[0],
|
||||
"key_info": key_info, "key_versions_in_use": dict(key_versions_in_use),
|
||||
"stale_key_rows": sum(stale.values()), "sample_count": sample_count,
|
||||
|
||||
Reference in New Issue
Block a user