feat(cupang): 제품 설정에 포장무게(g) — 수기 추가·수정 입력, 목록 표시·정렬

- cupang_products.weight_g (마이그레이션 007, NULL = 미입력, 0~1,000,000 CHECK)
- 초기 무게 39건 시드(cupang_products_weight_seed.sql) — 무게가 비어 있는 행만 채움, 실행 전 값 백업
- 수기 추가에 포장무게(g) 칸(1,070·1070g 허용, 비우면 기존 무게 유지), 수정 팝업에서 수정·지우기
- 등록 목록에 포장무게 열(1,070g, 숫자 정렬, 무게 없는 줄은 맨 뒤)
- 007 미적용이면 무게 칸·열을 숨기고 저장 SQL 에서도 뺌(기존 동작 그대로)
- tests/test_cupang_weight.py: 입력 읽기 + 무게 칸 유무별 등록·수정 SQL

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-02 13:43:17 +09:00
parent 968892d811
commit f02742497a
15 changed files with 376 additions and 24 deletions
+9 -3
View File
@@ -22,7 +22,7 @@ from fastapi import APIRouter, Body, Depends, File, Form, HTTPException, Request
from fastapi.responses import HTMLResponse, JSONResponse, RedirectResponse
from .holidays import holiday_name, is_holiday
from .store import SHIP_METHODS
from .store import SHIP_METHODS, parse_weight_g
router = APIRouter(prefix="/cupang", tags=["cupang"])
@@ -1349,6 +1349,8 @@ def products_page(request: Request) -> HTMLResponse:
"page_subtitle": "왼쪽 itemcode_db 목록에서 선택해 등록하면 폼 드롭다운에 노출됩니다.",
"products": store.list_products(include_inactive=True),
"registered_codes": [p["product_code"] for p in store.list_products(include_inactive=True)],
# 포장무게(g) — 마이그레이션 007 적용 전이면 무게 칸을 숨긴다
"weight_enabled": store.weight_enabled(),
"search_enabled": bool(reader and reader.enabled),
"search_reason": (reader.reason if reader else ""),
},
@@ -1412,6 +1414,7 @@ def product_upsert(
product_code: str = Form(...),
product_name: str = Form(...),
coupang_item_code: str = Form(""),
weight_g: str = Form(""),
sort_order: int = Form(0),
user: dict[str, Any] = Depends(_require_user),
) -> RedirectResponse:
@@ -1422,9 +1425,10 @@ def product_upsert(
store.upsert_product(
product_code=product_code,
product_name=product_name,
# 빈 값은 "미입력" 으로 보고 기존 쿠팡상품코드를 유지한다.
# 빈 값은 "미입력" 으로 보고 기존 쿠팡상품코드·포장무게를 유지한다.
coupang_item_code=(coupang_item_code.strip() or None),
sort_order=sort_order,
weight_g=parse_weight_g(weight_g),
)
except ValueError as exc:
raise HTTPException(status_code=400, detail=str(exc))
@@ -1457,7 +1461,8 @@ def product_edit(
payload: dict[str, Any] = Body(...),
user: dict[str, Any] = Depends(_require_user),
) -> JSONResponse:
"""등록된 제품 수정. body: {product_name, product_code, coupang_item_code}."""
"""등록된 제품 수정. body: {product_name, product_code, coupang_item_code, weight_g?}.
weight_g 키가 있으면 저장(빈 값 = 지움), 없으면 무게는 그대로."""
store = _store(request)
if store is None:
raise HTTPException(status_code=503, detail="cupang_db 미설정")
@@ -1467,6 +1472,7 @@ def product_edit(
product_name=str(payload.get("product_name") or ""),
product_code=str(payload.get("product_code") or ""),
coupang_item_code=str(payload.get("coupang_item_code") or ""),
weight_g=(parse_weight_g(payload.get("weight_g")) if "weight_g" in payload else ...),
)
except KeyError:
raise HTTPException(status_code=404, detail="제품을 찾을 수 없습니다.")