ee96c924fc
- KPI 는 수수료 차감 매출만 화면 왼쪽 한 줄(금액 + 비교 기간 대비 %), 나머지 카드 제거 - 일자별 표 기본 보기 = 수수료 차감 매출(localStorage 저장값 안 씀) - 마지막 업데이트 옆 다음 자동 업데이트까지 남은 시간(초 단위 실시간) - 일 합계 ROAS = 일 합계 금액 ÷ 일 합계 광고비(보기 기준별 roas / roas_net) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
110 lines
5.7 KiB
Python
110 lines
5.7 KiB
Python
"""실적 대시보드(index.html)·광고비(ads.html)·설정(settings.html)을 테스트용 HTML 로 렌더한다(erp_base.html 은 최소 스텁, 가상의 데이터).
|
|
|
|
python tests/js/render_performance.py # → tests/js/.out/perf_dash.html · perf_ads.html · perf_settings.html
|
|
|
|
화면 데이터는 실제 build_dashboard·build_settings 로 만든다(저장소만 가짜). DB·쇼핑몰 API 는 쓰지 않는다.
|
|
쿠팡은 수동 입력 켬(10/5 수동 값 87,000, 10/6 은 API 값만), 카카오도 켬(값 없음), 나머지는 끔.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
from datetime import date
|
|
from decimal import Decimal
|
|
|
|
import jinja2
|
|
|
|
ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
sys.path.insert(0, ROOT)
|
|
OUT_DIR = os.path.join(ROOT, "tests", "js", ".out")
|
|
|
|
from app.modules.performance.ad_spend import build_ad_dashboard # noqa: E402
|
|
from app.modules.performance.dashboard import amount_text, build_dashboard, build_settings # noqa: E402
|
|
|
|
BASE_STUB = ("{% block head_extra %}{% endblock %}<body><main class='erp-page'>{% block content %}{% endblock %}</main>"
|
|
"{% block scripts %}{% endblock %}</body>")
|
|
ORDER = ["cafe24", "naver", "coupang", "toss", "gsshop", "elevenst", "ohouse", "gmarket", "kakao", "lotteon"]
|
|
NAMES = {"cafe24": "카페24", "naver": "네이버 스마트스토어", "coupang": "쿠팡", "toss": "토스쇼핑", "gsshop": "GS샵",
|
|
"elevenst": "11번가", "ohouse": "오늘의집", "gmarket": "G마켓", "kakao": "카카오", "lotteon": "롯데ON"}
|
|
|
|
|
|
class FakeStore:
|
|
def list_marketplaces(self):
|
|
return [{"code": c, "name": NAMES[c], "enabled": True, "include_in_sales": True, "sort_order": i * 10,
|
|
"manual_input": c in ("coupang", "kakao")} for i, c in enumerate(ORDER, 1)]
|
|
|
|
def daily_amounts(self, start, end, codes):
|
|
api = {(date(2026, 10, 5), "coupang"): 50000, (date(2026, 10, 6), "coupang"): 7000,
|
|
(date(2026, 10, 5), "cafe24"): 100000}
|
|
out = {k: v for k, v in api.items() if start <= k[0] <= end and k[1] in codes}
|
|
out.update(self.manual_amounts(start, end, codes))
|
|
return out
|
|
|
|
def manual_amounts(self, start, end, codes, *, active_only=True):
|
|
manual = {(date(2026, 10, 5), "coupang"): 87000}
|
|
return {k: v for k, v in manual.items() if start <= k[0] <= end and k[1] in codes}
|
|
|
|
def rate_table(self):
|
|
return {"coupang": [(date(2026, 1, 1), Decimal("12"))]}
|
|
|
|
def statuses(self):
|
|
return {}
|
|
|
|
def last_update_at(self):
|
|
return None
|
|
|
|
def running_codes(self):
|
|
return []
|
|
|
|
def ad_amounts(self, start, end):
|
|
rows = {(date(2026, 10, 1), "coupang_rocket"): (220000, "upload"), (date(2026, 10, 2), "google"): (50000, "manual"),
|
|
(date(2026, 10, 5), "coupang_wing"): (29000, "manual"), (date(2026, 10, 3), "naver"): (300000, "upload"),
|
|
(date(2026, 10, 4), "google"): (123457, "api")} # 구글 광고 API 값(초록 숫자)
|
|
rows = {k: v for k, v in rows.items() if start <= k[0] <= end}
|
|
return {k: v[0] for k, v in rows.items()}, {k: v[1] for k, v in rows.items()}
|
|
|
|
def ad_roas(self, start, end):
|
|
rows = {(date(2026, 10, 3), "naver"): Decimal("250.5"), (date(2026, 10, 4), "google"): Decimal("500")}
|
|
return {k: v for k, v in rows.items() if start <= k[0] <= end}
|
|
|
|
|
|
def env() -> jinja2.Environment:
|
|
e = jinja2.Environment(loader=jinja2.ChoiceLoader([
|
|
jinja2.DictLoader({"erp_base.html": BASE_STUB}),
|
|
jinja2.FileSystemLoader(os.path.join(ROOT, "app", "modules", "performance", "templates")),
|
|
]), autoescape=True)
|
|
return e
|
|
|
|
|
|
def main() -> None:
|
|
os.makedirs(OUT_DIR, exist_ok=True)
|
|
e = env()
|
|
base = {"user": {"email": "me@test.local"}, "is_admin": True, "nav_items": [], "page_title": "실적", "page_subtitle": "",
|
|
"unit": "won", "unit_label": "원", "amt": lambda v: amount_text(v)}
|
|
ctx = build_dashboard(FakeStore(), kind="week", anchor=date(2026, 10, 7), today=date(2026, 10, 7))
|
|
# 다음 자동 업데이트(router._auto_sync_ctx 와 같은 모양) — 화면이 초 단위로 센다
|
|
ctx["auto_sync"] = {"next_at": "2026-10-07T10:30:00+09:00", "now": "2026-10-07T10:17:25.000+09:00", "hours": [9, 19], "slot": 30}
|
|
html = e.get_template("performance/index.html").render(**base, active_tab="dashboard", metric="net", **ctx)
|
|
with open(os.path.join(OUT_DIR, "perf_dash.html"), "w", encoding="utf-8") as f:
|
|
f.write(html)
|
|
actx = build_ad_dashboard(FakeStore(), kind="month", anchor=date(2026, 10, 7), today=date(2026, 10, 7),
|
|
sales_codes=["cafe24", "coupang"])
|
|
actx["ad_sync_sources"] = [{"code": "google", "name": "구글 광고"}] # [구글 광고 불러오기]
|
|
html = e.get_template("performance/ads.html").render(**base, active_tab="ads", **actx)
|
|
with open(os.path.join(OUT_DIR, "perf_ads.html"), "w", encoding="utf-8") as f:
|
|
f.write(html)
|
|
sctx = build_settings(FakeStore(), configured={}, key_info={}, key_versions_in_use={}, sample_count=0)
|
|
sctx["ad_api_ready"] = True # 광고 API 연동 표(마이그레이션 007)
|
|
sctx["ad_sources"] = [{"code": "google", "name": "구글 광고", "configured": True, "status": "ok", "status_label": "정상 연결",
|
|
"last_test_at": "2026-10-15T10:00:00+09:00", "last_error": "", "last_error_at": None,
|
|
"last_sync_at": "2026-10-15T10:30:02+09:00", "last_success_sync_at": "2026-10-15T10:30:02+09:00"}]
|
|
html = e.get_template("performance/settings.html").render(**base, active_tab="settings", **sctx)
|
|
with open(os.path.join(OUT_DIR, "perf_settings.html"), "w", encoding="utf-8") as f:
|
|
f.write(html)
|
|
print("ok")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|