diff --git a/CLAUDE.md b/CLAUDE.md index e4c826a..81f05d5 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -31,7 +31,7 @@ Claude Code는 이 저장소에서 작업을 시작하기 전에 **반드시 아 - 반품관리 - 외부 쇼핑몰 API 연동 (카페24, 네이버 스마트스토어, 사방넷 등) - 개인경비 (`app/modules/expense/`, `expense_db`) -- 쿠팡 밀크런 (`app/modules/cupang/`, `cupang_db`) — 출고 달력/상자 계산, 상품은 `itemcode_db` 읽기 전용. 설정(제품명)에서 제품별 포장무게(g, `cupang_products.weight_g`, 마이그레이션 007 + 시드) 입력·표시·정렬. 출고 묶음은 **상자 계산 화면의 [분배 확정] 으로만** 만든다(신규 등록 폼 없음, `/cupang/new` 는 상자 계산으로 리다이렉트). 확정 조건: 미배분 상자 0 + 담긴 센터마다 출고방식(택배/파렛트) 선택. 확정 시 센터마다 출고 묶음 1건(`status=출고준비`, 센터입고일=출고일+1일, 상자 구성은 `cupang_shipments.box_plan` JSONB 에 스냅샷 — 혼합 상자 내용물·상자 종류 표시용) + 출고리스트 엑셀 자동 다운로드(`GET /cupang/export.xlsx?date=`, 시트명 YYYYMMDD). 양식 생성은 `app/modules/cupang/export.py` 한 곳에서 만들어 xlsx·구글시트가 공유. `CUPANG_SHEET_ID` + 인증(사용자 OAuth `GOOGLE_SHEETS_OAUTH_REFRESH_TOKEN` 또는 서비스 계정 `GOOGLE_SHEETS_CREDENTIALS[_JSON]`) 설정 시 확정과 동시에 Google 스프레드시트에 출고일 시트를 생성/덮어쓰기(`app/integrations/google_sheets.py`, 미설정이면 조용히 skip). 출고 삭제(건별/날짜 전체) 시에도 같은 날짜 시트를 동기화 — 남은 출고가 있으면 다시 쓰고, 없으면 시트 삭제(문서에 시트가 하나뿐이면 내용만 비움). 작업 중 상태는 `cupang_box_calc_drafts` 에 이름 붙여 임시 저장/불러오기. 쿠팡 로켓 매출(`/cupang/sales`, `cupang_sales`·`cupang_sales_weekly`) — 발주 라인별 공급가·원가·물류비·마진 표. 기간/센터/유형/검색 조회, 행 CRUD, 구글 시트 양식 xlsx·csv 업로드(같은 발주번호+SKU+출고일+센터+수량은 덮어씀), 엑셀 다운로드. 광고비·할인 프로모션·장려금은 주차 단위(`cupang_sales_weekly`)로 보관하고 순마진은 화면에서 계산. 초기 데이터는 `scripts/sql/cupang_sales_seed.sql`. 쿠팡 발주 엑셀(xlsx) 다중 업로드 지원(`POST /cupang/api/box-calc/upload`, openpyxl) — F13 입고예정일의 하루 전 = 출고일, 22행부터 B=쿠팡상품코드·F=센터명·G=수량을 읽어 `cupang_products.coupang_item_code` 로 제품 매칭 후 센터별 합산 → 센터 단위로 상자 계산·자동 배분 +- 쿠팡 밀크런 (`app/modules/cupang/`, `cupang_db`) — 출고 달력/상자 계산, 상품은 `itemcode_db` 읽기 전용. 설정(제품명)에서 제품별 포장무게(g, `cupang_products.weight_g`, 마이그레이션 007 + 시드) 입력·표시·정렬. 출고 상세 상자 목록에 상자별 무게 합계(수량 × 지금 포장무게, `router._attach_box_weights`, 무게 없는 제품은 "일부 미입력") — 상자 목록 엑셀에도 무게(g) 열. 출고 묶음은 **상자 계산 화면의 [분배 확정] 으로만** 만든다(신규 등록 폼 없음, `/cupang/new` 는 상자 계산으로 리다이렉트). 확정 조건: 미배분 상자 0 + 담긴 센터마다 출고방식(택배/파렛트) 선택. 확정 시 센터마다 출고 묶음 1건(`status=출고준비`, 센터입고일=출고일+1일, 상자 구성은 `cupang_shipments.box_plan` JSONB 에 스냅샷 — 혼합 상자 내용물·상자 종류 표시용) + 출고리스트 엑셀 자동 다운로드(`GET /cupang/export.xlsx?date=`, 시트명 YYYYMMDD). 양식 생성은 `app/modules/cupang/export.py` 한 곳에서 만들어 xlsx·구글시트가 공유. `CUPANG_SHEET_ID` + 인증(사용자 OAuth `GOOGLE_SHEETS_OAUTH_REFRESH_TOKEN` 또는 서비스 계정 `GOOGLE_SHEETS_CREDENTIALS[_JSON]`) 설정 시 확정과 동시에 Google 스프레드시트에 출고일 시트를 생성/덮어쓰기(`app/integrations/google_sheets.py`, 미설정이면 조용히 skip). 출고 삭제(건별/날짜 전체) 시에도 같은 날짜 시트를 동기화 — 남은 출고가 있으면 다시 쓰고, 없으면 시트 삭제(문서에 시트가 하나뿐이면 내용만 비움). 작업 중 상태는 `cupang_box_calc_drafts` 에 이름 붙여 임시 저장/불러오기. 쿠팡 로켓 매출(`/cupang/sales`, `cupang_sales`·`cupang_sales_weekly`) — 발주 라인별 공급가·원가·물류비·마진 표. 기간/센터/유형/검색 조회, 행 CRUD, 구글 시트 양식 xlsx·csv 업로드(같은 발주번호+SKU+출고일+센터+수량은 덮어씀), 엑셀 다운로드. 광고비·할인 프로모션·장려금은 주차 단위(`cupang_sales_weekly`)로 보관하고 순마진은 화면에서 계산. 초기 데이터는 `scripts/sql/cupang_sales_seed.sql`. 쿠팡 발주 엑셀(xlsx) 다중 업로드 지원(`POST /cupang/api/box-calc/upload`, openpyxl) — F13 입고예정일의 하루 전 = 출고일, 22행부터 B=쿠팡상품코드·F=센터명·G=수량을 읽어 `cupang_products.coupang_item_code` 로 제품 매칭 후 센터별 합산 → 센터 단위로 상자 계산·자동 배분 - 휴가 관리 (`app/modules/vacation/`, `vacation_db`) — 월간 달력(구글식 bar)/연차·반차 신청/승인 워크플로/공휴일·연차 설정. 권한키 `vacation`·`vacation_approver` - 말레이시아 창고 재고관리 (`app/modules/malaysia/`, `malaysia_stock_db`) — 낱개(MT/MX/MZ) 입출고·조정, 세트(MY) BOM, 일일 재고조사(세트→낱개 자동 분해), 현재고 현황. 뚜껑(MD-)은 재고 집계 제외 — 단, 창고 랙에는 위치 확인용으로 배치 가능(`store.LID_ITEMS`). 상품은 `itemcode_db` 읽기 전용. 권한키 `malaysia` - 말레이시아 배송 (`app/modules/dispatch/`, `dispatch_db`) — TikTok·Shopee 출고관리. 플랫폼별 데이터 엑셀 업로드(TikTok=03_TikTok_Order_Export.xlsx, Shopee=Packing List.Doorstep Delivery.xlsx) → 1상자=1카드 출고 작업 리스트·SKU 피킹 요약·Kagayaku 전달표 자동 생성. 1상자 묶음 기준 Package ID > Tracking ID > Order ID, 같은 상자 같은 SKU 합산. 작업 상태 토글(`dispatch_logs` 기록). 받는 사람 이름/전화/주소는 상자 단위로 저장(작업 카드 표시 + 출고 엑셀 생성용 — 개인정보). 배치 다운로드 zip 에 업로드 원본 + 취합 출고 엑셀(`YYYY.MM.DD(Ddd)_tictoc|shopee.xlsx`) 포함. 엑셀은 openpyxl 파싱/생성. 권한키 `dispatch`. 상세는 `docs/DISPATCH_MODULE.md` diff --git a/app/modules/cupang/export.py b/app/modules/cupang/export.py index 0c74da6..6b273d3 100644 --- a/app/modules/cupang/export.py +++ b/app/modules/cupang/export.py @@ -193,10 +193,17 @@ def build_workbook(ship_date: str, shipments: list[dict[str, Any]]) -> Any: # ── 상자 목록(상자 번호별 내용물) ────────────────────────────── BOX_HEADERS = ["상자번호", "제품명", "제품코드", "수량"] BOX_WIDTHS_PX = {1: 70, 2: 240, 3: 110, 4: 70} +BOX_WEIGHT_HEADER = "무게(g)" # with_weight 일 때 5열 — 상자 무게 합계(상자번호처럼 상자 단위로 세로 병합) +BOX_WEIGHT_WIDTH_PX = 80 -def build_box_list_workbook(shipment: dict[str, Any], box_list: list[dict[str, Any]]) -> Any: - """상자 번호 · 제품명 · 제품코드 · 수량 한 줄씩. 시트명 = YYYYMMDD(요일).""" +def build_box_list_workbook( + shipment: dict[str, Any], box_list: list[dict[str, Any]], *, with_weight: bool = False +) -> Any: + """상자 번호 · 제품명 · 제품코드 · 수량 한 줄씩. 시트명 = YYYYMMDD(요일). + + with_weight 면 5열 "무게(g)" — 상자마다 box["weight_g"](라우터 _attach_box_weights), 모르면 빈칸.""" + headers = BOX_HEADERS + ([BOX_WEIGHT_HEADER] if with_weight else []) from openpyxl import Workbook from openpyxl.styles import Alignment, Border, Font, PatternFill, Side from openpyxl.utils import get_column_letter @@ -215,10 +222,10 @@ def build_box_list_workbook(shipment: dict[str, Any], box_list: list[dict[str, A ws.cell(row=1, column=1, value=f"{with_dow(ship_date)} {center} 상자 목록") ws.cell(row=1, column=1).font = Font(size=14, bold=True) - ws.merge_cells(start_row=1, start_column=1, end_row=1, end_column=len(BOX_HEADERS)) + ws.merge_cells(start_row=1, start_column=1, end_row=1, end_column=len(headers)) header_fill = PatternFill("solid", fgColor=HEADER_BG) - for idx, name in enumerate(BOX_HEADERS, start=1): + for idx, name in enumerate(headers, start=1): cell = ws.cell(row=2, column=idx, value=name) cell.font = Font(bold=True) cell.alignment = center_align @@ -235,18 +242,27 @@ def build_box_list_workbook(shipment: dict[str, Any], box_list: list[dict[str, A ws.cell(row=row, column=3, value=it.get("product_code") or "") ws.cell(row=row, column=4, value=int(it.get("quantity") or 0)) row += 1 - # 한 상자에 여러 제품이면 상자번호 칸을 세로로 합친다. + if with_weight and contents: + w = entry.get("weight_g") + ws.cell(row=first, column=5, value=(int(w) if w is not None else None)) + ws.cell(row=first, column=5).number_format = "#,##0" + # 한 상자에 여러 제품이면 상자번호(·무게) 칸을 세로로 합친다. if row - first > 1: ws.merge_cells(start_row=first, start_column=1, end_row=row - 1, end_column=1) + if with_weight: + ws.merge_cells(start_row=first, start_column=5, end_row=row - 1, end_column=5) last = row - 1 for r in range(3, last + 1): - for col in range(1, len(BOX_HEADERS) + 1): + for col in range(1, len(headers) + 1): cell = ws.cell(row=r, column=col) cell.border = box cell.alignment = left_align if col == 2 else center_align - for col, px in BOX_WIDTHS_PX.items(): + widths = dict(BOX_WIDTHS_PX) + if with_weight: + widths[5] = BOX_WEIGHT_WIDTH_PX + for col, px in widths.items(): ws.column_dimensions[get_column_letter(col)].width = round(px / PX_PER_CHAR, 2) ws.row_dimensions[1].height = 24 diff --git a/app/modules/cupang/router.py b/app/modules/cupang/router.py index 1f218db..fb6726c 100644 --- a/app/modules/cupang/router.py +++ b/app/modules/cupang/router.py @@ -411,6 +411,8 @@ def detail(request: Request, shipment_id: int) -> HTMLResponse: ] calc = _compute_boxes(store, items) total_qty = sum(it["quantity"] for it in items) + box_list = _expand_box_list(ship, calc, items) + box_weight = _attach_box_weights(store, box_list) return render_template( request, @@ -424,7 +426,9 @@ def detail(request: Request, shipment_id: int) -> HTMLResponse: "shipment": ship, "items": items, "calc": calc, - "box_list": _expand_box_list(ship, calc, items), + "box_list": box_list, + # 상자별 무게 합계(g) 칸 — 포장무게(마이그레이션 007) 가 있을 때만 + "box_weight": box_weight, "total_qty": total_qty, }, ) @@ -432,7 +436,7 @@ def detail(request: Request, shipment_id: int) -> HTMLResponse: @router.get("/{shipment_id:int}/boxes.xlsx") def export_box_list_xlsx(request: Request, shipment_id: int) -> Any: - """상자 목록(상자번호·제품명·제품코드·수량) 엑셀 다운로드.""" + """상자 목록(상자번호·제품명·제품코드·수량·무게) 엑셀 다운로드.""" from io import BytesIO # noqa: WPS433 from fastapi.responses import StreamingResponse # noqa: WPS433 @@ -457,8 +461,9 @@ def export_box_list_xlsx(request: Request, shipment_id: int) -> Any: for ln in (ship.get("lines") or []) ] box_list = _expand_box_list(ship, _compute_boxes(store, items), items) + with_weight = _attach_box_weights(store, box_list) - wb = build_box_list_workbook(ship, box_list) + wb = build_box_list_workbook(ship, box_list, with_weight=with_weight) buf = BytesIO() wb.save(buf) buf.seek(0) @@ -1185,6 +1190,36 @@ def _compute_boxes(store: Any, raw_items: list[Any]) -> dict[str, Any]: } +def _attach_box_weights(store: Any, box_list: list[dict[str, Any]]) -> bool: + """상자마다 무게 합계(g) — 상자에 든 제품마다 수량 × 포장무게(설정(제품명)의 지금 값, cupang_products.weight_g). + + 상자에 넣는 값: weight_g = 아는 무게의 합(상자 안 제품 무게가 하나도 없으면 None), + weight_missing = 무게가 없는 제품코드 목록(일부만 없으면 합계는 그 제품을 뺀 값). + 포장무게 칸(마이그레이션 007)이 없으면 아무것도 넣지 않고 False. + """ + if not store.weight_enabled(): + return False + weights = { + str(p.get("product_code") or "").strip(): p.get("weight_g") + for p in store.list_products(include_inactive=True) + } + for box in box_list: + contents = box.get("items") or [] + total, missing = 0, [] + for it in contents: + code = str(it.get("product_code") or "").strip() + w = weights.get(code) + if w is None: + if code not in missing: + missing.append(code) + continue + total += int(w) * int(it.get("quantity") or 0) + known = any(weights.get(str(it.get("product_code") or "").strip()) is not None for it in contents) + box["weight_g"] = total if known else None + box["weight_missing"] = missing + return True + + def _expand_box_list( shipment: dict[str, Any], calc: dict[str, Any], items: list[dict[str, Any]] ) -> list[dict[str, Any]]: diff --git a/app/modules/cupang/templates/cupang/box_calc.html b/app/modules/cupang/templates/cupang/box_calc.html index 5ffb7b8..dce249a 100644 --- a/app/modules/cupang/templates/cupang/box_calc.html +++ b/app/modules/cupang/templates/cupang/box_calc.html @@ -1,6 +1,6 @@ {% extends "erp_base.html" %} -{% block head_extra %}{% endblock %} +{% block head_extra %}{% endblock %} {% block content %}
diff --git a/app/modules/cupang/templates/cupang/box_rules.html b/app/modules/cupang/templates/cupang/box_rules.html index e181339..dd64f6d 100644 --- a/app/modules/cupang/templates/cupang/box_rules.html +++ b/app/modules/cupang/templates/cupang/box_rules.html @@ -1,6 +1,6 @@ {% extends "erp_base.html" %} -{% block head_extra %}{% endblock %} +{% block head_extra %}{% endblock %} {% block content %}
diff --git a/app/modules/cupang/templates/cupang/index.html b/app/modules/cupang/templates/cupang/index.html index 39fc937..3eb1934 100644 --- a/app/modules/cupang/templates/cupang/index.html +++ b/app/modules/cupang/templates/cupang/index.html @@ -1,6 +1,6 @@ {% extends "erp_base.html" %} -{% block head_extra %}{% endblock %} +{% block head_extra %}{% endblock %} {% block content %}
diff --git a/app/modules/cupang/templates/cupang/products.html b/app/modules/cupang/templates/cupang/products.html index 9ced99c..a9c2594 100644 --- a/app/modules/cupang/templates/cupang/products.html +++ b/app/modules/cupang/templates/cupang/products.html @@ -1,6 +1,6 @@ {% extends "erp_base.html" %} -{% block head_extra %}{% endblock %} +{% block head_extra %}{% endblock %} {% block content %}
diff --git a/app/modules/cupang/templates/cupang/sales.html b/app/modules/cupang/templates/cupang/sales.html index 9c1a973..332d310 100644 --- a/app/modules/cupang/templates/cupang/sales.html +++ b/app/modules/cupang/templates/cupang/sales.html @@ -1,6 +1,6 @@ {% extends "erp_base.html" %} -{% block head_extra %}{% endblock %} +{% block head_extra %}{% endblock %} {% block content %} {# 쿠팡 로켓 매출 — 발주 라인별 공급가·원가·물류비·마진 #} diff --git a/app/modules/cupang/templates/cupang/view.html b/app/modules/cupang/templates/cupang/view.html index 3ca95c2..0746568 100644 --- a/app/modules/cupang/templates/cupang/view.html +++ b/app/modules/cupang/templates/cupang/view.html @@ -1,6 +1,6 @@ {% extends "erp_base.html" %} -{% block head_extra %}{% endblock %} +{% block head_extra %}{% endblock %} {% block content %} {# 출고 묶음 보기 — 상자 계산 화면과 같은 3열 구성. 읽기 전용(수정 없음). #} @@ -80,9 +80,10 @@ + {% if box_weight %}{% endif %} - 상자번호제품명제품코드수량 + 상자번호제품명제품코드수량{% if box_weight %}무게{% endif %} {% for b in box_list %} @@ -94,11 +95,21 @@ {{ it.product_name }} {{ it.product_code }} {{ it.quantity }} + {% if box_weight and loop.first %} + {# 상자 무게 합계 — 상자번호처럼 상자 단위로 한 칸. 무게 없는 제품이 있으면 표시 #} + {% set miss = b.weight_missing or [] %} + + {%- if b.weight_g is not none -%} + {{ "{:,}".format(b.weight_g) }}g{% if miss %}일부 미입력{% endif %} + {%- else -%}—{%- endif -%} + + {% endif %} {% endfor %} {% endfor %} {% if not box_list %} - 상자 정보가 없습니다. + 상자 정보가 없습니다. {% endif %} diff --git a/app/static/cupang.css b/app/static/cupang.css index 790da41..83800eb 100644 --- a/app/static/cupang.css +++ b/app/static/cupang.css @@ -1345,6 +1345,16 @@ a.cpg-boxno-dl:hover { background: #1a5c38; border-color: #1a5c38; font-weight: .cpg-boxno-c-name { width: auto; } .cpg-boxno-c-code { width: 100px; } .cpg-boxno-c-qty { width: 62px; } +.cpg-boxno-c-weight { width: 92px; } +/* 상자 무게 합계(g) — 상자 단위 한 칸(rowspan), 오른쪽 정렬 숫자. 무게 없는 제품이 있으면 작은 표시 */ +.cpg-boxno-weight { + text-align: right; vertical-align: middle; font-variant-numeric: tabular-nums; font-weight: 600; + border-left: 1px solid var(--color-cloud-gray); +} +.cpg-boxno-weight .cpg-weight-unit { font-weight: 400; } +.cpg-boxno-wmiss { + display: block; margin-top: 1px; font-size: 10.5px; font-weight: 600; color: #b45309; white-space: nowrap; +} .cpg-boxno-cell { text-align: center; font-weight: 700; font-family: var(--font-geist-mono); diff --git a/docs/DATABASES.md b/docs/DATABASES.md index 9922e2a..c29c512 100644 --- a/docs/DATABASES.md +++ b/docs/DATABASES.md @@ -208,7 +208,7 @@ DDL: `scripts/sql/cupang_db_init.sql` (멱등). DB·역할(`cupang_app`)·테이 박스 계산은 서버(`store.compute_boxes`)에서 재계산: `required_boxes = ceil(quantity / units_per_box)`. 클라이언트 계산은 미리보기용. -제품 카탈로그 `cupang_products`(제품코드 UNIQUE·제품명·쿠팡상품코드·활성) — **포장무게 `weight_g`**(INTEGER g, NULL = 미입력, 0~1,000,000 CHECK)는 마이그레이션 `scripts/sql/cupang_db_007_product_weight.sql`, 초기 값 시드 `scripts/sql/cupang_products_weight_seed.sql`(무게가 비어 있는 행만 채움, 실행 전 값은 `_cpg_weight_seed_backup` 에 남김). 007 미적용이면 화면은 무게 칸을 숨기고 그대로 동작. +제품 카탈로그 `cupang_products`(제품코드 UNIQUE·제품명·쿠팡상품코드·활성) — **포장무게 `weight_g`**(INTEGER g, NULL = 미입력, 0~1,000,000 CHECK)는 마이그레이션 `scripts/sql/cupang_db_007_product_weight.sql`, 초기 값 시드 `scripts/sql/cupang_products_weight_seed.sql`(무게가 비어 있는 행만 채움, 실행 전 값은 `_cpg_weight_seed_backup` 에 남김). 007 미적용이면 화면은 무게 칸을 숨기고 그대로 동작. 출고 상세의 상자별 무게 합계는 저장하지 않고 화면·엑셀을 만들 때 지금 무게로 계산한다. 임시 저장(`cupang_box_calc_drafts`)은 화면 상태 스냅샷만 담는다. 불러올 때 박스 수는 저장값을 쓰지 않고 서버에서 다시 계산하고, 그 위에 분배 내역을 얹는다(사라진 항목은 제외). 마이그레이션: `scripts/sql/cupang_db_003_box_calc_drafts.sql`. diff --git a/tests/test_cupang_weight.py b/tests/test_cupang_weight.py index a1fe79d..f3b613f 100644 --- a/tests/test_cupang_weight.py +++ b/tests/test_cupang_weight.py @@ -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 == "수량"