diff --git a/CLAUDE.md b/CLAUDE.md index 7c6fd9f..ef70187 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 + 시드) 입력·표시·정렬. 출고 상세 상자 목록에 상자별 무게 합계(수량 × 지금 포장무게, `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/cupang/`, `cupang_db`) — 출고 달력/상자 계산, 상품은 `itemcode_db` 읽기 전용. 설정(제품명)에서 제품별 포장무게(g, `cupang_products.weight_g`, 마이그레이션 007 + 시드) 입력·표시·정렬. 출고 상세 상자 목록에 상자별 무게 합계(수량 × 지금 포장무게, `router._attach_box_weights`, 무게 없는 제품은 "일부 미입력", 화면은 kg 소수 첫째 자리 사사오입 `router._g_to_kg` + 맨 아래 수량·무게 합계 행) — 상자 목록 엑셀에도 무게(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/router.py b/app/modules/cupang/router.py index fb6726c..9a62e10 100644 --- a/app/modules/cupang/router.py +++ b/app/modules/cupang/router.py @@ -11,6 +11,7 @@ from __future__ import annotations import calendar as _calendar import json +from decimal import ROUND_HALF_UP, Decimal from fractions import Fraction from typing import Any @@ -413,6 +414,17 @@ def detail(request: Request, shipment_id: int) -> HTMLResponse: 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) + # 상자 목록 합계 행 — 수량 합계와 무게 합계(kg, 소수 첫째 자리) + box_qty_total = sum(int(it.get("quantity") or 0) for b in box_list for it in (b.get("items") or [])) + box_weight_total = None + box_weight_partial = False + if box_weight: + for b in box_list: + b["weight_kg"] = _g_to_kg(b.get("weight_g")) + if b.get("weight_g") is not None: + box_weight_total = (box_weight_total or 0) + int(b["weight_g"]) + if b.get("weight_missing"): + box_weight_partial = True return render_template( request, @@ -429,6 +441,9 @@ def detail(request: Request, shipment_id: int) -> HTMLResponse: "box_list": box_list, # 상자별 무게 합계(g) 칸 — 포장무게(마이그레이션 007) 가 있을 때만 "box_weight": box_weight, + "box_qty_total": box_qty_total, + "box_weight_total_kg": _g_to_kg(box_weight_total), + "box_weight_partial": box_weight_partial, "total_qty": total_qty, }, ) @@ -1190,6 +1205,14 @@ def _compute_boxes(store: Any, raw_items: list[Any]) -> dict[str, Any]: } +def _g_to_kg(grams: Any) -> str | None: + """g → kg 표시 글자 — 소수 둘째 자리에서 반올림(사사오입)해 첫째 자리까지. 예: 1,250g → "1.3".""" + if grams is None: + return None + kg = (Decimal(int(grams)) / 1000).quantize(Decimal("0.1"), rounding=ROUND_HALF_UP) + return f"{kg:,.1f}" + + def _attach_box_weights(store: Any, box_list: list[dict[str, Any]]) -> bool: """상자마다 무게 합계(g) — 상자에 든 제품마다 수량 × 포장무게(설정(제품명)의 지금 값, cupang_products.weight_g). diff --git a/app/modules/cupang/templates/cupang/box_calc.html b/app/modules/cupang/templates/cupang/box_calc.html index dce249a..756a7eb 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 dd64f6d..ea54170 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 3eb1934..f687525 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 a9c2594..7b51cbf 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 332d310..8a62d6e 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 0746568..e61fc7c 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열 구성. 읽기 전용(수정 없음). #} @@ -101,7 +101,7 @@ {%- if b.weight_g is not none -%} - {{ "{:,}".format(b.weight_g) }}g{% if miss %}일부 미입력{% endif %} + {{ b.weight_kg }}kg{% if miss %}일부 미입력{% endif %} {%- else -%}—{%- endif -%} {% endif %} @@ -112,6 +112,25 @@ 상자 정보가 없습니다. {% endif %} + {% if box_list %} + {# 합계 행 — 수량 합계, 무게 합계(kg). 무게 없는 제품이 있으면 아는 무게만 더한 값 #} + + + 합계 + + + {{ "{:,}".format(box_qty_total) }} + {% if box_weight %} + + {%- if box_weight_total_kg is not none -%} + {{ box_weight_total_kg }}kg{% if box_weight_partial %}일부 미입력{% endif %} + {%- else -%}—{%- endif -%} + + {% endif %} + + + {% endif %} diff --git a/app/static/cupang.css b/app/static/cupang.css index 83800eb..0889485 100644 --- a/app/static/cupang.css +++ b/app/static/cupang.css @@ -1362,6 +1362,14 @@ a.cpg-boxno-dl:hover { background: #1a5c38; border-color: #1a5c38; font-weight: vertical-align: middle; } .cpg-boxno-code { color: var(--color-midtone-gray); font-family: var(--font-geist-mono); } +/* 합계 행 — 수량·무게(kg) 합계. 클릭 체크 대상 아님 */ +.cpg-boxno-table tfoot td { + background: var(--color-ghost-gray); + font-weight: 700; + border-top: 1px solid var(--color-subtle-ash); + border-bottom: 0; +} +.cpg-boxno-table tfoot .cpg-boxno-cell { font-family: inherit; } .cpg-boxno-table tbody tr.is-boxtop td { border-top: 1px solid var(--color-cloud-gray); } .cpg-boxno-table tbody tr { cursor: pointer; } .cpg-boxno-table tbody tr:hover td { background: var(--color-ghost-gray); } diff --git a/tests/test_cupang_weight.py b/tests/test_cupang_weight.py index f3b613f..fc8cfa1 100644 --- a/tests/test_cupang_weight.py +++ b/tests/test_cupang_weight.py @@ -167,3 +167,14 @@ def test_box_list_workbook_weight_column(): 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 == "수량" + + +def test_g_to_kg_rounds_half_up_to_one_decimal(): + """출고 상세 상자 목록 무게(kg) — 소수 둘째 자리에서 반올림해 첫째 자리까지.""" + from app.modules.cupang.router import _g_to_kg + + assert _g_to_kg(3000) == "3.0" + assert _g_to_kg(1250) == "1.3" # 1.25 → 1.3 (사사오입) + assert _g_to_kg(1249) == "1.2" + assert _g_to_kg(1234567) == "1,234.6" + assert _g_to_kg(None) is None