From ef4658fb1ddf17c13eb3cd20a1d91d976d1554d9 Mon Sep 17 00:00:00 2001 From: king Date: Mon, 22 Jun 2026 15:23:00 +0900 Subject: [PATCH] =?UTF-8?q?feat(dispatch):=20=EC=B6=9C=EA=B3=A0=20?= =?UTF-8?q?=EC=97=91=EC=85=80=20=EC=88=98=EB=9F=89=EC=97=90=20=5FN=20?= =?UTF-8?q?=EB=B0=B0=EC=88=98=20=EB=B0=98=EC=98=81=20+=20=EC=95=84?= =?UTF-8?q?=EC=9D=B4=ED=85=9C=EC=BD=94=EB=93=9C=20base=20=ED=91=9C?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - seller_sku 끝 _<숫자>는 '같은 상품 N개' → 주문 수량을 qty×N 으로 계산 - 아이템 코드 칸은 접미사 제거한 base 코드(MT-0320) 표기 - 상품명은 base 코드로 itemcode_db 조회(기존) Co-Authored-By: Claude Opus 4.8 --- app/modules/dispatch/export.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/app/modules/dispatch/export.py b/app/modules/dispatch/export.py index 4399c29..2fbddfd 100644 --- a/app/modules/dispatch/export.py +++ b/app/modules/dispatch/export.py @@ -47,6 +47,19 @@ def export_filename(*, dispatch_date: str, platform: str) -> str: return f"{stamp}_{suffix}.xlsx" +def split_sku(seller_sku: str) -> tuple[str, int]: + """seller_sku → (아이템코드, 배수). + + 끝의 `_<숫자>` 는 '같은 상품 N개'를 뜻한다(예: MT-0320_3 → 코드 MT-0320, 3개). + 접미사가 없으면 배수 1. + """ + s = (seller_sku or "").strip() + m = re.search(r"_(\d+)$", s) + if m: + return s[: m.start()], int(m.group(1)) + return s, 1 + + def resolve_product_name(seller_sku: str, name_map: dict[str, str], fallback: str = "") -> str: """아이템코드(seller_sku)로 itemcode_db 상품명을 찾는다. @@ -107,11 +120,13 @@ def build_workbook_bytes( for it in items: row_data = dict(box) sku = it.get("seller_sku", "") or "" + base_code, mult = split_sku(sku) row_data["product_name"] = resolve_product_name( - sku, name_map, fallback=it.get("product_name", "") or "" + base_code, name_map, fallback=it.get("product_name", "") or "" ) - row_data["seller_sku"] = sku - row_data["quantity"] = it.get("quantity", "") if it.get("quantity") is not None else "" + row_data["seller_sku"] = base_code # 접미사(_N) 제거한 실제 아이템코드 + qty = it.get("quantity") + row_data["quantity"] = (int(qty) * mult) if qty is not None else "" ws.append([_cell(row_data.get(key, "")) for _, key in _COLUMNS]) _autosize(ws, headers)