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:
@@ -6,11 +6,12 @@ import importlib
|
||||
from datetime import date
|
||||
|
||||
import pytest
|
||||
from fastapi import FastAPI
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from app.modules.performance import common, dashboard
|
||||
from app.modules.performance.adapters.registry import get_adapter
|
||||
from app.modules.performance.db import SettingsMigrationNeeded
|
||||
|
||||
TODAY = date(2026, 10, 7)
|
||||
|
||||
@@ -36,6 +37,13 @@ class _Store:
|
||||
(date(2026, 10, 6), "custom_a"): 7_000}
|
||||
self.order = None
|
||||
self.deleted = []
|
||||
self.settings = {}
|
||||
|
||||
def get_setting(self, key):
|
||||
return self.settings.get(key)
|
||||
|
||||
def set_setting(self, key, value, *, user=""):
|
||||
self.settings[key] = value
|
||||
|
||||
def list_marketplaces(self):
|
||||
return sorted((dict(r) for r in self.rows), key=lambda r: (r["sort_order"], r["code"]))
|
||||
@@ -113,8 +121,8 @@ def test_dashboard_group_column_sums_children_without_double_count():
|
||||
ctx = dashboard.build_dashboard(_Store(), kind="week", anchor=TODAY, today=TODAY)
|
||||
assert ctx["codes"] == ["cafe24", "naver", "custom_b", "custom_a", "custom_c"]
|
||||
assert [(c["code"], c["kind"]) for c in ctx["cols"]] == [
|
||||
("cafe24", "shop"), ("naver", "shop"), ("group_x", "group"), ("custom_b", "child"), ("custom_a", "child"),
|
||||
("custom_c", "shop")]
|
||||
("cafe24", "shop"), (dashboard.CAFE24_EX_GB, "diff"), ("naver", "shop"), ("group_x", "group"), ("custom_b", "child"),
|
||||
("custom_a", "child"), ("custom_c", "shop")]
|
||||
assert ctx["group_members"] == {"group_x": ["custom_b", "custom_a"]}
|
||||
assert ctx["names"]["group_x"] == "오프라인"
|
||||
day5 = next(r for r in ctx["table"] if r.get("date") == "2026-10-05")
|
||||
@@ -127,7 +135,7 @@ def test_dashboard_group_column_sums_children_without_double_count():
|
||||
|
||||
def test_dashboard_filter_hides_group_when_no_child_selected():
|
||||
ctx = dashboard.build_dashboard(_Store(), kind="week", anchor=TODAY, today=TODAY, selected=["cafe24", "custom_c"])
|
||||
assert [c["code"] for c in ctx["cols"]] == ["cafe24", "custom_c"] and ctx["group_members"] == {}
|
||||
assert [c["code"] for c in ctx["cols"]] == ["cafe24", dashboard.CAFE24_EX_GB, "custom_c"] and ctx["group_members"] == {}
|
||||
ctx = dashboard.build_dashboard(_Store(), kind="week", anchor=TODAY, today=TODAY, selected=["custom_a"])
|
||||
assert [c["kind"] for c in ctx["cols"]] == ["group", "child"]
|
||||
day5 = next(r for r in ctx["table"] if r.get("date") == "2026-10-05")
|
||||
@@ -223,36 +231,152 @@ def test_dashboard_page_renders_group_header_and_child_cells(client):
|
||||
assert 'data-group-child="group_x" data-manual-code="custom_a" data-date="2026-10-05"' in body
|
||||
|
||||
|
||||
def test_cafe24_minus_groupbuy_column():
|
||||
"""'카페24 공동구매' 바로 오른쪽 = 카페24 − 공동구매(2026-10-30). 표 열만 — 일 합계엔 안 더함."""
|
||||
def _real(ctx, date_iso):
|
||||
return next(r for r in ctx["table"] if r.get("date") == date_iso)["cells"][dashboard.CAFE24_EX_GB]
|
||||
|
||||
|
||||
def test_cafe24_real_column():
|
||||
"""카페24(실적) = 카페24(전체) 바로 오른쪽, 카페24 − 자사몰(공동구매). 표 열만 — 일 합계엔 안 더함."""
|
||||
st = _Store()
|
||||
st._find("custom_c")["name"] = "카페24 공동구매"
|
||||
# 공동구매 없음 = 전체 그대로
|
||||
ctx = dashboard.build_dashboard(st, kind="week", anchor=TODAY, today=TODAY)
|
||||
assert _real(ctx, "2026-10-05")["gross"] == 1_000_000
|
||||
assert ctx["short_names"]["cafe24"] == "카페24(전체)" and ctx["short_names"][dashboard.CAFE24_EX_GB] == "카페24(실적)"
|
||||
|
||||
st._find("custom_c")["name"] = "자사몰 (공동구매)"
|
||||
st._find("custom_c")["parent_code"] = "group_x"
|
||||
st.manual[(date(2026, 10, 5), "custom_c")] = 300_000
|
||||
ctx = dashboard.build_dashboard(st, kind="week", anchor=TODAY, today=TODAY)
|
||||
assert [c["code"] for c in ctx["cols"]][-2:] == ["custom_c", dashboard.CAFE24_EX_GB]
|
||||
assert [c["code"] for c in ctx["cols"]][:2] == ["cafe24", dashboard.CAFE24_EX_GB]
|
||||
assert ctx["cols"][1] == {"code": dashboard.CAFE24_EX_GB, "kind": "diff", "group": "", "base": "cafe24", "minus": "custom_c"}
|
||||
assert _real(ctx, "2026-10-05") == {"gross": 700_000, "commission": 0, "net": 700_000}
|
||||
day5 = next(r for r in ctx["table"] if r.get("date") == "2026-10-05")
|
||||
assert day5["cells"][dashboard.CAFE24_EX_GB] == {"gross": 700_000, "commission": 0, "net": 700_000}
|
||||
assert day5["total"]["gross"] == 1_450_000 # 카페24 + 매장 150,000 + 공동구매 300,000
|
||||
# 일 합계 = 카페24(실적) 700,000 + 공동구매 300,000 + 매장 150,000 — 카페24(전체) 1,000,000 은 안 더함
|
||||
assert day5["total"] == {"gross": 1_150_000, "commission": 10_000, "net": 1_140_000}
|
||||
week = next(r for r in ctx["table"] if r["kind"] == "week")
|
||||
assert week["cells"][dashboard.CAFE24_EX_GB]["gross"] == 700_000
|
||||
assert week["total"]["gross"] == 1_157_000 # 주간합계도 같은 규칙(매장 157,000)
|
||||
|
||||
# 카페24 를 고르지 않으면 열 없음, 공동구매가 그룹 하위면 같은 그룹으로 접힘
|
||||
# 공동구매를 필터로 빼도 실적에서는 뺀다 — 일 합계 = 실적 + 나머지
|
||||
ctx = dashboard.build_dashboard(st, kind="week", anchor=TODAY, today=TODAY, selected=["cafe24"])
|
||||
assert _real(ctx, "2026-10-05")["gross"] == 700_000
|
||||
assert next(r for r in ctx["table"] if r.get("date") == "2026-10-05")["total"]["gross"] == 700_000
|
||||
# 카페24 를 고르지 않으면 열 없음, 일 합계에 공동구매 그대로
|
||||
ctx = dashboard.build_dashboard(st, kind="week", anchor=TODAY, today=TODAY, selected=["custom_c"])
|
||||
assert dashboard.CAFE24_EX_GB not in [c["code"] for c in ctx["cols"]]
|
||||
st._find("custom_c")["parent_code"] = "group_x"
|
||||
assert next(r for r in ctx["table"] if r.get("date") == "2026-10-05")["total"]["gross"] == 300_000
|
||||
|
||||
|
||||
def test_summaries_match_day_total():
|
||||
"""KPI·추이·비중·월/연 누적도 일 합계와 같은 기준 — 공동구매가 두 번 안 들어감, 카페24 줄 = 카페24(실적)."""
|
||||
st = _Store()
|
||||
st._find("custom_c")["name"] = "자사몰(공동구매)"
|
||||
st.manual[(date(2026, 10, 5), "custom_c")] = 300_000
|
||||
ctx = dashboard.build_dashboard(st, kind="week", anchor=TODAY, today=TODAY)
|
||||
assert ctx["cols"][-1] == {"code": dashboard.CAFE24_EX_GB, "kind": "diff", "group": "group_x",
|
||||
"base": "cafe24", "minus": "custom_c"}
|
||||
week_total = next(r for r in ctx["table"] if r["kind"] == "week")["total"]
|
||||
assert week_total["gross"] == 1_157_000 # 카페24(전체) 1,000,000 + 매장 157,000
|
||||
assert ctx["kpis"][0]["value"] == week_total["net"]
|
||||
assert next(p for p in ctx["chart_daily"] if p["date"] == "2026-10-05")["gross"] == 1_150_000
|
||||
assert sum(s["gross"] for s in ctx["chart_share"]) == 1_157_000
|
||||
assert next(s for s in ctx["chart_share"] if s["code"] == "cafe24")["name"] == "카페24(실적)"
|
||||
assert ctx["month"]["total"]["gross"] == 1_157_000 and ctx["year"]["total"]["gross"] == 1_157_000
|
||||
assert next(r for r in ctx["month"]["rows"] if r["code"] == "cafe24")["gross"] == 700_000
|
||||
assert ctx["year"]["rows"][9]["gross"] == 1_157_000
|
||||
# 카페24(전체) 열은 원래 값 그대로, 공동구매 열도 그대로
|
||||
day5 = next(r for r in ctx["table"] if r.get("date") == "2026-10-05")
|
||||
assert day5["cells"]["cafe24"]["gross"] == 1_000_000 and day5["cells"]["custom_c"]["gross"] == 300_000
|
||||
|
||||
|
||||
def test_dashboard_page_renders_cafe24_minus_groupbuy(client):
|
||||
client.store._find("custom_c")["name"] = "카페24 공동구매"
|
||||
def test_total_sales_codes_drops_groupbuy_only_with_cafe24():
|
||||
m = lambda c, n: {"code": c, "name": n} # noqa: E731
|
||||
assert dashboard.total_sales_codes([m("cafe24", "카페24"), m("x", "자사몰 (공동구매)"), m("y", "네이버")]) == ["cafe24", "y"]
|
||||
assert dashboard.total_sales_codes([m("x", "자사몰(공동구매)"), m("y", "네이버")]) == ["x", "y"]
|
||||
assert dashboard.total_sales_codes([m("cafe24", "카페24"), m("y", "네이버")]) == ["cafe24", "y"]
|
||||
|
||||
|
||||
def test_day_total_roas_uses_real_total():
|
||||
"""일 합계 ROAS = 일 합계 금액(공동구매 중복 없음) ÷ 일 합계 광고비."""
|
||||
st = _Store()
|
||||
st._find("custom_c")["name"] = "자사몰(공동구매)"
|
||||
st.manual[(date(2026, 10, 5), "custom_c")] = 300_000
|
||||
st.ad_amounts = lambda s, e: ({(date(2026, 10, 5), "google"): 115_000}, {})
|
||||
ctx = dashboard.build_dashboard(st, kind="week", anchor=TODAY, today=TODAY)
|
||||
day5 = next(r for r in ctx["table"] if r.get("date") == "2026-10-05")
|
||||
assert day5["ads_total"]["amount"] == 115_000 and day5["ads_total"]["roas"] == 1000 # 1,150,000 ÷ 115,000
|
||||
|
||||
|
||||
def test_hidden_columns_only_hide_table_columns():
|
||||
"""열 숨기기(모든 사용자 공통 설정) — 열만 숨김, 일 합계·그래프 그대로. 하위를 다 숨기면 그룹 열도 없음."""
|
||||
st = _Store()
|
||||
st.settings[dashboard.HIDDEN_SETTING] = ["cafe24", "custom_a", "custom_b"]
|
||||
ctx = dashboard.build_dashboard(st, kind="week", anchor=TODAY, today=TODAY)
|
||||
assert [c["code"] for c in ctx["cols"]] == [dashboard.CAFE24_EX_GB, "naver", "custom_c"]
|
||||
assert _real(ctx, "2026-10-05")["gross"] == 1_000_000 # 전체를 숨겨도 실적은 계산됨
|
||||
assert next(r for r in ctx["table"] if r.get("date") == "2026-10-05")["total"]["gross"] == 1_150_000
|
||||
assert ctx["codes"] == ["cafe24", "naver", "custom_b", "custom_a", "custom_c"]
|
||||
st.settings[dashboard.HIDDEN_SETTING] = [dashboard.CAFE24_EX_GB]
|
||||
ctx = dashboard.build_dashboard(st, kind="week", anchor=TODAY, today=TODAY)
|
||||
assert dashboard.CAFE24_EX_GB not in [c["code"] for c in ctx["cols"]]
|
||||
|
||||
|
||||
def test_hidden_setting_missing_migration_shows_everything():
|
||||
st = _Store()
|
||||
|
||||
def raises(key):
|
||||
raise SettingsMigrationNeeded()
|
||||
|
||||
st.get_setting = raises
|
||||
assert dashboard.load_hidden(st) == set()
|
||||
assert "naver" in [c["code"] for c in dashboard.build_dashboard(st, kind="week", anchor=TODAY, today=TODAY)["cols"]]
|
||||
|
||||
|
||||
def test_api_hidden_marketplaces(client):
|
||||
"""저장값이 그대로 다른 사용자 화면에도 — 쿠키가 아니라 서버 설정(모르는 코드는 버림)."""
|
||||
r = client.put("/performance/api/hidden-marketplaces", json={"codes": ["naver", "ghost", dashboard.CAFE24_EX_GB, "naver"]})
|
||||
assert r.status_code == 200 and r.json()["codes"] == [dashboard.CAFE24_EX_GB, "naver"]
|
||||
assert client.store.settings[dashboard.HIDDEN_SETTING] == [dashboard.CAFE24_EX_GB, "naver"]
|
||||
head = TestClient(client.app).get("/performance/?period=week&d=2026-10-07").text.split("<thead>", 1)[1].split("</thead>", 1)[0]
|
||||
assert 'data-col="naver"' not in head and 'data-col="cafe24"' in head
|
||||
assert client.put("/performance/api/hidden-marketplaces", json={"codes": "naver"}).status_code == 400
|
||||
assert client.put("/performance/api/hidden-marketplaces", json={"codes": []}).json()["codes"] == []
|
||||
|
||||
def raises(key, value, *, user=""):
|
||||
raise SettingsMigrationNeeded()
|
||||
|
||||
client.store.set_setting = raises
|
||||
assert client.put("/performance/api/hidden-marketplaces", json={"codes": []}).status_code == 503
|
||||
|
||||
|
||||
def test_api_hidden_marketplaces_admin_only(client, monkeypatch):
|
||||
def require_store(request, admin=False):
|
||||
if admin:
|
||||
raise HTTPException(status_code=403)
|
||||
return client.store, {"email": "u@x"}
|
||||
|
||||
monkeypatch.setattr(common, "require_store", require_store)
|
||||
assert client.put("/performance/api/hidden-marketplaces", json={"codes": ["naver"]}).status_code == 403
|
||||
assert dashboard.HIDDEN_SETTING not in client.store.settings
|
||||
|
||||
|
||||
def test_dashboard_page_renders_cafe24_real(client):
|
||||
client.store._find("custom_c")["name"] = "자사몰(공동구매)"
|
||||
client.store.manual[(date(2026, 10, 5), "custom_c")] = 300_000
|
||||
client.store.settings[dashboard.HIDDEN_SETTING] = ["naver"]
|
||||
html = client.get("/performance/?period=week&d=2026-10-07").text
|
||||
head = html.split("<thead>", 1)[1].split("</thead>", 1)[0]
|
||||
assert head.index('data-col="custom_c"') < head.index(f'data-col="{dashboard.CAFE24_EX_GB}"')
|
||||
assert "카페24(공구 제외)" in head
|
||||
# 날짜 → 일 합계 → 카페24(전체) → 카페24(실적)
|
||||
assert head.index('data-col="label"') < head.index('data-col="total"') < head.index('data-col="cafe24"') < head.index(f'data-col="{dashboard.CAFE24_EX_GB}"')
|
||||
assert "카페24(전체)" in head and "카페24(실적)" in head and 'data-col="naver"' not in head
|
||||
body = html.split("<tbody>", 1)[1].split("</tbody>", 1)[0]
|
||||
assert "700,000" in body
|
||||
# 일 행만 화면 즉시 계산용 값(카페24 총매출,수수료,차감) — performance.js saveManual
|
||||
assert 'data-diff-minus="custom_c" data-base="1000000,0,1000000"' in body
|
||||
|
||||
|
||||
def test_cafe24_real_shows_same_ad_lines(client):
|
||||
"""카페24(전체)의 구글·메타 광고비 줄이 카페24(실적) 칸에도 그대로."""
|
||||
client.store.ad_amounts = lambda s, e: ({(date(2026, 10, 5), "google"): 11_000, (date(2026, 10, 5), "meta"): 22_000}, {})
|
||||
body = client.get("/performance/?period=week&d=2026-10-07").text.split("<tbody>", 1)[1]
|
||||
row = next(tr for tr in body.split("<tr ") if 'data-date="2026-10-05"' in tr)
|
||||
assert row.count("<i>구글</i>11,000") == 2 and row.count("<i>메타</i>22,000") == 2
|
||||
assert row.index("<i>구글</i>") < row.index("data-code=\"naver\"")
|
||||
|
||||
@@ -121,15 +121,51 @@ def test_dashboard_page_renders_unit_and_ad_lines(monkeypatch):
|
||||
assert 'class="perf-adl"' in html and "<i>구글</i>100,000<em>(413%)</em>" in html and "<i>메타</i>50,000" in html
|
||||
assert "200,000<em>(300%)</em>" in html and "단위:" not in html
|
||||
|
||||
client.cookies.set("perf_unit", "thousand")
|
||||
# 매출 단위 = 서버 공통 설정(2026-11-02) — 예전 브라우저 쿠키는 안 봄
|
||||
client.cookies.set("perf_unit", "million")
|
||||
assert "단위:" not in client.get("/performance/?period=week&d=2026-10-07").text
|
||||
client.cookies.delete("perf_unit")
|
||||
store.get_setting = lambda key: "thousand" if key == dashboard.UNIT_SETTING else None
|
||||
html = client.get("/performance/?period=week&d=2026-10-07").text
|
||||
assert "단위: 천원" in html and "2,000<" in html and "<i>구글</i>100<em>(413%)</em>" in html
|
||||
assert "2,000,000<" not in html.split("perf-main", 1)[1].split("</table>", 1)[0]
|
||||
client.cookies.set("perf_unit", "million")
|
||||
store.get_setting = lambda key: "million" if key == dashboard.UNIT_SETTING else None
|
||||
html = client.get("/performance/?period=week&d=2026-10-07").text
|
||||
assert "단위: 백만원" in html and ">2.0<" in html and '"unit": "million"' in html
|
||||
|
||||
|
||||
def test_api_display_unit(monkeypatch):
|
||||
import importlib
|
||||
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from app.modules.performance import common
|
||||
|
||||
perf_router = importlib.import_module("app.modules.performance.router")
|
||||
saved = {}
|
||||
store = _Store()
|
||||
store.set_setting = lambda key, value, *, user="": saved.__setitem__(key, (value, user))
|
||||
monkeypatch.setattr(common, "require_store", lambda request, admin=False: (store, {"email": "king@x"}))
|
||||
app = FastAPI()
|
||||
app.include_router(perf_router.router)
|
||||
client = TestClient(app)
|
||||
|
||||
assert client.put("/performance/api/display-unit", json={"unit": "thousand"}).json()["unit"] == "thousand"
|
||||
assert saved[dashboard.UNIT_SETTING] == ("thousand", "king@x")
|
||||
assert client.put("/performance/api/display-unit", json={"unit": "nope"}).status_code == 400
|
||||
assert client.put("/performance/api/display-unit", json={"unit": ["won"]}).status_code == 400
|
||||
|
||||
def not_admin(request, admin=False):
|
||||
if admin:
|
||||
raise HTTPException(status_code=403)
|
||||
return store, {"email": "u@x"}
|
||||
|
||||
monkeypatch.setattr(common, "require_store", not_admin)
|
||||
assert client.put("/performance/api/display-unit", json={"unit": "won"}).status_code == 403
|
||||
assert saved[dashboard.UNIT_SETTING] == ("thousand", "king@x")
|
||||
|
||||
|
||||
def test_total_roas_uses_whole_day_total():
|
||||
"""일 합계 ROAS = 그날 일 합계 금액(광고비 없는 쇼핑몰 매출 포함) ÷ 일 합계 광고비 — 예전엔 광고비 있는 쇼핑몰 매출만 더했다."""
|
||||
class _S(_Store):
|
||||
|
||||
Reference in New Issue
Block a user