feat(performance): 카페24 매출 대조 — 환불합계 후보·환불 건별·취소/반품 완료 품목

9/26 은 결제합계가 카페24와 같고 환불만 97,580 모자라며 완료일·접수일·적립금
어느 기준으로도 맞지 않아, 환불 API 에 빠진 건을 찾는 진단을 추가.
- 환불합계 후보 표: 카페24 화면 값을 입력하면 같은 줄 강조
- 환불 건별 목록(완료일·접수일 기준 합침, 계좌 등 개인정보 제외)
- 그날 취소/반품/교환 완료 품목(orders date_type=*_complete_date, embed=items)
  품목 판매가·결제금액·쿠폰·환불 기록 유무

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-29 17:44:21 +09:00
parent a19c1f4cab
commit 370834b58b
7 changed files with 199 additions and 6 deletions
@@ -407,8 +407,9 @@ def _c24_refund(code, oid, amount, status="T", order_date="2026-09-20T09:00:00+0
class _FakeCafe24(__import__("app.modules.performance.adapters.cafe24", fromlist=["Cafe24Adapter"]).Cafe24Adapter):
def __init__(self, orders_pages, refunds_pages=(), lookup=None):
def __init__(self, orders_pages, refunds_pages=(), lookup=None, claims=None):
self.orders_pages = orders_pages # 결제일 조회 페이지들
self.claims = claims or {} # date_type(취소/반품/교환 완료일) → 주문 목록
self.refunds_pages = list(refunds_pages)
self.lookup = lookup or {} # order_id → market_id (환불 원 주문 조회)
self.calls = []
@@ -424,6 +425,8 @@ class _FakeCafe24(__import__("app.modules.performance.adapters.cafe24", fromlist
if params.get("date_type") == "order_date": # 원 주문 market_id 조회
ids = params["order_id"].split(",")
return {"orders": [{"order_id": i, "market_id": self.lookup.get(i, "self")} for i in ids]}
if params.get("date_type", "").endswith("_complete_date"):
return {"orders": self.claims.get(params["date_type"], []) if idx == 0 else []}
return {"orders": self.orders_pages[idx] if idx < len(self.orders_pages) else []}
@@ -485,7 +488,32 @@ def test_cafe24_normalize_matches_daily_report():
assert rb["completed"]["count"] == 3 and rb["completed"]["actual_refund_amount"] == 12_610 + 20_000 + 9_000
assert rb["accepted_all"]["count"] == 4 and rb["accepted_all"]["with_points"] == 12_610 + 20_000 + 9_000 + 5_000
assert {s["status"]: s["count"] for s in rb["accepted_by_status"]} == {"T": 3, "F": 1}
# 기기: PC 채널(self)이어도 휴대폰 주문(order_from_mobile=T)은 모바일
assert {c["key"] for c in rec["refund_candidates"]} >= {"completed", "completed_pts", "claim_pay"}
assert {r["refund_code"] for r in rec["refund_list"]} == {"C20260929-01", "R20260929-02", "C20260929-03", "C20260929-04"}
assert "1234567890" not in str(rec["refund_list"]) # 환불 계좌 미노출
# 클레임 완료 품목: 환불 API 에 없는 취소(네이버페이 등)를 찾는다. 입금전취소·미완료는 합계 제외
item = lambda code, st, pay, price=10_000, qty=1: {"order_item_code": code, "order_status": st, "quantity": qty,
"product_price": f"{price}.00", "option_price": "0.00",
"payment_amount": f"{pay}.00", "product_name": "상품"}
fake4 = _FakeCafe24([[]], [[_c24_refund("C1", "A", 9_000)]], claims={
"cancel_complete_date": [
{**_c24_order("A"), "items": [item("A-01", "C40", 9_000)]},
{**_c24_order("N"), "market_id": "NCHECKOUT", "items": [item("N-01", "C40", 19_800, 20_000), item("N-02", "C40", 5_000, 5_000)]},
{**_c24_order("U"), "items": [item("U-01", "C48", 7_000)]},
{**_c24_order("P"), "items": [item("P-01", "C34", 3_000), item("P-02", "N40", 4_000)]}],
"return_complete_date": [{**_c24_order("N"), "items": [item("N-01", "C40", 19_800, 20_000)]},
{**_c24_order("R"), "items": [item("R-01", "R40", 12_000, 6_000, 2)]}],
})
rec4 = fake4.reconcile(ctx, date(2026, 9, 29))
cl = {c["item_code"]: c for c in rec4["claims"]["items"]}
assert set(cl) == {"A-01", "N-01", "N-02", "P-01", "R-01"} # 입금전취소(U)·정상 품목 제외, 중복 제거
assert cl["A-01"]["has_refund"] and not cl["N-01"]["has_refund"] and not cl["P-01"]["done"]
assert cl["R-01"]["product_amount"] == 12_000
assert rec4["claims"]["full_cancel_shipping"] == 3_000 * 2 # A, N 전체취소(배송비 3,000씩)
cand = {c["key"]: c["amount"] for c in rec4["refund_candidates"]}
assert cand["claim_pay"] == 9_000 + 19_800 + 5_000 + 12_000
assert cand["completed_plus_noref"] == 9_000 + 19_800 + 5_000 + 12_000
# 기기: PC 채널(self)이어도 휴대폰 주문(order_from_mobile=T)은 모바일
assert ch["self"]["mobile_orders"] == 1 and ch["self"]["pc_orders"] == 0 and ch["self"]["mobile_total"] == 47_000
assert ch["NCHECKOUT"]["pc_orders"] == 1 and ch["mobile"]["mobile_orders"] == 1
# self 는 PC 전용이 아니다 — 주문경로(PC쇼핑몰/모바일웹)별로 한 줄씩(실데이터 확인)