diff --git a/app/modules/performance/CLAUDE.md b/app/modules/performance/CLAUDE.md index 812c775..21acbf3 100644 --- a/app/modules/performance/CLAUDE.md +++ b/app/modules/performance/CLAUDE.md @@ -64,8 +64,12 @@ 직접 추가 쇼핑몰만 그룹 select 로 묶음, 이름 변경·삭제(삭제 = 그 쇼핑몰 수동 입력·수수료도). 매출 실적 표 그룹 열 = 보이는 하위 합계(일 합계엔 안 더함), ▾/▸ 하위 열 접기(localStorage). ⠿ 드래그 → `PUT /api/marketplace-order` → `sort_order`, 화면 순서는 `dashboard.ordered_marketplaces` (그룹 바로 뒤 하위) 한 곳. 상세 `docs/PERFORMANCE_MODULE.md` "직접 추가 쇼핑몰·그룹". -- **카페24(공구 제외) 열**(2026-10-30) — 직접 추가 쇼핑몰 "카페24 공동구매"(이름으로 찾음, 띄어쓰기 무시) 바로 오른쪽에 카페24 − 공동구매 계산 열 - (`dashboard._cafe24_ex_gb_column`, kind `diff`, 표 열만 — 일 합계엔 안 더함, 클릭·메모 없음). 공동구매 칸을 저장하면 그 줄 차이 칸이 바로 바뀜(`performance.js saveManual`, td `data-diff-minus`·`data-base`), 합계 줄은 입력 마친 뒤 새로고침 때. 상세 `docs/PERFORMANCE_MODULE.md` "직접 추가 쇼핑몰·그룹". +- **카페24(전체)·카페24(실적) 열**(2026-11-02, 예전 "공구 제외") — 카페24 열 이름 = 카페24(전체)(`_short_name`), 바로 오른쪽 카페24(실적) = 카페24 − 직접 추가 쇼핑몰 "자사몰(공동구매)"("카페24 공동구매"도, 이름으로 찾음·띄어쓰기 무시 — 없으면 전체 그대로, 쇼핑몰 필터·숨김과 무관하게 뺌). + 광고비 줄은 카페24(전체)와 같은 구글·메타(`dashboard._cafe24_real_column`, kind `diff`, 표 열만 — 일 합계엔 안 더함, 클릭·메모 없음). 공동구매 칸을 저장하면 그 줄 칸이 바로 바뀜(`performance.js saveManual`, td `data-diff-minus`·`data-base`), 합계 줄은 입력 마친 뒤 새로고침 때. 상세 `docs/PERFORMANCE_MODULE.md` "직접 추가 쇼핑몰·그룹". +- **합계 기준**(2026-11-02) — 일 합계 = 카페24(실적) + 공동구매 + 나머지 쇼핑몰(카페24(전체)는 안 더함 — 공동구매가 들어 있어 중복). 일 합계·ROAS·KPI·추이·비중·월/연 누적 모두 `dashboard._summary_cells`(카페24 칸 = 실적, 그래프·누적의 카페24 줄 이름도 `summary_names` = 카페24(실적)), 표의 카페24(전체) 열만 원래 값. 광고비 탭 매출 대비 광고비·합계 ROAS = `total_sales_codes`(카페24 있으면 공동구매 코드 뺌, 같은 금액). **프로젝트 회의록 머리 카드는 아직 예전 합계**(`project/router.py` `total` — 공동구매 중복). +- **매출 실적 표 열 숨기기**(2026-11-02) — 실적 설정 "공통 보기 설정" 카드(관리자만, `PUT /api/hidden-marketplaces`, `perf_settings` key `hidden_marketplaces`, 011 미적용 503) → **모든 사용자에게 적용**. **열만** 숨김(`dashboard.load_hidden`) — 일 합계·KPI·그래프·누적은 그대로, 그룹 열 = 보이는 하위 합계(다 숨기면 그룹 열도 없음). 쇼핑몰 필터(합계까지 바뀜)와 다름. 광고비 탭은 적용 안 함. +- **일 합계 열 위치**(2026-11-02) — 매출 실적·광고비 표 모두 날짜 바로 오른쪽, 날짜 열과 함께 가로 고정(왼쪽 위치 `--perf-label-w` = 날짜 열 너비, `performance.js stickyHead`). +- **기간 이동**(2026-11-02, `_period_nav.html` 공통) — 날짜 바로 좌우 화살표 SVG(글자 높이, 진한 회색), 글자 버튼 없음. - **매출 실적 표 모양(2026-10-22)** — `table.perf-autofit`(매출 탭만, 모든 기간 같음): 표가 100% 로 늘지 않고 **열 너비 = 내용 길이**, 날짜 열은 고정 210px 대신 자동 + **가로 스크롤해도 고정**(sticky left, 오른쪽 그림자). 그룹 열 = 진한 보라 머리·왼쪽 묶음 선, 하위 열 = 옅은 보라 머리(위 띠)·옅은 칸, 마지막 하위(`is-glast`, 접히면 그룹 열 `is-gclosed`) = 오른쪽 선. 접기 단추 = 22px ⊟/⊞(SVG, 세로 막대가 돌아 바뀜). 접기·펴기 애니메이션 = 하위 칸 내용 `.perf-gc` 너비·칸 여백·투명도 260ms(`setGroup(code, fold, animate)`, @@ -86,7 +90,7 @@ 수동 = 매출 실적·광고비 일자별 표에 `perf-colw-manual` → `performance.js initColWidths` 가 자동 너비를 잰 뒤 `table-layout:fixed`(`is-colw-fixed`, 넘치는 글자 …), 머리글 오른쪽 경계 `.perf-colw-grip` 드래그(최소 36px)·두 번 누르면 그 열만 자동. **날짜 열(`label`)은 조절 불가 — 늘 자동 너비, 손잡이 없음, 저장값 무시**. 너비 = localStorage `perf_colw_sales`/`perf_colw_ads`(th `data-col` = 쇼핑몰·채널 코드·`label`·`total`)에 계속 유지, 설정 [조절한 너비 초기화]가 둘 다 지움. 그룹 접기·펴기 때 열 너비도 함께 움직임(`colw.animate/settle`). 테스트 `tests/js/perf_colw.browser.test.js`. -- **매출 단위** 원·천원·백만원 — 설정 "보기 설정"(누구나, 이 브라우저 쿠키 `perf_unit`), 서버가 `amount_text`(천원 정수·백만원 소수 한 자리)로 그림(`router._unit_ctx` → 템플릿 `amt`). 광고비 탭은 원 그대로. +- **매출 단위** 원·천원·백만원(2026-11-02 모든 사용자 공통) — 설정 "공통 보기 설정"(관리자, `PUT /api/display-unit`, `perf_settings` key `display_unit`, 저장 값 없음·011 미적용 = 원, 예전 쿠키 `perf_unit` 은 안 봄), 서버가 `amount_text`(천원 정수·백만원 소수 한 자리)로 그림(`router._unit_ctx` → 템플릿 `amt`). 광고비 탭은 원 그대로. 표 열 너비는 사람(브라우저)마다 그대로. - 설정의 진단 카드(쇼핑몰 원본 데이터 확인·카페24 매출 대조·일별 한 번에 비교)는 2026-10-19 화면에서 뺐다(서버 API `marketplaces/{code}/reconcile`·`daily-check` 는 진단용으로 남김). ## 날짜 칸 메모 (2026-10-22, 마이그레이션 010 `perf_cell_memos`) diff --git a/app/modules/performance/dashboard.py b/app/modules/performance/dashboard.py index 45d539f..efe2148 100644 --- a/app/modules/performance/dashboard.py +++ b/app/modules/performance/dashboard.py @@ -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, diff --git a/app/modules/performance/router.py b/app/modules/performance/router.py index 5467f94..6fdd1c4 100644 --- a/app/modules/performance/router.py +++ b/app/modules/performance/router.py @@ -29,6 +29,8 @@ JSON API — 관리자 POST /performance/api/marketplaces 쇼핑몰(수동 입력 전용)·그룹 직접 추가(009) DELETE /performance/api/marketplaces/{code} 직접 추가 쇼핑몰·그룹 삭제(그 쇼핑몰 수동 입력·수수료도) PUT /performance/api/marketplace-order 쇼핑몰 순서(설정 드래그 — 매출 실적 열 순서) + PUT /performance/api/hidden-marketplaces 매출 실적 표 열 숨기기(모든 사용자에게 적용) + PUT /performance/api/display-unit 매출 단위(모든 사용자에게 적용) GET /performance/api/marketplaces/{code}/manual-days 수동 입력해 둔 날 수(삭제 확인 문구) POST /performance/api/marketplaces/{code}/rates 수수료율(적용 시작일) DELETE /performance/api/marketplaces/{code}/rates/{id} @@ -147,7 +149,7 @@ def dashboard_page( ctx["metric"] = metric if metric in ("gross", "commission", "net") else "net" ctx["auto_sync"] = _auto_sync_ctx(store, "sales") ctx["update_watch"] = _update_watch("sales", user) - _unit_ctx(request, ctx) + _unit_ctx(store, ctx) _colw_ctx(request, ctx) return render_template(request, "performance/index.html", {**common.base_ctx(user, active_tab="dashboard"), **ctx}) @@ -198,11 +200,11 @@ def api_update_status(request: Request, kind: str = "sales") -> JSONResponse: "user": job.user if job else ""}) -def _unit_ctx(request: Request, ctx: dict[str, Any]) -> None: - """매출 단위(원·천원·백만원) — 실적 설정 "보기 설정"이 이 브라우저 쿠키(perf_unit)에 둔다. 템플릿은 amt(v) 로 그린다.""" - from .dashboard import UNIT_COOKIE, UNITS, amount_text, normalize_unit # noqa: WPS433 +def _unit_ctx(store: Any, ctx: dict[str, Any]) -> None: + """매출 단위(원·천원·백만원) — 관리자가 실적 설정 "공통 보기 설정"에서 정하면 모든 사용자에게 같게. 템플릿은 amt(v) 로 그린다.""" + from .dashboard import UNITS, amount_text, load_unit # noqa: WPS433 - unit = normalize_unit(request.cookies.get(UNIT_COOKIE)) + unit = load_unit(store) ctx["unit"] = unit ctx["unit_label"] = UNITS[unit][2] ctx["amt"] = lambda v: amount_text(v, unit) @@ -231,13 +233,13 @@ def ads_page( return g store, user = g from .ad_spend import build_ad_dashboard # noqa: WPS433 - from .dashboard import _sales_marketplaces # noqa: WPS433 + from .dashboard import _sales_marketplaces, total_sales_codes # noqa: WPS433 today = today_kst() ctx = build_ad_dashboard( store, kind=period, anchor=_parse_date(d) or today, today=today, custom_from=_parse_date(from_), custom_to=_parse_date(to), holidays=_holidays(), - sales_codes=[m["code"] for m in _sales_marketplaces(store)], + sales_codes=total_sales_codes(_sales_marketplaces(store)), ) # [광고비 업데이트](2026-10-20) — 관리자가 실적 설정에서 인증정보를 넣은 광고 연동 전부를 진행 창으로. # 마지막 업데이트 = 광고 API 마지막 성공 가져오기, 다음 업데이트 = 매출 자동 업데이트와 같은 회차. @@ -283,7 +285,7 @@ def settings_page(request: Request): ctx["ad_sources"] = _ad_source_rows(store, ad_sync.configured()) ctx["ad_api_ready"] = store.ad_api_ready() ctx["auto_sync_settings"] = _auto_sync_settings_ctx(store) # 카드는 관리자에게만(템플릿) - _unit_ctx(request, ctx) + _unit_ctx(store, ctx) _colw_ctx(request, ctx) return render_template(request, "performance/settings.html", {**common.base_ctx(user, active_tab="settings", page_title="실적 설정"), **ctx}) @@ -954,6 +956,44 @@ def api_marketplace_order(request: Request, payload: dict[str, Any] = Body(...)) return JSONResponse({"ok": True}) +@router.put("/api/hidden-marketplaces") +def api_hidden_marketplaces(request: Request, payload: dict[str, Any] = Body(...)) -> JSONResponse: + """매출 실적 표 열 숨기기(2026-11-02, 관리자, 마이그레이션 011) — 체크한 코드 전부. 모든 사용자의 표에 적용.""" + from .dashboard import CAFE24_EX_GB, HIDDEN_SETTING # noqa: WPS433 + + store, user = common.require_store(request, admin=True) + raw = payload.get("codes") + if not isinstance(raw, list): + raise HTTPException(status_code=400, detail="숨길 쇼핑몰 목록이 필요합니다.") + known = {m["code"] for m in store.list_marketplaces()} | {CAFE24_EX_GB} + codes = sorted({str(c) for c in raw} & known) + _save_shared_setting(store, HIDDEN_SETTING, codes, user) + return JSONResponse({"ok": True, "codes": codes}) + + +@router.put("/api/display-unit") +def api_display_unit(request: Request, payload: dict[str, Any] = Body(...)) -> JSONResponse: + """매출 단위(2026-11-02, 관리자, 마이그레이션 011) — won·thousand·million. 모든 사용자의 매출 실적 화면에 적용.""" + from .dashboard import UNIT_SETTING, UNITS # noqa: WPS433 + + store, user = common.require_store(request, admin=True) + unit = payload.get("unit") + if not isinstance(unit, str) or unit not in UNITS: + raise HTTPException(status_code=400, detail="알 수 없는 매출 단위입니다.") + _save_shared_setting(store, UNIT_SETTING, unit, user) + return JSONResponse({"ok": True, "unit": unit}) + + +def _save_shared_setting(store: Any, key: str, value: Any, user: dict[str, Any]) -> None: + from .db import SettingsMigrationNeeded # noqa: WPS433 + + try: + store.set_setting(key, value, user=user.get("email", "")) + except SettingsMigrationNeeded: + raise HTTPException(status_code=503, detail="저장하려면 performance_db 마이그레이션 011" + "(scripts/sql/performance_db_011_settings.sql)을 먼저 적용해야 합니다.") from None + + @router.put("/api/marketplaces/{code}") def api_update_marketplace(request: Request, code: str, payload: dict[str, Any] = Body(...)) -> JSONResponse: store, _ = common.require_store(request, admin=True) diff --git a/app/modules/performance/templates/performance/_period_nav.html b/app/modules/performance/templates/performance/_period_nav.html new file mode 100644 index 0000000..46afa7a --- /dev/null +++ b/app/modules/performance/templates/performance/_period_nav.html @@ -0,0 +1,6 @@ +{# 기간 이동(2026-11-02, 매출 실적·광고비 공통) — 날짜 바로 좌우에 화살표 이미지(SVG, 글자 높이), 글자 버튼 없음 #} +
diff --git a/app/modules/performance/templates/performance/ads.html b/app/modules/performance/templates/performance/ads.html index 0e24291..9ef77a1 100644 --- a/app/modules/performance/templates/performance/ads.html +++ b/app/modules/performance/templates/performance/ads.html @@ -1,6 +1,6 @@ {% extends "erp_base.html" %} -{% block head_extra %}{% endblock %} +{% block head_extra %}{% endblock %} {#- ROAS 덧붙임 — "광고비(ROAS%)". 광고비가 없으면 아무것도 안 붙는다. -#} {%- macro roas(p) -%}{%- if p is not none -%}({{ "{:,}".format(p) }}%){%- endif -%}{%- endmacro -%} @@ -24,11 +24,7 @@ - + {% include "performance/_period_nav.html" %}