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)