Merge branch 'fix/ad-roas-no-google-meta'

This commit is contained in:
2026-10-14 11:10:10 +09:00
5 changed files with 24 additions and 16 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+15 -8
View File
@@ -41,9 +41,11 @@ CHANNELS: tuple[tuple[str, str], ...] = (
)
CHANNEL_NAMES = dict(CHANNELS)
CHANNEL_CODES = tuple(c for c, _ in CHANNELS)
# ROAS(매출 ÷ 광고비 × 100) 의 매출 = 이 쇼핑몰 매출 실적 총매출. 구글·메타는 자체몰(카페24)로 보내는 광고라 카페24 매출.
ROAS_SALES_CODE: dict[str, str] = {c: c for c in CHANNEL_CODES}
ROAS_SALES_CODE.update({"google": "cafe24", "meta": "cafe24", "coupang_wing": "coupang"})
# ROAS(매출 ÷ 광고비 × 100) 의 매출 = 이 쇼핑몰 매출 실적 총매출. 쿠팡(윙)은 매출 쪽 코드가 coupang.
# 구글·메타는 ROAS 를 계산하지 않는다 — ROAS 값을 따로 넣는다(2026-10-14 사용자 요청).
NO_ROAS = frozenset({"google", "meta"})
ROAS_SALES_CODE: dict[str, str] = {c: c for c in CHANNEL_CODES if c not in NO_ROAS}
ROAS_SALES_CODE["coupang_wing"] = "coupang"
def roas(sales: int, spend: int) -> int | None:
@@ -54,9 +56,14 @@ def roas(sales: int, spend: int) -> int | None:
def roas_basis(code: str) -> str:
"""머리글 말풍선 — ROAS 에 쓰는 매출."""
sales = ROAS_SALES_CODE[code]
return "카페24(자체몰)" if sales == "cafe24" else CHANNEL_NAMES.get(code, code)
"""머리글 말풍선 — ROAS 에 쓰는 매출(구글·메타는 빈 값 = 계산 안 함)."""
return "" if code not in ROAS_SALES_CODE else CHANNEL_NAMES.get(code, code)
def channel_roas(code: str, sales_of: Callable[[str], int], spend: int) -> int | None:
"""채널 칸의 ROAS — 구글·메타는 늘 None(계산 안 함)."""
mcode = ROAS_SALES_CODE.get(code)
return None if mcode is None else roas(sales_of(mcode), spend)
ROCKET_DATE_COL = 0 # 1열 날짜
ROCKET_AMOUNT_COL = 18 # 19열 청구금액(+부가가치세)
@@ -250,11 +257,11 @@ def build_ad_dashboard(store: Any, *, kind: str, anchor: date, today: date,
for row in table:
s = date.fromisoformat(row["from"]) if row.get("from") else period.start
e = date.fromisoformat(row["to"]) if row.get("to") else period.end
row["roas"] = {c: roas(sales_sum([ROAS_SALES_CODE[c]], s, e), row["cells"][c]["gross"]) for c in codes}
row["roas"] = {c: channel_roas(c, lambda m: sales_sum([m], s, e), row["cells"][c]["gross"]) for c in codes}
row["roas_total"] = roas(sales_sum(total_codes, s, e), row["total"]["gross"]) if total_codes else None
m_s, m_e = month_period.start, month_period.end
for r in month["rows"]:
r["roas"] = roas(sales_sum([ROAS_SALES_CODE[r["code"]]], m_s, m_e), r["gross"])
r["roas"] = channel_roas(r["code"], lambda m: sales_sum([m], m_s, m_e), r["gross"])
month["total"]["roas"] = roas(sales_sum(total_codes, m_s, m_e), month["total"]["gross"]) if total_codes else None
year = calc.year_months(year_period.start.year, codes, cells, today=today)
for i, r in enumerate(year["rows"], start=1):
@@ -82,7 +82,7 @@
<thead>
<tr>
<th class="perf-th-label">{% if period_kind == 'year' %}월{% else %}날짜{% endif %}</th>
{% for c in codes %}<th title="{{ names[c] }} — 날짜 칸을 눌러 광고비 입력. 괄호 = ROAS({{ roas_basis[c] }} 매출 ÷ 광고비)">{{ names[c] }} <span class="perf-manual-mark" aria-hidden="true">✎</span></th>{% endfor %}
{% for c in codes %}<th title="{{ names[c] }} — 날짜 칸을 눌러 광고비 입력.{% if roas_basis[c] %} 괄호 = ROAS({{ roas_basis[c] }} 매출 ÷ 광고비){% else %} ROAS 는 계산하지 않음(따로 입력){% endif %}">{{ names[c] }} <span class="perf-manual-mark" aria-hidden="true">✎</span></th>{% endfor %}
<th class="perf-th-total">{% if period_kind == 'year' %}월 합계{% else %}일 합계{% endif %}</th>
</tr>
</thead>
@@ -111,7 +111,7 @@
</div>
{% if period_kind != 'year' %}
<p class="perf-muted perf-manual-help">날짜 칸을 눌러 그날 <b>광고비</b>를 직접 입력합니다 — Enter 저장 후 아래 칸, Esc 취소, 비우고 저장하면 지움.
칸은 <b>광고비(ROAS%)</b> — ROAS = 그 쇼핑몰 매출 실적 총매출 ÷ 광고비(구글·메타는 카페24 자체몰 매출, 합계 열은 전체 매출).
칸은 <b>광고비(ROAS%)</b> — ROAS = 그 쇼핑몰 매출 실적 총매출 ÷ 광고비(합계 열은 전체 매출). 구글·메타는 ROAS 를 계산하지 않습니다.
파란 숫자 = 직접 입력, 주황 숫자 = 파일 업로드 값. 쿠팡(윙)·쿠팡(로켓)은 [파일 업로드]로 광고 보고서를 올리면 날짜별로 한 번에 들어갑니다.</p>
{% endif %}
</div>
@@ -190,7 +190,7 @@
</div>
<p class="perf-foot perf-muted">
광고비 기준: 쿠팡(윙)·쿠팡(로켓)은 광고 보고서의 청구금액(+부가가치세). ROAS = 매출 ÷ 광고비 × 100(구글·메타 = 카페24 자체몰 매출).
광고비 기준: 쿠팡(윙)·쿠팡(로켓)은 광고 보고서의 청구금액(+부가가치세). ROAS = 그 쇼핑몰 매출 ÷ 광고비 × 100(구글·메타는 계산 안 함).
매출 대비 광고비 = 같은 기간 광고비 ÷ 매출 실적 총매출.
구글·메타는 지금은 직접 입력합니다.
</p>
@@ -104,14 +104,15 @@ def test_ad_dashboard_month():
# ROAS = 그 쇼핑몰 매출 ÷ 광고비 — 로켓 10/1: 550,000 ÷ 220,000 = 250%, 구글 10/2: 카페24 그날 매출 0 → 0%
assert day1["roas"]["coupang_rocket"] == 250 and day1["roas"]["google"] is None
day2 = next(r for r in ctx["table"] if r.get("date") == "2026-10-02")
assert day2["roas"]["google"] == 0
assert day2["roas"]["google"] is None # 구글·메타는 ROAS 계산 안 함(따로 입력)
total = ctx["table"][-1]
assert total["roas"]["coupang_rocket"] == 300 and total["roas"]["google"] == 5400 # 660,000÷220,000 · 2,700,000÷50,000
assert total["roas"]["coupang_rocket"] == 300 and total["roas"]["google"] is None # 660,000÷220,000
assert total["roas_total"] == 1000 # 2,700,000 ÷ 270,000 (합계 = sales_codes)
m = {r["code"]: r for r in ctx["month"]["rows"]}
assert m["coupang_rocket"]["roas"] == 300 and m["naver"]["roas"] is None and ctx["month"]["total"]["roas"] == 1000
assert ctx["year"]["rows"][9]["roas"] == 1000 and ctx["year"]["rows"][10]["roas"] is None # 11월 = 앞으로
assert ctx["roas_basis"]["google"] == "카페24(자체몰)" and ctx["roas_basis"]["coupang_wing"] == "쿠팡(윙)"
assert ctx["roas_basis"]["google"] == "" and ctx["roas_basis"]["coupang_wing"] == "쿠팡(윙)"
assert {r["code"]: r for r in ctx["month"]["rows"]}["google"]["roas"] is None
assert ads.roas(1, 3) == 33 and ads.roas(1, 200) == 1 and ads.roas(5, 0) is None # 0.5% 반올림 → 1
assert ctx["nav"]["quick"][2]["active"] # 이번달
+1 -1
View File
@@ -345,7 +345,7 @@
연간은 월)·일별 추이·채널 비중·월/연 누적. 채널(2026-10-14) = 구글·메타·네이버·쿠팡(윙)·쿠팡(로켓)·오늘의집·G마켓·카카오·GS샵·11번가·롯데ON·토스·애터미아자몰
(`ad_spend.CHANNELS`, 앱이 정함 — 쇼핑몰 채널 코드는 실적 쇼핑몰 코드와 같고 쿠팡(윙)만 `coupang_wing`).
모든 칸 직접 입력 가능, 칸 표시 = **광고비(ROAS%)** — ROAS = 그 칸 기간의 매출 실적 총매출 ÷ 광고비 × 100(정수 반올림,
`ad_spend.roas`). 매출 쇼핑몰 = `ROAS_SALES_CODE`(같은 쇼핑몰, 쿠팡(윙) = `coupang`, **구글·메타 = 카페24 자체몰**),
`ad_spend.roas`). 매출 쇼핑몰 = `ROAS_SALES_CODE`(같은 쇼핑몰, 쿠팡(윙) = `coupang`). **구글·메타는 ROAS 계산 안 함**(`NO_ROAS` — ROAS 값을 따로 넣을 예정, 2026-10-14),
합계 열·월/연 누적 = 매출 실적에 들어가는 쇼핑몰 전체 매출. 광고비가 없는 칸은 ROAS 없음. 광고비를 고치면 옛 ROAS 는 지우고 새로고침 때 다시 계산.
KPI: 기간 광고비(전기간 대비), 매출 대비 광고비(같은 기간 광고비 ÷ 매출 실적 총매출), 월·연 누적.
저장 `perf_ad_spend`(마이그레이션 005 — 채널 × 날짜 하나에 금액, `source` manual/upload/api), 미적용이면 화면에 안내·API 503.