feat(performance): GS샵 매출 수집 — 매출 내역 custChrAmt(할인 후 고객 결제금액), 매출인식일 기준

- 9/3 실데이터로 항목 확인: salePrice − dcTotAmt = custChrAmt, supGiveAmt = 협력사 지급액
- 매출 내역 한 줄 = 사건, SALE 이 아닌 줄은 RETURN 음수, 배송비 제외, replace_range
- GS API 에는 주문일 기준 조회가 없어 포털 주문 통계(총주문금액)와 날짜 기준이 다름 — 문서에 기록
- 원본 데이터 확인에 날짜별 현재 규칙 매출(열 이름은 쇼핑몰별 day_cols)
- 테스트 1개 추가(29개 통과), performance.js 캐시 버전

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-30 14:53:13 +09:00
parent f4fadec0a4
commit b765fb8fb8
6 changed files with 152 additions and 11 deletions
@@ -1287,6 +1287,59 @@ def test_gsshop_token_connection_and_probe():
httpx.get = orig
def test_gsshop_collect_sales():
"""GS샵 매출 = 매출 내역 custChrAmt(할인 후 고객 결제금액), 매출인식일 기준, 배송비 제외.
SALE 이 아닌 줄은 음수(RETURN). 실데이터 9/3: 16,400 − 820 = 15,580 모양."""
import httpx
from app.modules.performance.adapters import gsshop as gs
key = "0123456789abcdef0123456789ABCDEF"
def line(no, item, day, sale, dc, typ="SALE", qty=1):
return {"rnum": 1, "saleAwareDt": day, "prdCd": 1064149860, "prdNm": "미라클통 황토 3200ml", "supCd": 1047142,
"ordNo": no, "ordItemNo": item, "orgOrdNo": no, "ordType": typ, "chrQty": qty, "salePrice": sale,
"dcTotAmt": dc, "custChrAmt": sale - dc, "supGiveAmt": int((sale - dc) * 0.9)}
rows = [line(3470403225, 1, 20260903, 16400, 820), line(3470403225, 2, 20260903, 32800, 1640, qty=2),
line(3470409999, 1, 20260904, 20000, 0, typ="RTN"), line(3470500000, 1, 20260912, 9900, 0)]
def get(url, params=None, headers=None, timeout=None):
if url.endswith("/shippingFee/period"):
return httpx.Response(200, json={"data": [{"saleAwareDt": 20260903, "prdNm": "배송비상품", "ordType": "SALE",
"ordNo": 3470403225, "ordItemNo": 3, "salePrice": 3500}],
"hasMorePage": False})
lo, hi = int(params["fromDate"]), int(params["toDate"])
return httpx.Response(200, json={"data": [r for r in rows if lo <= r["saleAwareDt"] <= hi], "hasMorePage": False})
st = FakeStore()
creds = CredentialService(st, lambda: ring())
creds.save(next(a for a in all_adapters() if a.code == "gsshop"), {"vendor_code": "1047142", "api_key": key})
orig = httpx.get
httpx.get = get
try:
r = SyncService(st, creds).sync_marketplace("gsshop", date(2026, 9, 3), date(2026, 9, 4))
finally:
httpx.get = orig
assert r["ok"], r
ev_ = {k[2]: v for k, v in st.events.items() if k[0] == "gsshop"}
assert set(ev_) == {"gs:3470403225-1-SALE-20260903", "gs:3470403225-2-SALE-20260903", "gs:3470409999-1-RTN-20260904"}
assert ev_["gs:3470403225-1-SALE-20260903"]["amount"] == 15580 and ev_["gs:3470403225-1-SALE-20260903"]["discount_amount"] == 820
assert ev_["gs:3470403225-2-SALE-20260903"]["quantity"] == 2
ret = ev_["gs:3470409999-1-RTN-20260904"]
assert ret["event_type"] == "RETURN" and ret["amount"] == -20000 and ret["sales_date"] == date(2026, 9, 4)
assert sum(v["amount"] for v in ev_.values()) == 15580 + 31160 - 20000 # 배송비 3,500 제외
httpx.get = get
try:
rec = gs.GsshopAdapter().reconcile(__import__("app.modules.performance.adapters.base", fromlist=["x"]).AdapterContext(
code="gsshop", credentials=creds.accessor("gsshop")), date(2026, 9, 3), to=date(2026, 9, 4))
finally:
httpx.get = orig
assert rec["days"][0] == {"date": "2026-09-03", "orders": 1, "amount": 46740, "claimed": 0, "ship": 3500}
assert rec["days"][1]["amount"] == -20000 and rec["days"][1]["claimed"] == 20000
if __name__ == "__main__":
os.environ.pop("APP_ENCRYPTION_KEY", None)
n = 0