e7b1e17579
- 실적 설정 "광고 API 연동" 카드: 개발자 토큰·고객 ID·로그인 고객 ID(MCC)·서비스 계정 JSON·API 버전(기본 v26) → 쇼핑몰과 같은 마스터 키로 암호화(perf_ad_credentials, AAD perf:ad:…), 연결 테스트·상태(perf_ad_source_status) - ad_sources/(채널 하나 = 파일 하나) + google_ads.py: 서비스 계정 JWT 토큰(httpx) → REST searchStream GAQL, 비용(cost_micros 원 반올림, 부가세 별도)·ROAS(전환 가치÷비용)·노출·클릭·전환 항목, KRW 계정만, 오류 코드별 안내 - ad_sync.py: 기간 한 트랜잭션 저장(source='api', 안 준 날은 예전 API 값만 지움), 같은 채널 동시 실행 차단, 비밀값 가림 - 광고비 탭 [구글 광고 불러오기](보는 기간, 92일 넘으면 관리자) + 매출 자동 업데이트 회차에 함께, API 값 초록 숫자, 구글 머리글 = 일자별 항목 표 - 마이그레이션 007, 테스트 test_google_ads.py(가짜 구글 서버) — performance 테스트 83개 통과 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
107 lines
5.4 KiB
Python
107 lines
5.4 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 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": ""}
|
|
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)
|
|
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()
|