454b3cc700
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
85 lines
3.6 KiB
Python
85 lines
3.6 KiB
Python
"""실적 대시보드(index.html)·설정(settings.html)을 테스트용 HTML 로 렌더한다(erp_base.html 은 최소 스텁, 가상의 데이터).
|
|
|
|
python tests/js/render_performance.py # → tests/js/.out/perf_dash.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.dashboard import 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 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": ""}
|
|
ctx = build_dashboard(FakeStore(), kind="week", anchor=date(2026, 10, 7), today=date(2026, 10, 7))
|
|
html = e.get_template("performance/index.html").render(**base, active_tab="dashboard", metric="gross", **ctx)
|
|
with open(os.path.join(OUT_DIR, "perf_dash.html"), "w", encoding="utf-8") as f:
|
|
f.write(html)
|
|
sctx = build_settings(FakeStore(), configured={}, key_info={}, key_versions_in_use={}, sample_count=0)
|
|
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()
|