feat(cupang): 출고 상세 상자 목록에 상자별 무게 합계
- 상자마다 무게 칸 = 상자에 든 제품 수량 × 포장무게(설정(제품명)의 지금 값) 합계, 상자번호처럼 상자 단위 한 칸 - 무게가 없는 제품이 섞이면 아는 무게만 더하고 "일부 미입력"(말풍선에 빠진 코드), 모두 없으면 — - 상자 목록 엑셀에도 무게(g) 열(혼합 상자는 세로 병합) - 포장무게 칸(마이그레이션 007)이 없으면 무게 칸·열 없이 예전 그대로 - tests/test_cupang_weight.py: 상자 무게 계산 + 엑셀 무게 열 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -121,3 +121,49 @@ def test_update_without_column_ignores_weight():
|
||||
st.update_product(product_id=7, product_name="미라클통", product_code="MS-9809", weight_g=950)
|
||||
sql, params = _main_sql(pool, "UPDATE cupang_products")
|
||||
assert "weight_g" not in sql and sql.count("%s") == len(params) == 4
|
||||
|
||||
|
||||
# ── 상자 목록 무게 합계(상자별) ──────────────────────────────────────
|
||||
class _WStore:
|
||||
def __init__(self, enabled: bool, weights: dict[str, int | None]):
|
||||
self.enabled, self.weights = enabled, weights
|
||||
|
||||
def weight_enabled(self) -> bool:
|
||||
return self.enabled
|
||||
|
||||
def list_products(self, include_inactive: bool = False):
|
||||
return [{"product_code": c, "weight_g": w} for c, w in self.weights.items()]
|
||||
|
||||
|
||||
def _boxes():
|
||||
mt = {"product_name": "멀티 5,000ml x4", "product_code": "MT-5000_4", "quantity": 2}
|
||||
mix = [{"product_name": "미라클 통 점보 x2", "product_code": "MT-7000_2", "quantity": 6},
|
||||
{"product_name": "무게 없음", "product_code": "XX-0001", "quantity": 1}]
|
||||
return [{"no": 1, "kind": "product", "items": [mt]},
|
||||
{"no": 2, "kind": "mix", "items": mix},
|
||||
{"no": 3, "kind": "product", "items": [{"product_name": "없음", "product_code": "XX-0001", "quantity": 3}]}]
|
||||
|
||||
|
||||
def test_box_weights():
|
||||
from app.modules.cupang.router import _attach_box_weights
|
||||
boxes = _boxes()
|
||||
assert _attach_box_weights(_WStore(True, {"MT-5000_4": 1800, "MT-7000_2": 1060, "XX-0001": None}), boxes) is True
|
||||
assert boxes[0]["weight_g"] == 3600 and boxes[0]["weight_missing"] == [] # 2 × 1,800
|
||||
assert boxes[1]["weight_g"] == 6360 and boxes[1]["weight_missing"] == ["XX-0001"] # 6 × 1,060, 무게 없는 제품은 빼고
|
||||
assert boxes[2]["weight_g"] is None and boxes[2]["weight_missing"] == ["XX-0001"] # 하나도 모르면 None
|
||||
plain = _boxes()
|
||||
assert _attach_box_weights(_WStore(False, {}), plain) is False and "weight_g" not in plain[0]
|
||||
|
||||
|
||||
def test_box_list_workbook_weight_column():
|
||||
from app.modules.cupang.export import build_box_list_workbook
|
||||
from app.modules.cupang.router import _attach_box_weights
|
||||
boxes = _boxes()
|
||||
_attach_box_weights(_WStore(True, {"MT-5000_4": 1800, "MT-7000_2": 1060}), boxes)
|
||||
ws = build_box_list_workbook({"ship_date": "2026-10-02", "center_name_snapshot": "대구3"}, boxes, with_weight=True).active
|
||||
assert [ws.cell(row=2, column=c).value for c in range(1, 6)] == ["상자번호", "제품명", "제품코드", "수량", "무게(g)"]
|
||||
assert ws.cell(row=3, column=5).value == 3600 and ws.cell(row=4, column=5).value == 6360
|
||||
assert any(str(r) == "E4:E5" for r in ws.merged_cells.ranges) # 혼합 상자 무게 칸 세로 병합
|
||||
assert ws.cell(row=6, column=5).value is None
|
||||
ws2 = build_box_list_workbook({"ship_date": "2026-10-02"}, _boxes()).active # 예전처럼 4열
|
||||
assert ws2.cell(row=2, column=5).value is None and ws2.cell(row=2, column=4).value == "수량"
|
||||
|
||||
Reference in New Issue
Block a user