feat(performance): 앞날 입력·계산식 칸·기간 합계 맨 위
- 매출 수동 입력·광고비 날짜 칸과 엑셀·광고 보고서 업로드에서 오늘 이후 날짜 허용 - 이번달 등 일자별 표의 기간 합계 행을 제목 행 바로 아래로 - 날짜 칸에 = 없이 1000+2000 계산식 입력(formula.parse_amount), 식은 마이그레이션 008 formula 열에 저장해 파랑 굵은 숫자·다시 누르면 식 - 광고비 탭 직접 입력값은 굵게 해제(굵게는 계산식만) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -393,36 +393,38 @@ def api_events(request: Request, code: str, from_: str = Query(..., alias="from"
|
||||
return JSONResponse({"rows": rows, "truncated": len(rows) >= 500})
|
||||
|
||||
|
||||
def _cell_amount(raw: Any) -> tuple[int | None, str | None]:
|
||||
"""날짜 칸 입력(매출 수동 입력·광고비) → (금액, 계산식). 빈 칸 = 지움."""
|
||||
from .formula import FormulaError, parse_amount # noqa: WPS433
|
||||
|
||||
try:
|
||||
amount, formula = parse_amount(raw)
|
||||
except FormulaError as exc:
|
||||
raise HTTPException(status_code=400, detail=f"{exc} (숫자 또는 1000+2000 같은 계산식)") from None
|
||||
if amount is not None and abs(amount) > MAX_MANUAL_AMOUNT:
|
||||
raise HTTPException(status_code=400, detail="금액이 너무 큽니다.")
|
||||
return amount, formula
|
||||
|
||||
|
||||
@router.put("/api/manual-sales/{code}/{day}")
|
||||
def api_manual_sale(request: Request, code: str, day: str, payload: dict[str, Any] = Body(...)) -> JSONResponse:
|
||||
"""수동 입력 — 그 쇼핑몰 수동 입력이 켜져 있을 때만, 오늘까지. amount 가 비면 지움(그날은 다시 API 값)."""
|
||||
"""수동 입력 — 그 쇼핑몰 수동 입력이 켜져 있을 때만, 앞으로의 날도 가능(2026-10-21). amount 가 비면 지움(그날은 다시 API 값).
|
||||
amount 는 숫자 또는 계산식(1000+2000 — formula.parse_amount)."""
|
||||
from .db import ManualMigrationNeeded # noqa: WPS433
|
||||
|
||||
store, user = common.require_store(request) # 모듈 권한자 누구나(켜고 끄기는 관리자 설정)
|
||||
_code_or_404(store, code)
|
||||
d = _parse_date(day)
|
||||
if d > today_kst():
|
||||
raise HTTPException(status_code=400, detail="앞으로의 날짜는 입력할 수 없습니다.")
|
||||
m = next((x for x in store.list_marketplaces() if x["code"] == code), {})
|
||||
if not m.get("manual_input"):
|
||||
raise HTTPException(status_code=400, detail="이 쇼핑몰은 수동 입력을 쓰지 않습니다(실적 설정에서 켜세요).")
|
||||
raw = payload.get("amount")
|
||||
amount: int | None
|
||||
if raw in (None, ""):
|
||||
amount = None
|
||||
else:
|
||||
try:
|
||||
amount = int(Decimal(str(raw).replace(",", "").strip()))
|
||||
except (InvalidOperation, ValueError):
|
||||
raise HTTPException(status_code=400, detail="금액은 숫자(원)로 입력하세요.") from None
|
||||
if abs(amount) > MAX_MANUAL_AMOUNT:
|
||||
raise HTTPException(status_code=400, detail="금액이 너무 큽니다.")
|
||||
amount, formula = _cell_amount(payload.get("amount"))
|
||||
try:
|
||||
store.set_manual_sale(code, d, amount, user=user.get("email", ""))
|
||||
store.set_manual_sale(code, d, amount, user=user.get("email", ""), formula=formula)
|
||||
except ManualMigrationNeeded:
|
||||
raise HTTPException(status_code=503, detail=MANUAL_MIGRATION_HELP) from None
|
||||
api_amount = store.api_amount(code, d)
|
||||
return JSONResponse({"ok": True, "code": code, "date": d.isoformat(), "manual": amount,
|
||||
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})
|
||||
|
||||
|
||||
@@ -493,24 +495,12 @@ def api_ad_spend(request: Request, channel: str, day: str, payload: dict[str, An
|
||||
d = _parse_date(day)
|
||||
if d is None:
|
||||
raise HTTPException(status_code=400, detail="날짜가 필요합니다.")
|
||||
if d > today_kst():
|
||||
raise HTTPException(status_code=400, detail="앞으로의 날짜는 입력할 수 없습니다.")
|
||||
raw = payload.get("amount")
|
||||
amount: int | None
|
||||
if raw in (None, ""):
|
||||
amount = None
|
||||
else:
|
||||
try:
|
||||
amount = int(Decimal(str(raw).replace(",", "").strip()))
|
||||
except (InvalidOperation, ValueError):
|
||||
raise HTTPException(status_code=400, detail="금액은 숫자(원)로 입력하세요.") from None
|
||||
if abs(amount) > MAX_MANUAL_AMOUNT:
|
||||
raise HTTPException(status_code=400, detail="금액이 너무 큽니다.")
|
||||
amount, formula = _cell_amount(payload.get("amount"))
|
||||
try:
|
||||
store.set_ad_spend(channel, d, amount, source="manual", user=user.get("email", ""))
|
||||
store.set_ad_spend(channel, d, amount, source="manual", user=user.get("email", ""), formula=formula)
|
||||
except AdMigrationNeeded as exc:
|
||||
raise HTTPException(status_code=503, detail=_ad_migration_help(exc)) from None
|
||||
return JSONResponse({"ok": True, "channel": channel, "date": d.isoformat(), "manual": amount,
|
||||
return JSONResponse({"ok": True, "channel": channel, "date": d.isoformat(), "manual": amount, "formula": formula,
|
||||
"amount": amount or 0})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user