From 439ecb035c80e995ea93917fe7f5d2004da3e622 Mon Sep 17 00:00:00 2001 From: king Date: Fri, 30 Oct 2026 12:49:48 +0900 Subject: [PATCH] =?UTF-8?q?feat(=EB=B0=B0=EC=86=A1):=20=EA=B8=B0=EA=B0=84?= =?UTF-8?q?=EB=B3=84=20=EB=B0=9C=EC=86=A1=20=EC=88=98=EB=9F=89=20=EC=97=91?= =?UTF-8?q?=EC=85=80=EC=97=90=20=EC=84=B8=ED=8A=B8=EB=B3=84=20=EC=9A=94?= =?UTF-8?q?=EC=95=BD=20=EC=8B=9C=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 「세트별 요약」: 세트 코드 × 날짜 피벗, 낱개로 풀기 전 세트 단위 수량(_N 배수 반영) - 아이템별·세트별 요약 시트 생성 코드를 하나로 합침 - 다운로드 카드 안내 문구·모듈 문서 갱신 Co-Authored-By: Claude Opus 5.5 --- app/modules/dispatch/CLAUDE.md | 2 +- app/modules/dispatch/export.py | 45 ++++++++++++------- .../dispatch/templates/dispatch/batches.html | 4 +- .../dispatch/tests/test_period_export.py | 8 +++- docs/DISPATCH_MODULE.md | 2 +- 5 files changed, 39 insertions(+), 22 deletions(-) diff --git a/app/modules/dispatch/CLAUDE.md b/app/modules/dispatch/CLAUDE.md index c7696e0..dedd69f 100644 --- a/app/modules/dispatch/CLAUDE.md +++ b/app/modules/dispatch/CLAUDE.md @@ -10,5 +10,5 @@ - 작업 상태 토글(`dispatch_logs` 기록). - 받는 사람 이름/전화/주소는 상자 단위로 저장(작업 카드 표시 + 출고 엑셀 생성용) — **개인정보**, 로그·외부 전송 주의. - 배치 다운로드 zip 에 업로드 원본 + 취합 출고 엑셀(`YYYY.MM.DD(Ddd)_tictoc|shopee.xlsx`) 포함. -- 기간별 발송 수량 엑셀(`/dispatch/period-export`, **수퍼 관리자 전용**): 날짜별·아이템별 수량(`_N` 배수 반영, 세트는 BOM 으로 낱개 분해) + 아이템×날짜 요약 시트. +- 기간별 발송 수량 엑셀(`/dispatch/period-export`, **수퍼 관리자 전용**): 날짜별·아이템별 수량(`_N` 배수 반영, 세트는 BOM 으로 낱개 분해) + 아이템×날짜 요약 시트 + 세트×날짜 요약 시트(낱개로 풀기 전 세트 수량). - 엑셀은 openpyxl 파싱/생성. diff --git a/app/modules/dispatch/export.py b/app/modules/dispatch/export.py index 8e48edb..1d485e3 100644 --- a/app/modules/dispatch/export.py +++ b/app/modules/dispatch/export.py @@ -310,17 +310,22 @@ def build_period_xlsx( name_map: dict[str, str] | None = None, set_bom: dict[str, list[dict[str, Any]]] | None = None, ) -> bytes: - """기간별 발송 수량 xlsx(세트는 낱개로 풀어 합산). 시트 2개. + """기간별 발송 수량 xlsx(세트는 낱개로 풀어 합산). 시트 3개. - 「날짜별」: 발송 날짜 / 아이템 코드 / 상품이름 / 수량 (날짜·코드 오름차순, 맨 끝 합계) - 「아이템별 요약」: 아이템 코드 / 상품이름 / 날짜1..N / 합계 (맨 끝 날짜별 합계 행) + - 「세트별 요약」: 세트 코드 / 상품이름 / 날짜1..N / 합계 — 낱개로 풀기 전 세트 단위 수량 """ from openpyxl import Workbook # noqa: WPS433 from openpyxl.styles import Alignment, Font, PatternFill from openpyxl.utils import get_column_letter + set_bom = set_bom or {} dates, names, qty = aggregate_shipped(rows, name_map, set_bom) codes = sorted(names) + # 세트 행만 BOM 없이 다시 합산하면 세트 단위 수량이 된다(_N 배수 반영은 같다). + set_rows = [r for r in rows if split_sku(r.get("seller_sku", ""))[0].strip().upper() in set_bom] + _sd, set_names, set_qty = aggregate_shipped(set_rows, name_map) head_fill = PatternFill("solid", fgColor="E2E8F0") head_font = Font(bold=True) @@ -354,22 +359,28 @@ def build_period_xlsx( _style_head(ws) _autosize(ws, headers) - # 시트 2 — 아이템(행) × 날짜(열) 요약 - ws2 = wb.create_sheet("아이템별 요약") - headers2 = ["아이템 코드", "상품이름", *dates, "합계"] - ws2.append(headers2) - for code in codes: - per_day = [qty.get((d, code), 0) for d in dates] - ws2.append([code, names.get(code, ""), *[n or None for n in per_day], sum(per_day)]) - day_totals = [sum(qty.get((d, c), 0) for c in codes) for d in dates] - ws2.append(["합계", "", *day_totals, sum(day_totals)]) - for cell in ws2[ws2.max_row]: - cell.font = bold - _style_head(ws2) - ws2.freeze_panes = "C2" - _autosize(ws2, headers2) - for i in range(3, len(headers2) + 1): # 날짜 열은 좁게 고정 - ws2.column_dimensions[get_column_letter(i)].width = 12 + # 시트 2·3 — 코드(행) × 날짜(열) 요약. 날짜 열은 두 시트 모두 전체 발송 날짜로 맞춘다. + def _pivot(title: str, code_label: str, p_names: dict[str, str], + p_qty: dict[tuple[str, str], int]) -> None: + p_codes = sorted(p_names) + ws2 = wb.create_sheet(title) + headers2 = [code_label, "상품이름", *dates, "합계"] + ws2.append(headers2) + for code in p_codes: + per_day = [p_qty.get((d, code), 0) for d in dates] + ws2.append([code, p_names.get(code, ""), *[n or None for n in per_day], sum(per_day)]) + day_totals = [sum(p_qty.get((d, c), 0) for c in p_codes) for d in dates] + ws2.append(["합계", "", *day_totals, sum(day_totals)]) + for cell in ws2[ws2.max_row]: + cell.font = bold + _style_head(ws2) + ws2.freeze_panes = "C2" + _autosize(ws2, headers2) + for i in range(3, len(headers2) + 1): # 날짜 열은 좁게 고정 + ws2.column_dimensions[get_column_letter(i)].width = 12 + + _pivot("아이템별 요약", "아이템 코드", names, qty) + _pivot("세트별 요약", "세트 코드", set_names, set_qty) wb.properties.title = f"말레이시아 발송 수량 {date_from} ~ {date_to}" diff --git a/app/modules/dispatch/templates/dispatch/batches.html b/app/modules/dispatch/templates/dispatch/batches.html index 86a8274..12c4b27 100644 --- a/app/modules/dispatch/templates/dispatch/batches.html +++ b/app/modules/dispatch/templates/dispatch/batches.html @@ -149,8 +149,8 @@

기간별 발송 수량

기간 안 날짜별·아이템별 발송 수량을 엑셀로 받습니다. 세트는 낱개로 풀어 합산합니다. (수퍼 관리자 전용)

+ data-ko="기간 안 날짜별·아이템별 발송 수량을 엑셀로 받습니다. 세트는 낱개로 풀어 합산하고, 세트 수량은 별도 시트에 담습니다. (수퍼 관리자 전용)" + data-en="Download shipped quantities per date and item for the period. Sets are split into singles; set counts are on a separate sheet. (Super admin only)">기간 안 날짜별·아이템별 발송 수량을 엑셀로 받습니다. 세트는 낱개로 풀어 합산하고, 세트 수량은 별도 시트에 담습니다. (수퍼 관리자 전용)

~ diff --git a/app/modules/dispatch/tests/test_period_export.py b/app/modules/dispatch/tests/test_period_export.py index 93d6775..b2707a2 100644 --- a/app/modules/dispatch/tests/test_period_export.py +++ b/app/modules/dispatch/tests/test_period_export.py @@ -55,7 +55,7 @@ def test_build_period_xlsx_sheets(): rows=_ROWS, date_from="2026-10-01", date_to="2026-10-02", name_map={}, set_bom=_BOM ) wb = load_workbook(io.BytesIO(data)) - assert wb.sheetnames == ["날짜별", "아이템별 요약"] + assert wb.sheetnames == ["날짜별", "아이템별 요약", "세트별 요약"] ws = wb["날짜별"] rows = list(ws.iter_rows(values_only=True)) @@ -72,6 +72,12 @@ def test_build_period_xlsx_sheets(): assert rows2[2] == ("MT-0550", None, 8, None, 8) assert rows2[3] == ("합계", None, 16, 2, 18) + # 세트는 낱개로 풀기 전 세트 단위 수량, 날짜 열은 전체 발송 날짜와 같다. + rows3 = list(wb["세트별 요약"].iter_rows(values_only=True)) + assert rows3[0] == ("세트 코드", "상품이름", "2026-10-01", "2026-10-02", "합계") + assert rows3[1] == ("MY-0001", "Set", 4, None, 4) + assert rows3[2] == ("합계", None, 4, 0, 4) + def test_period_filename(): assert export.period_filename("2026-10-01", "2026-10-28") == "2026.10.01-2026.10.28_shipped_qty.xlsx" diff --git a/docs/DISPATCH_MODULE.md b/docs/DISPATCH_MODULE.md index 97f414e..eefa151 100644 --- a/docs/DISPATCH_MODULE.md +++ b/docs/DISPATCH_MODULE.md @@ -53,7 +53,7 @@ | `GET /dispatch/batches/{id}/picking` | SKU별 피킹 요약 | | `GET /dispatch/batches/{id}/handover` | Kagayaku 전달 리스트(A4 인쇄용) | | `POST /dispatch/parcels/{id}/toggle` | 작업 상태 1개 토글(AJAX, 즉시 저장) | -| `GET /dispatch/period-export?date_from=&date_to=` | **수퍼 관리자 전용** 기간별 발송 수량 xlsx(배치 목록 오른쪽 카드). 시트 「날짜별」(날짜/아이템코드/상품이름/수량) + 「아이템별 요약」(아이템 × 날짜 피벗, 합계). `_N` 배수 반영, 세트(MY-)는 itemcode_db BOM 으로 낱개 분해 후 합산(BOM 없는 세트가 있으면 422 로 목록 안내), 최대 366일 | +| `GET /dispatch/period-export?date_from=&date_to=` | **수퍼 관리자 전용** 기간별 발송 수량 xlsx(배치 목록 오른쪽 카드). 시트 「날짜별」(날짜/아이템코드/상품이름/수량) + 「아이템별 요약」(아이템 × 날짜 피벗, 합계) + 「세트별 요약」(세트 × 날짜 피벗, 낱개로 풀기 전 세트 수량). `_N` 배수 반영, 세트(MY-)는 itemcode_db BOM 으로 낱개 분해 후 합산(BOM 없는 세트가 있으면 422 로 목록 안내), 최대 366일 | 작업 상태(카드 버튼, 누르면 초록색): 상품준비 완료 → 포장완료 → 라벨부착 완료 → Kagayaku 전달 완료 → 택배스캔 확인. 모든 변경은 `dispatch_logs` 에 기록된다.