feat(cupang): 출고 상세 상자 목록에 상자별 무게 합계
- 상자마다 무게 칸 = 상자에 든 제품 수량 × 포장무게(설정(제품명)의 지금 값) 합계, 상자번호처럼 상자 단위 한 칸 - 무게가 없는 제품이 섞이면 아는 무게만 더하고 "일부 미입력"(말풍선에 빠진 코드), 모두 없으면 — - 상자 목록 엑셀에도 무게(g) 열(혼합 상자는 세로 병합) - 포장무게 칸(마이그레이션 007)이 없으면 무게 칸·열 없이 예전 그대로 - tests/test_cupang_weight.py: 상자 무게 계산 + 엑셀 무게 열 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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]]:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "erp_base.html" %}
|
||||
|
||||
{% block head_extra %}<link rel="stylesheet" href="/static/cupang.css?v=20261002w" />{% endblock %}
|
||||
{% block head_extra %}<link rel="stylesheet" href="/static/cupang.css?v=20261002x" />{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<section class="cpg">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "erp_base.html" %}
|
||||
|
||||
{% block head_extra %}<link rel="stylesheet" href="/static/cupang.css?v=20261002w" />{% endblock %}
|
||||
{% block head_extra %}<link rel="stylesheet" href="/static/cupang.css?v=20261002x" />{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<section class="cpg">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "erp_base.html" %}
|
||||
|
||||
{% block head_extra %}<link rel="stylesheet" href="/static/cupang.css?v=20261002w" />{% endblock %}
|
||||
{% block head_extra %}<link rel="stylesheet" href="/static/cupang.css?v=20261002x" />{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<section class="cpg">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "erp_base.html" %}
|
||||
|
||||
{% block head_extra %}<link rel="stylesheet" href="/static/cupang.css?v=20261002w" />{% endblock %}
|
||||
{% block head_extra %}<link rel="stylesheet" href="/static/cupang.css?v=20261002x" />{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<section class="cpg">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "erp_base.html" %}
|
||||
|
||||
{% block head_extra %}<link rel="stylesheet" href="/static/cupang.css?v=20261002w" />{% endblock %}
|
||||
{% block head_extra %}<link rel="stylesheet" href="/static/cupang.css?v=20261002x" />{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{# 쿠팡 로켓 매출 — 발주 라인별 공급가·원가·물류비·마진 #}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "erp_base.html" %}
|
||||
|
||||
{% block head_extra %}<link rel="stylesheet" href="/static/cupang.css?v=20261002w" />{% endblock %}
|
||||
{% block head_extra %}<link rel="stylesheet" href="/static/cupang.css?v=20261002x" />{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{# 출고 묶음 보기 — 상자 계산 화면과 같은 3열 구성. 읽기 전용(수정 없음). #}
|
||||
@@ -80,9 +80,10 @@
|
||||
<col class="cpg-boxno-c-name" />
|
||||
<col class="cpg-boxno-c-code" />
|
||||
<col class="cpg-boxno-c-qty" />
|
||||
{% if box_weight %}<col class="cpg-boxno-c-weight" />{% endif %}
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr><th>상자번호</th><th>제품명</th><th>제품코드</th><th>수량</th></tr>
|
||||
<tr><th>상자번호</th><th>제품명</th><th>제품코드</th><th>수량</th>{% if box_weight %}<th title="상자에 든 제품의 수량 × 포장무게(설정(제품명)) 합계">무게</th>{% endif %}</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for b in box_list %}
|
||||
@@ -94,11 +95,21 @@
|
||||
<td title="{{ it.product_name }}">{{ it.product_name }}</td>
|
||||
<td class="cpg-boxno-code">{{ it.product_code }}</td>
|
||||
<td class="cpg-calc-num">{{ it.quantity }}</td>
|
||||
{% if box_weight and loop.first %}
|
||||
{# 상자 무게 합계 — 상자번호처럼 상자 단위로 한 칸. 무게 없는 제품이 있으면 표시 #}
|
||||
{% set miss = b.weight_missing or [] %}
|
||||
<td class="cpg-boxno-weight" rowspan="{{ b['items']|length }}"
|
||||
{% if miss %}title="포장무게 미입력: {{ miss|join(', ') }}{% if b.weight_g is not none %} — 이 제품을 뺀 합계{% endif %} (설정(제품명)에서 입력)"{% endif %}>
|
||||
{%- if b.weight_g is not none -%}
|
||||
{{ "{:,}".format(b.weight_g) }}<span class="cpg-weight-unit">g</span>{% if miss %}<span class="cpg-boxno-wmiss">일부 미입력</span>{% endif %}
|
||||
{%- else -%}<span class="erp-muted">—</span>{%- endif -%}
|
||||
</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% if not box_list %}
|
||||
<tr><td colspan="4" class="erp-muted">상자 정보가 없습니다.</td></tr>
|
||||
<tr><td colspan="{{ 5 if box_weight else 4 }}" class="erp-muted">상자 정보가 없습니다.</td></tr>
|
||||
{% endif %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user