fix(performance): 메타 광고비에 부가세 1.1 곱하지 않음

- 메타 지출 금액은 이미 부가세 포함(사용자 확인) — 광고비 = 지출 금액 그대로(외화 계정은 × 그날 환율만).
  × 1.1 은 비용이 부가세 별도인 구글만 그대로.
- 일자별 표: "광고비(부가세 포함)"·"지출 금액(부가세 별도)" 두 열 → "지출 금액(부가세 포함)" 한 열.
- 설정·광고비 탭 안내 문구, 문서, 테스트 기대값 갱신.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-16 14:04:57 +09:00
parent 7933f163b4
commit 8051e7f207
6 changed files with 37 additions and 38 deletions
+23 -23
View File
@@ -125,19 +125,19 @@ def test_fetch_days_sums_accounts_pages_and_converts(monkeypatch):
assert {"spend", "action_values", "actions", "account_currency", "date_start"} <= set(q["fields"].split(","))
assert [r.url.params.get("after") for r in seen] == [None, "CUR", None] # 계정 1 두 쪽 → 계정 2
d1, d2 = days
# 10-01: 지출 100,000 + 50,000.5 = 150,000.5 → 광고비(부가세 포함) 165,000.55 → 165,001
# 10-01: 지출 100,000 + 50,000.5 = 150,000.5 → 광고비 = 지출 그대로(메타는 부가세 포함, 2026-10-16) → 150,001
# 구매 전환값 = 계정1 omni_purchase 450,000(겹친 purchase·픽셀 값은 더하지 않음) + 계정2 픽셀 150,000 = 600,000
# ROAS = 600,000 ÷ 150,000.5 × 100 = 399.998... → 400.00
assert (d1.day, d1.amount, d1.roas) == (date(2026, 10, 1), 165001, Decimal("400.00"))
assert (d1.day, d1.amount, d1.roas) == (date(2026, 10, 1), 150001, Decimal("400.00"))
total_metrics = {k: v for k, v in d1.metrics.items() if k != "_accounts"}
assert total_metrics == {"광고비(부가세 포함)": 165001, "지출 금액(부가세 별도)": 150001, "노출수": 25000, "클릭수": 500,
assert total_metrics == {"지출 금액(부가세 포함)": 150001, "노출수": 25000, "클릭수": 500,
"클릭률(%)": 2.0, "링크 클릭": 380, "구매수": 12, "구매 전환값": 600000, "ROAS(%)": 400.0}
assert list(d1.metrics)[:2] == ["광고비(부가세 포함)", "지출 금액(부가세 별도)"] # 일자별 표 열 순서
assert list(d1.metrics)[0] == "지출 금액(부가세 포함)" # 일자별 표 첫 열(× 1.1 없음 — 부가세 별도 열도 없음)
assert (d2.day, d2.amount, d2.roas, d2.metrics["클릭률(%)"]) == (date(2026, 10, 2), 0, None, 0.0) # 지출 0 → ROAS 없음
# 계정별(상세보기 탭, 2026-10-16) — 계정마다 따로 변환. 이름은 insights 의 account_name(없는 쪽은 같은 계정 앞 줄 이름)
a1, a2 = d1.metrics["_accounts"]["1111111111"], d1.metrics["_accounts"]["2222222222"]
assert (a1["name"], a1["amount"], a1["roas"]) == ("본계정", 110000, 450.0) # 100,000 × 1.1, 450,000 ÷ 100,000
assert (a2["name"], a2["amount"], a2["roas"]) == ("서브계정", 55001, 300.0) # 50,000.5 × 1.1 = 55,000.55 → 55,001, 150,000 ÷ 50,000.5 = 299.997 → 300.00
assert (a1["name"], a1["amount"], a1["roas"]) == ("본계정", 100000, 450.0) # 지출 그대로, 450,000 ÷ 100,000
assert (a2["name"], a2["amount"], a2["roas"]) == ("서브계정", 50001, 300.0) # 50,000.5 → 50,001, 150,000 ÷ 50,000.5 = 299.997 → 300.00
assert a1["metrics"]["구매수"] == 10 and a2["metrics"]["구매 전환값"] == 150000 and a2["metrics"]["링크 클릭"] == 80
assert list(d2.metrics["_accounts"]) == ["1111111111"] and d2.metrics["_accounts"]["1111111111"]["name"] == "본계정"
assert "account_name" in seen[0].url.params["fields"].split(",")
@@ -218,10 +218,10 @@ def test_sync_service_end_to_end(monkeypatch):
svc = ad_sync.AdSyncService(store, CredentialService(None, lambda: None))
svc._ctx = lambda code, values=None, user="", cleared=None: _ctx()
res = svc.sync("meta", date(2026, 10, 1), date(2026, 10, 2), user="king@x")
assert res["ok"] and res["days"] == 2 and res["total"] == 165001 and res["name"] == "메타 광고"
assert res["ok"] and res["days"] == 2 and res["total"] == 150001 and res["name"] == "메타 광고"
code, start, end, days, user = store.replaced[0]
assert (code, start, end, user) == ("meta", date(2026, 10, 1), date(2026, 10, 2), "king@x")
assert [(d, amt, roas) for d, amt, roas, _m in days] == [(date(2026, 10, 1), 165001, Decimal("400.00")),
assert [(d, amt, roas) for d, amt, roas, _m in days] == [(date(2026, 10, 1), 150001, Decimal("400.00")),
(date(2026, 10, 2), 0, None)]
assert store.status[-1] == ("meta", "ok", True, "", "sync")
@@ -347,14 +347,14 @@ def _stored(day, amount, roas, metrics):
def test_detail_tabs_total_and_accounts():
def acc(name, amount, roas, spend_metric):
return {"name": name, "amount": amount, "roas": roas,
"metrics": {"광고비(부가세 포함)": amount, "노출수": spend_metric, "클릭수": spend_metric // 100, "클릭률(%)": 1.0,
"metrics": {"지출 금액(부가세 포함)": amount, "노출수": spend_metric, "클릭수": spend_metric // 100, "클릭률(%)": 1.0,
"ROAS(%)": roas}}
rows = [
_stored("2026-10-01", 300, 200.0, {"광고비(부가세 포함)": 300, "노출수": 3000, "클릭수": 30, "클릭률(%)": 1.0, "ROAS(%)": 200.0,
_stored("2026-10-01", 300, 200.0, {"지출 금액(부가세 포함)": 300, "노출수": 3000, "클릭수": 30, "클릭률(%)": 1.0, "ROAS(%)": 200.0,
"_accounts": {"1": acc("작은계정", 100, 100.0, 1000), "2": acc("큰계정", 200, 250.0, 2000)}}),
_stored("2026-10-02", 500, 300.0, {"광고비(부가세 포함)": 500, "노출수": 5000, "클릭수": 50, "클릭률(%)": 1.0, "ROAS(%)": 300.0,
_stored("2026-10-02", 500, 300.0, {"지출 금액(부가세 포함)": 500, "노출수": 5000, "클릭수": 50, "클릭률(%)": 1.0, "ROAS(%)": 300.0,
"_accounts": {"2": acc("큰계정(새 이름)", 500, 300.0, 5000)}}),
_stored("2026-10-03", 70, None, {"광고비(부가세 포함)": 70}), # 계정별 저장 전에 가져온 날
_stored("2026-10-03", 70, None, {"지출 금액(부가세 포함)": 70}), # 계정별 저장 전에 가져온 날
]
t = ad_spend.detail_table(rows)
assert "_accounts" not in t["columns"] and "_accounts" not in t["total"] # "_" 키는 표 열·합계에 없음
@@ -366,14 +366,14 @@ def test_detail_tabs_total_and_accounts():
assert tabs[0]["total"] == t["total"] and len(tabs[0]["rows"]) == 3
big = tabs[1]
assert big["account_id"] == "2" and [r["date"] for r in big["rows"]] == ["2026-10-01", "2026-10-02"]
assert big["total"]["광고비(부가세 포함)"] == 700 and big["total"]["노출수"] == 7000
assert big["total"]["지출 금액(부가세 포함)"] == 700 and big["total"]["노출수"] == 7000
assert big["total"]["ROAS(%)"] == round((200 * 250 + 500 * 300) / 700, 2) # 광고비 가중 평균
assert [r["date"] for r in tabs[2]["rows"]] == ["2026-10-01"] # 광고를 낸 날만
assert out["accounts_missing"] == 1
def test_detail_tabs_absent_without_accounts():
rows = [_stored("2026-10-01", 100, 150.0, {"광고비(부가세 포함)": 100, "ROAS(%)": 150.0})]
rows = [_stored("2026-10-01", 100, 150.0, {"지출 금액(부가세 포함)": 100, "ROAS(%)": 150.0})]
assert ad_spend.detail_tabs(rows) == {"tabs": [], "accounts_missing": 0} # 네이버·구글·옛 메타 자료 = 탭 없음
@@ -386,8 +386,8 @@ def test_details_endpoint_returns_tabs(monkeypatch):
from app.modules.performance import common
perf_router = importlib.import_module("app.modules.performance.router")
rows = [_stored("2026-10-01", 110, 450.0, {"광고비(부가세 포함)": 110, "_accounts": {
"1": {"name": "본계정", "amount": 110, "roas": 450.0, "metrics": {"광고비(부가세 포함)": 110}}}})]
rows = [_stored("2026-10-01", 110, 450.0, {"지출 금액(부가세 포함)": 110, "_accounts": {
"1": {"name": "본계정", "amount": 110, "roas": 450.0, "metrics": {"지출 금액(부가세 포함)": 110}}}})]
class Store:
def ad_details(self, code, start, end):
@@ -398,7 +398,7 @@ def test_details_endpoint_returns_tabs(monkeypatch):
app = FastAPI()
app.include_router(perf_router.router)
d = TestClient(app).get("/performance/api/ad-spend/meta/details?from=2026-10-01&to=2026-10-31").json()
assert d["columns"] == ["광고비(부가세 포함)"] and [t["label"] for t in d["tabs"]] == ["합계", "본계정"]
assert d["columns"] == ["지출 금액(부가세 포함)"] and [t["label"] for t in d["tabs"]] == ["합계", "본계정"]
assert d["accounts_missing"] == 0
@@ -437,17 +437,17 @@ def test_usd_account_converted_with_daily_rate(monkeypatch):
q = calls["fx"][0].url.params
assert (q["base"], q["quotes"], q["to"]) == ("USD", "KRW", "2026-10-03") and q["from"] <= "2026-10-01"
assert len(calls["fx"]) == 1 # 통화마다 기간 한 번
# 10-01: USD 100 × 1,350 = 135,000원 + 원화 50,000 = 185,000 → 부가세 포함 203,500
# 10-01: USD 100 × 1,350 = 135,000원 + 원화 50,000 = 185,000 = 광고비(메타 지출은 부가세 포함 — × 1.1 없음)
# 구매 전환값 USD 400 × 1,350 = 540,000 → ROAS = 540,000 ÷ 185,000 = 291.89%
assert (d1.amount, d1.roas) == (203500, Decimal("291.89"))
assert d1.metrics["지출 금액(부가세 별도)"] == 185000 and d1.metrics["구매 전환값"] == 540000
assert (d1.amount, d1.roas) == (185000, Decimal("291.89"))
assert d1.metrics["지출 금액(부가세 포함)"] == 185000 and d1.metrics["구매 전환값"] == 540000
us = d1.metrics["_accounts"]["333333"]
assert (us["amount"], us["roas"]) == (148500, 400.0) # 135,000 × 1.1, ROAS 는 환율과 무관(400 ÷ 100)
assert (us["amount"], us["roas"]) == (135000, 400.0) # 100 × 1,350, ROAS 는 환율과 무관(400 ÷ 100)
assert us["metrics"]["지출 금액(USD)"] == 100.0 and us["metrics"]["적용 환율(원)"] == 1350.0
assert "적용 환율(원)" not in d1.metrics["_accounts"]["444444"]["metrics"] # 원화 계정엔 없음
assert "적용 환율(원)" not in d1.metrics # 합계 표에도 없음
# 10-03: 그날 환율 없음 → 10-02 값(1,360.5). 10.5 × 1,360.5 = 14,285.25 → 부가세 포함 15,713.775 → 15,714
assert d3.day == date(2026, 10, 3) and d3.amount == 15714
# 10-03: 그날 환율 없음 → 10-02 값(1,360.5). 10.5 × 1,360.5 = 14,285.25 → 14,285
assert d3.day == date(2026, 10, 3) and d3.amount == 14285
assert d3.metrics["_accounts"]["333333"]["metrics"]["적용 환율(원)"] == 1360.5