From 34dca7cb7675775d6a636027e05367b8386446a6 Mon Sep 17 00:00:00 2001 From: king Date: Wed, 21 Oct 2026 13:15:57 +0900 Subject: [PATCH] =?UTF-8?q?fix(performance):=20=EA=B3=84=EC=82=B0=EC=8B=9D?= =?UTF-8?q?=20=EC=9E=85=EB=A0=A5=20=EC=A7=81=ED=9B=84=20=EC=B0=A8=EA=B0=90?= =?UTF-8?q?=20=EB=A7=A4=EC=B6=9C=20=EC=88=AB=EC=9E=90=EA=B0=80=20=EC=95=88?= =?UTF-8?q?=20=EB=B3=B4=EC=9D=B4=EB=8D=98=20=EB=AC=B8=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 칸 저장 뒤 총매출만 바꾸고 수수료·차감 매출(기본 보기)은 새로고침 때까지 예전 값(–)으로 흐리게 남겼다. 저장 응답에 그날 수수료·차감 매출을 함께 돌려주고 화면이 세 숫자를 바로 바꾼다. Co-Authored-By: Claude Opus 5.5 --- app/modules/performance/router.py | 9 +++++++-- .../performance/templates/performance/ads.html | 2 +- .../performance/templates/performance/index.html | 2 +- .../performance/templates/performance/settings.html | 2 +- app/modules/performance/tests/test_performance.py | 4 ++++ app/static/performance.js | 11 ++++++++--- 6 files changed, 22 insertions(+), 8 deletions(-) diff --git a/app/modules/performance/router.py b/app/modules/performance/router.py index b408c55..32a3685 100644 --- a/app/modules/performance/router.py +++ b/app/modules/performance/router.py @@ -50,7 +50,7 @@ from fastapi.responses import FileResponse, HTMLResponse, JSONResponse from app.timezone import today_kst -from . import common +from . import calc, common from .adapters.registry import all_adapters, get_adapter router = APIRouter(prefix="/performance", tags=["performance"]) @@ -424,8 +424,13 @@ def api_manual_sale(request: Request, code: str, day: str, payload: dict[str, An except ManualMigrationNeeded: raise HTTPException(status_code=503, detail=MANUAL_MIGRATION_HELP) from None api_amount = store.api_amount(code, d) + shown = api_amount if amount is None else amount + # 그날 수수료·수수료 차감 매출도 돌려준다 — 화면이 새로고침 전에도 보고 있는 기준(기본 = 차감 매출) 숫자를 바로 바꾸게 + rate_table = getattr(store, "rate_table", None) + money = calc.build_cells({(d, code): shown}, rate_table() if rate_table else {})[(d, code)].as_dict() return JSONResponse({"ok": True, "code": code, "date": d.isoformat(), "manual": amount, "formula": formula, - "amount": api_amount if amount is None else amount, "api_amount": api_amount}) + "amount": shown, "api_amount": api_amount, + "commission": money["commission"], "net": money["net"]}) @router.get("/api/manual-sales/sample.xlsx") diff --git a/app/modules/performance/templates/performance/ads.html b/app/modules/performance/templates/performance/ads.html index 9b1e7ee..dee2934 100644 --- a/app/modules/performance/templates/performance/ads.html +++ b/app/modules/performance/templates/performance/ads.html @@ -238,4 +238,4 @@ } | tojson }} {% endblock %} -{% block scripts %}{% endblock %} +{% block scripts %}{% endblock %} diff --git a/app/modules/performance/templates/performance/index.html b/app/modules/performance/templates/performance/index.html index 7a0de33..66109e7 100644 --- a/app/modules/performance/templates/performance/index.html +++ b/app/modules/performance/templates/performance/index.html @@ -275,4 +275,4 @@ } | tojson }} {% endblock %} -{% block scripts %}{% endblock %} +{% block scripts %}{% endblock %} diff --git a/app/modules/performance/templates/performance/settings.html b/app/modules/performance/templates/performance/settings.html index 752ab2e..3cbd98f 100644 --- a/app/modules/performance/templates/performance/settings.html +++ b/app/modules/performance/templates/performance/settings.html @@ -219,4 +219,4 @@ {% endblock %} -{% block scripts %}{% endblock %} +{% block scripts %}{% endblock %} diff --git a/app/modules/performance/tests/test_performance.py b/app/modules/performance/tests/test_performance.py index 85dbfaa..180cef4 100644 --- a/app/modules/performance/tests/test_performance.py +++ b/app/modules/performance/tests/test_performance.py @@ -2123,6 +2123,9 @@ def test_manual_sale_api_rules(): def api_amount(self, code, day): return 50000 + def rate_table(self): + return {"coupang": [(date(2026, 1, 1), Decimal("10"))]} + def update_marketplace(self, code, **kw): if self.missing and kw.get("manual_input") is not None: raise ManualMigrationNeeded() @@ -2156,6 +2159,7 @@ def test_manual_sale_api_rules(): assert st.formula is None body = __import__("json").loads(router.api_manual_sale(None, "coupang", "2026-10-12", {"amount": "1,000+2000*2"}).body) assert st.saved[-1][2] == 5000 and st.formula == "1000+2000*2" and body["formula"] == "1000+2000*2" + assert body["commission"] == 500 and body["net"] == 4500 # 화면이 새로고침 전에도 차감 매출을 바로 보이게 assert status_of(lambda: router.api_manual_sale(None, "coupang", "2026-10-12", {"amount": "1/0"}))[0] == 400 code, msg = status_of(lambda: router.api_manual_sale(None, "naver", "2026-10-12", {"amount": 1})) assert code == 400 and "수동 입력" in msg # 꺼진 쇼핑몰 diff --git a/app/static/performance.js b/app/static/performance.js index b02002a..d4e3910 100644 --- a/app/static/performance.js +++ b/app/static/performance.js @@ -664,9 +664,14 @@ td.title = res.formula ? "계산식 " + res.formula + " — 눌러 고치기" : manual !== "" ? "직접 입력값 — 눌러 고치기(비우고 저장하면 " + (FIXED_METRIC ? "지움" : "API 값") + ")" : "눌러 " + MANUAL_WORD + " 직접 입력"; - const g = td.querySelector(".v-gross"); - if (g) g.innerHTML = unitWon(res.amount, data.unit); - td.classList.add("is-stale"); // 수수료·차감 매출은 새로고침 때 다시 계산 + // 총매출·수수료·차감 매출을 바로 바꾼다(기본 보기 = 차감 매출 — 예전엔 총매출만 바뀌어 계산식 결과가 안 보였다). + // 서버가 수수료를 안 돌려주면(광고비) 그 칸만 새로고침 때까지 흐리게. + const shown = { "v-gross": res.amount, "v-commission": res.commission, "v-net": res.net }; + Object.keys(shown).forEach(function (cls) { + const s = td.querySelector("." + cls); + if (s && shown[cls] != null) s.innerHTML = unitWon(shown[cls], data.unit); + }); + td.classList.toggle("is-stale", res.net == null); manualDirty = true; return true; });