62c345bbb5
[프로젝트]
- 보드 카드 끌기: 기울어진 끄는 모양 + 점선 자리 표시가 카드 사이로 FLIP 애니메이션, 놓은 자리 그대로(다른 섹션도 순서 저장)
- 컬럼 dragenter 도 허용 — 자리 표시가 들어온 직후 놓을 때 drop 이 거부되던 문제
- 끄는 동안 실시간 동기화가 보드를 다시 그리지 않음
- 주간 회의록 항목 칸을 끌어 위아래로 이동(묶인 줄·세로 병합째, 같은 구역) — POST meeting-items/{id}/move-to
- 주간 회의록 표 테두리 모두 검정
- 도움말·모듈 문서 갱신
[실적]
- 설정의 쇼핑몰 원본 데이터 확인·카페24 매출 대조·일별 한 번에 비교 카드 삭제(서버 API 는 유지)
- 보기 설정: 매출 단위 원·천원·백만원(이 브라우저 쿠키 perf_unit)
- 매출 실적 표 매출 칸 아래 광고비(ROAS%) 줄(광고비 색), 카페24 는 구글·메타 두 줄
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
131 lines
6.2 KiB
Python
131 lines
6.2 KiB
Python
"""매출 실적 화면 — 매출 칸 아래 광고비(ROAS%)·매출 단위(원·천원·백만원) (2026-10-19)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import date
|
|
|
|
from app.modules.performance import dashboard
|
|
|
|
TODAY = date(2026, 10, 7)
|
|
|
|
|
|
class _Store:
|
|
"""build_dashboard 가 읽는 것만 — 카페24·네이버·쿠팡 매출 + 구글·메타·네이버·쿠팡(윙) 광고비."""
|
|
|
|
def __init__(self, ads_missing=False):
|
|
self.ads_missing = ads_missing
|
|
|
|
def list_marketplaces(self):
|
|
return [{"code": c, "name": n, "enabled": True, "include_in_sales": True}
|
|
for c, n in (("cafe24", "카페24"), ("naver", "네이버 스마트스토어"), ("coupang", "쿠팡"))]
|
|
|
|
def daily_amounts(self, start, end, codes):
|
|
rows = {(date(2026, 10, 5), "cafe24"): 2_000_000, (date(2026, 10, 5), "coupang"): 600_000,
|
|
(date(2026, 10, 6), "naver"): 1_234_567}
|
|
return {k: v for k, v in rows.items() if start <= k[0] <= end and k[1] in codes}
|
|
|
|
def rate_table(self):
|
|
return {}
|
|
|
|
def statuses(self):
|
|
return {}
|
|
|
|
def last_update_at(self):
|
|
return None
|
|
|
|
def running_codes(self):
|
|
return []
|
|
|
|
def ad_amounts(self, start, end):
|
|
if self.ads_missing:
|
|
raise RuntimeError("perf_ad_spend 없음")
|
|
rows = {(date(2026, 10, 5), "google"): 100_000, (date(2026, 10, 5), "meta"): 50_000,
|
|
(date(2026, 10, 5), "coupang_wing"): 200_000, (date(2026, 10, 6), "naver"): 300_000}
|
|
rows = {k: v for k, v in rows.items() if start <= k[0] <= end}
|
|
return rows, {k: "manual" for k in rows}
|
|
|
|
def ad_roas(self, start, end):
|
|
rows = {(date(2026, 10, 5), "google"): 412.5, (date(2026, 10, 6), "naver"): 150}
|
|
return {k: v for k, v in rows.items() if start <= k[0] <= end}
|
|
|
|
|
|
def test_sales_ad_channels_mapping():
|
|
m = dashboard.sales_ad_channels()
|
|
assert m["cafe24"] == (("google", "구글"), ("meta", "메타"))
|
|
assert m["naver"] == (("naver", ""),) and m["coupang"] == (("coupang_wing", ""),)
|
|
assert m["coupang_rocket"] == (("coupang_rocket", ""),) and "google" not in m
|
|
|
|
|
|
def test_ad_lines_under_sales_cells():
|
|
ctx = dashboard.build_dashboard(_Store(), kind="week", anchor=TODAY, today=TODAY)
|
|
day5 = next(r for r in ctx["table"] if r.get("date") == "2026-10-05")
|
|
# 카페24 = 구글·메타 두 줄, ROAS 는 광고 보고서 값(구글 412.5 → 413), 메타는 보고서 ROAS 없음
|
|
assert day5["ads"]["cafe24"] == [{"label": "구글", "amount": 100_000, "roas": 413},
|
|
{"label": "메타", "amount": 50_000, "roas": None}]
|
|
# 쿠팡 = 쿠팡(윙) 광고비, ROAS = 쿠팡 매출 ÷ 광고비 = 600,000 ÷ 200,000
|
|
assert day5["ads"]["coupang"] == [{"label": "", "amount": 200_000, "roas": 300}]
|
|
assert "naver" not in day5["ads"] # 그날 네이버 광고비 없음 → 줄 없음
|
|
# 일 합계 = 보이는 쇼핑몰 광고비 합, ROAS = 그 쇼핑몰들 매출 합 ÷ 광고비 합
|
|
assert day5["ads_total"] == {"amount": 350_000, "roas": 743} # 2,600,000 ÷ 350,000
|
|
day6 = next(r for r in ctx["table"] if r.get("date") == "2026-10-06")
|
|
assert day6["ads"]["naver"] == [{"label": "", "amount": 300_000, "roas": 150}]
|
|
week = next(r for r in ctx["table"] if r["kind"] == "week")
|
|
assert [a["amount"] for a in week["ads"]["cafe24"]] == [100_000, 50_000] and week["ads_total"]["amount"] == 650_000
|
|
day1 = next(r for r in ctx["table"] if r.get("date") == "2026-10-07")
|
|
assert day1["ads"] == {} and day1["ads_total"] is None
|
|
|
|
|
|
def test_ad_lines_follow_shop_filter_and_missing_table():
|
|
ctx = dashboard.build_dashboard(_Store(), kind="week", anchor=TODAY, today=TODAY, selected=["coupang"])
|
|
day5 = next(r for r in ctx["table"] if r.get("date") == "2026-10-05")
|
|
assert list(day5["ads"]) == ["coupang"] and day5["ads_total"] == {"amount": 200_000, "roas": 300}
|
|
ctx = dashboard.build_dashboard(_Store(ads_missing=True), kind="week", anchor=TODAY, today=TODAY)
|
|
assert all(r["ads"] == {} and r["ads_total"] is None for r in ctx["table"]) # 광고비 표 없어도 매출 화면은 그대로
|
|
|
|
|
|
def test_amount_text_units():
|
|
assert dashboard.amount_text(2_475_300) == "2,475,300"
|
|
assert dashboard.amount_text(2_475_300, "thousand") == "2,475"
|
|
assert dashboard.amount_text(2_475_500, "thousand") == "2,476"
|
|
assert dashboard.amount_text(2_475_300, "million") == "2.5"
|
|
assert dashboard.amount_text(158_000, "million") == "0.2"
|
|
assert dashboard.amount_text(-158_000, "thousand") == "-158"
|
|
assert dashboard.amount_text(1_234_567_890, "million") == "1,234.6"
|
|
assert dashboard.amount_text(5, "nope") == "5" and dashboard.normalize_unit("x") == "won"
|
|
|
|
|
|
def test_dashboard_page_renders_unit_and_ad_lines(monkeypatch):
|
|
import importlib
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.testclient import TestClient
|
|
|
|
from app.modules.performance import common
|
|
|
|
perf_router = importlib.import_module("app.modules.performance.router")
|
|
|
|
class _Creds:
|
|
def configured_codes(self, adapters):
|
|
return {}
|
|
|
|
store = _Store()
|
|
monkeypatch.setattr(common, "guard", lambda request, admin=False: (store, {"email": "king@x", "name": "King", "is_admin": True}))
|
|
monkeypatch.setattr(common, "services", lambda request, st: (_Creds(), None))
|
|
monkeypatch.setattr(perf_router, "today_kst", lambda: TODAY)
|
|
app = FastAPI()
|
|
app.include_router(perf_router.router)
|
|
client = TestClient(app)
|
|
|
|
html = client.get("/performance/?period=week&d=2026-10-07").text
|
|
assert "2,000,000" in html
|
|
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")
|
|
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")
|
|
html = client.get("/performance/?period=week&d=2026-10-07").text
|
|
assert "단위: 백만원" in html and ">2.0<" in html and '"unit": "million"' in html
|