fix(performance): 토스쇼핑 환불 건별 표에 주문일을 메모가 아닌 별도 열로

- 원본 데이터 확인 → 환불 출처별 비교 건별 표: 환불일 · 주문일 · 주문번호 · 주문상품 · 금액 · 메모
  (예: 9/5 주문을 9/6 취소 → 환불일 9/6, 주문일 9/5), 메모에는 취소/반품·클레임 상태만
- 저장되는 환불 사건의 order_date(대시보드 금액 클릭 상세의 주문일 열)를 테스트로 확인
- performance.js 캐시 버전 20261001f

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 10:36:51 +09:00
parent b6b4f8c360
commit 931cc0d1d9
5 changed files with 19 additions and 11 deletions
+7 -6
View File
@@ -178,8 +178,8 @@ def cancel_rows(items: Iterable[dict[str, Any]], start: date, end: date) -> list
continue
status = str(it.get("orderProductStatus") or "")
out.append({"orderId": str(it["orderId"]), "orderProductId": str(it.get("orderProductId") or ""), "_day": day,
"amount": _won(it.get("price")), "status": status, "note":f"{STATUS_KO.get(status, status)} · 주문일 "
f"{kst_day(it.get('orderedAt')) or '?'}"})
"amount": _won(it.get("price")), "status": status, "note": STATUS_KO.get(status, status),
"order_day": kst_day(it.get("orderedAt"))})
return out
@@ -195,7 +195,7 @@ def claim_rows(items: Iterable[dict[str, Any]], start: date, end: date) -> list[
continue
out.append({"orderId": str(order["id"]), "orderProductId": str(order.get("orderProductId") or ""), "_day": day,
"amount": _won(order.get("price")), "note": f"{it.get('type') or '?'}/{it.get('status') or '?'} · "
f"수량 {_won(product.get('quantity'))} · 주문일 {kst_day(order.get('createdDt')) or '?'}"})
f"수량 {_won(product.get('quantity'))}", "order_day": kst_day(order.get("createdDt"))})
return out
@@ -566,14 +566,14 @@ class TossAdapter(MarketplaceAdapter):
# ── 환불 출처별 — 파트너스 화면 "환불"과 맞춰 보는 용도 ──
candidates: list[dict[str, Any]] = [
{"key": "rule", "label": "적용 규칙(클레임 환불 + 클레임 없는 결제취소)", "rows": [
{**r, "note": f"{'반품' if r['type'] == 'RETURN' else '취소'} · 주문일 {r.get('order_day') or '?'}"}
{**r, "note": "반품" if r["type"] == "RETURN" else "취소"}
for r in refunds], "error": claims_err},
{"key": "claims", "label": "클레임 환불 완료(refundedDt, 금액 order.price)", "rows": claim_rows(claims, day, to),
"error": claims_err},
{"key": "canceled", "label": f"주문 취소 시각(canceledAt, {CANCEL_LOOKBACK_DAYS}일 전 주문까지)",
"rows": cancel_rows(back + items, day, to), "error": ""},
{"key": "settlement", "label": "정산 REFUND 상품 줄(거래일) — 참고", "rows": [
{**r, "note": f"정산 REFUND · 주문일 {r.get('order_day') or '?'}"} for r in refund_rows(settle, day, to)],
{**r, "note": "정산 REFUND"} for r in refund_rows(settle, day, to)],
"error": settle_err},
]
for c in candidates:
@@ -581,7 +581,8 @@ class TossAdapter(MarketplaceAdapter):
for r in c["rows"]:
k = r["_day"].isoformat()
c["days"][k] = c["days"].get(k, 0) + r["amount"]
c["rows"] = [{"date": r["_day"].isoformat(), "orderId": r["orderId"], "orderProductId": r["orderProductId"],
c["rows"] = [{"date": r["_day"].isoformat(), "orderDate": r["order_day"].isoformat() if r.get("order_day") else "",
"orderId": r["orderId"], "orderProductId": r["orderProductId"],
"amount": r["amount"], "note": r.get("note") or ""}
for r in sorted(c["rows"], key=lambda x: (x["_day"], x["orderId"]))][:200]
@@ -239,4 +239,4 @@
} | tojson }}</script>
{% endblock %}
{% block scripts %}<script src="/static/performance.js?v=20261001e" defer></script>{% endblock %}
{% block scripts %}<script src="/static/performance.js?v=20261001f" defer></script>{% endblock %}
@@ -192,4 +192,4 @@
</section>
{% endblock %}
{% block scripts %}<script src="/static/performance.js?v=20261001e" defer></script>{% endblock %}
{% block scripts %}<script src="/static/performance.js?v=20261001f" defer></script>{% endblock %}
@@ -569,6 +569,10 @@ def test_toss_collect_sales():
"toss:R51": (-7000, date(2026, 8, 10), "CANCEL"), # 앞 90일 주문 — 금액은 주문 price(판매가 × 수량)
"toss:R81": (-4400, date(2026, 8, 15), "CANCEL"), # 주문 내역에 없는 오래된 주문 → 클레임 order.price
} # R61: 클레임 환불(9/5)이 기간 밖 → canceledAt(9/2)으로 넣지 않음, 교환·미환불 클레임 제외
# 환불 사건에도 원래 주문일 — 대시보드 금액 클릭 상세의 "주문일" 열(9/6 화면: 9/5 주문을 9/6 취소)
assert {k: v["order_date"] for k, v in refunds.items()} == {
"toss:R21": date(2026, 9, 1), "toss:R41": date(2026, 9, 1), "toss:R51": date(2026, 7, 15),
"toss:R81": date(2026, 8, 1)}
net = {}
for v in ev_.values():
net[v["sales_date"]] = net.get(v["sales_date"], 0) + v["amount"]
@@ -640,7 +644,8 @@ def test_toss_reconcile_hides_personal():
assert sorted(x["orderId"] for x in cand["rule"]["rows"]) == ["7", "8"]
assert cand["settlement"]["days"] == {"2026-09-10": 9900}
assert cand["canceled"]["days"] == {"2026-09-10": 11900} and cand["canceled"]["rows"][0]["orderId"] == "7"
assert "주문일 2026-08-20" in cand["canceled"]["rows"][0]["note"]
assert cand["canceled"]["rows"][0]["orderDate"] == "2026-08-20" # 주문일은 따로 열로(메모 X)
assert {x["orderId"]: x["orderDate"] for x in cand["rule"]["rows"]} == {"7": "2026-08-20", "8": "2026-08-25"}
assert cand["claims"]["days"] == {"2026-09-10": 5000} and len(cand["claims"]["rows"]) == 1 # 환불 안 된 클레임 제외
cf = {x["name"]: x for x in next(p for p in rec["probes"] if p["key"] == "claims")["fields"]}
assert cf["requestReason"]["personal"] and cf["returnAddress"]["personal"] and cf["order.ordererPhoneNumber"]["personal"]
+4 -2
View File
@@ -1051,10 +1051,12 @@
}).join("") + "</tr></tbody></table>" +
rc.filter(function (c) { return !c.error && (c.rows || []).length; }).map(function (c) {
return '<p class="perf-muted" style="margin:10px 0 4px">' + esc(c.label) + " — " + fmt(c.rows.length) + "건</p>" +
'<table class="perf-table"><thead><tr><th class="perf-th-label">날짜</th><th class="perf-th-label">주문번호</th>' +
'<table class="perf-table"><thead><tr><th class="perf-th-label">환불일</th><th class="perf-th-label">주문일</th>' +
'<th class="perf-th-label">주문번호</th>' +
'<th class="perf-th-label">주문상품</th><th>금액</th><th class="perf-th-label">메모</th></tr></thead><tbody>' +
c.rows.map(function (x) {
return '<tr><td class="perf-td-label">' + esc(x.date) + "</td><td>" + esc(x.orderId) + "</td><td>" + esc(x.orderProductId) +
return '<tr><td class="perf-td-label">' + esc(x.date) + "</td><td>" + esc(x.orderDate || "") + "</td><td>" +
esc(x.orderId) + "</td><td>" + esc(x.orderProductId) +
'</td><td class="perf-num">' + fmt(x.amount) + '</td><td class="perf-muted">' + esc(x.note) + "</td></tr>";
}).join("") + "</tbody></table>";
}).join("") : "";