feat(cupang): 출고리스트 작성 — 입고센터별 입력·기본 택배·완료 진행 막대(%)
- 팝업에 입고센터 카드: [+ 입고센터 추가]·[센터 삭제], 센터마다 입고센터·출고방식·제품·출고를 따로 입력 (작성일·출고일·센터입고일·작업자는 공통), 출고방식 기본값 택배 - POST /cupang/api/outbound-sheet: centers 목록을 받아 센터 순서대로 출고일 시트 아래에 덧붙임 (엑셀 내려받기·올리기 1번씩, 순번 이어짐, 파렛트 센터만 배경색). centers 없으면 예전처럼 센터 1곳 - ?stream=1 이면 단계별 진행률을 NDJSON 으로 흘려보냄(내려받기 → 센터별 추가 → 올리기 → 완료/오류), 팝업은 막대 그래프와 %로 표시하고 단계 사이에도 조금씩 채움, 실패하면 빨간 막대 + 사유 - 테스트: pytest(센터별 입력 검사·여러 센터 한 번에 쓰기·진행 단계·스트림·충돌), Playwright(카드·진행 막대·완료·실패·모바일) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -392,6 +392,91 @@ def test_sheet_target_picks_writer_by_drive_file_type(monkeypatch):
|
||||
assert cupang_router._sheet_target(None)[2]["skipped"] is True
|
||||
|
||||
|
||||
def _multi_payload() -> dict[str, Any]:
|
||||
base = _payload()
|
||||
return {
|
||||
"document_date": base["document_date"], "ship_date": base["ship_date"],
|
||||
"center_arrival_date": base["center_arrival_date"], "worker": "",
|
||||
"centers": [
|
||||
{"center": "인천32", "ship_method": "파렛트", "outbound": "2파렛트", "lines": base["lines"]},
|
||||
{"center": "대구3", "ship_method": "택배", "outbound": "",
|
||||
"lines": [{"code": "MT-3000", "name": "중형", "quantity": 30}]},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def test_clean_entries_per_center_shares_dates_and_worker():
|
||||
entries = cupang_router._clean_outbound_entries(_multi_payload())
|
||||
assert [e["center_name_snapshot"] for e in entries] == ["인천32", "대구3"]
|
||||
assert [e["ship_method"] for e in entries] == ["파렛트", "택배"]
|
||||
assert all(e["ship_date"] == "2026-10-26" and e["worker"] == WORKER for e in entries)
|
||||
assert len(cupang_router._clean_outbound_entries(_payload())) == 1 # centers 없으면 센터 1곳
|
||||
|
||||
|
||||
@pytest.mark.parametrize("centers, words", [
|
||||
([], "1곳 이상"),
|
||||
([{"center": "a", "ship_method": "택배", "lines": [{"code": "A", "name": "가", "quantity": 1}]}] * 21, "20곳"),
|
||||
([{"center": "a", "ship_method": "택배", "lines": [{"code": "A", "name": "가", "quantity": 1}]},
|
||||
{"center": "", "ship_method": "택배", "lines": [{"code": "A", "name": "가", "quantity": 1}]}], "2번째 입고센터: 입고센터"),
|
||||
])
|
||||
def test_clean_entries_rejects_bad_centers(centers, words):
|
||||
with pytest.raises(HTTPException) as err:
|
||||
cupang_router._clean_outbound_entries({**_multi_payload(), "centers": centers})
|
||||
assert err.value.status_code == 400 and words in err.value.detail
|
||||
|
||||
|
||||
def test_xlsx_multi_center_one_download_one_upload_with_progress():
|
||||
drive = FakeDrive(_xlsx_bytes({"20261026(월)": _sheet_rows(4)}))
|
||||
steps: list[tuple[int, int, str]] = []
|
||||
res = cupang_router._run_outbound_write(
|
||||
_xlsx_writer(drive), "f", cupang_router._clean_outbound_entries(_multi_payload()),
|
||||
lambda p, until, step: steps.append((p, until, step)))
|
||||
assert drive.uploads == 1
|
||||
assert [(c["center"], c["first_row"], c["last_row"]) for c in res["centers"]] == [("인천32", 10, 11), ("대구3", 12, 12)]
|
||||
assert (res["first_row"], res["last_row"], res["line_count"]) == (10, 12, 3)
|
||||
ws = _load(drive)["20261026(월)"]
|
||||
assert [ws[f"B{r}"].value for r in (10, 11, 12)] == [5, 6, 7] # 순번은 센터를 넘어 이어짐
|
||||
assert ws["F12"].value == "대구3" and ws["G12"].value == "택배"
|
||||
assert ws["B10"].fill.fgColor.rgb.endswith(PALLET_BG) and ws["B12"].fill.fill_type is None
|
||||
assert [s[0] for s in steps] == [5, 40, 60, 80] and steps[1][2] == "인천32 추가 중 (1/2)"
|
||||
assert all(p < until for p, until, _ in steps)
|
||||
|
||||
|
||||
def test_xlsx_multi_center_new_sheet_then_append():
|
||||
drive = FakeDrive(_xlsx_bytes({"20261023(금)": _sheet_rows(1)}))
|
||||
res = cupang_router._run_outbound_write(
|
||||
_xlsx_writer(drive), "f", cupang_router._clean_outbound_entries(_multi_payload()), lambda *a: None)
|
||||
assert [(c["first_row"], c["last_row"]) for c in res["centers"]] == [(6, 7), (8, 8)] and drive.uploads == 1
|
||||
ws = _load(drive)["20261026(월)"]
|
||||
assert ws["B5"].value == "구분" and ws["B8"].value == 3 and ws["F8"].value == "대구3"
|
||||
|
||||
|
||||
def test_outbound_write_streams_progress_lines(monkeypatch):
|
||||
import asyncio
|
||||
import json
|
||||
|
||||
drive = FakeDrive(_xlsx_bytes({"20261026(월)": _sheet_rows(4)}))
|
||||
writer = _xlsx_writer(drive)
|
||||
monkeypatch.setattr(cupang_router, "_outbound_target", lambda: (writer, "f", None))
|
||||
|
||||
async def collect(resp):
|
||||
return [chunk async for chunk in resp.body_iterator]
|
||||
|
||||
resp = cupang_router.outbound_sheet_write(None, _multi_payload(), stream=True, _={})
|
||||
assert resp.media_type == "application/x-ndjson" and resp.headers["x-accel-buffering"] == "no"
|
||||
events = [json.loads(line) for chunk in asyncio.run(collect(resp)) for line in chunk.splitlines() if line]
|
||||
assert [e["progress"] for e in events] == [5, 40, 60, 80, 100]
|
||||
assert events[-1]["done"] is True and len(events[-1]["centers"]) == 2 and drive.uploads == 1
|
||||
|
||||
busy = FakeDrive(_xlsx_bytes({"20261026(월)": _sheet_rows(1)}))
|
||||
busy.always_bump = True
|
||||
w2 = _xlsx_writer(busy)
|
||||
monkeypatch.setattr(cupang_router, "_outbound_target", lambda: (w2, "f", None))
|
||||
resp = cupang_router.outbound_sheet_write(None, _multi_payload(), stream=True, _={})
|
||||
last = json.loads(asyncio.run(collect(resp))[-1])
|
||||
assert "다른 사람이 파일을 고치는 중" in last["error"] and busy.uploads == 0
|
||||
|
||||
|
||||
def test_outbound_popup_writes_only_to_drive_xlsx(monkeypatch):
|
||||
"""CUPANG_SHEET_ID 가 구글 시트 문서여도 팝업은 엑셀 파일(CUPANG_OUTBOUND_XLSX_ID)에만 쓴다."""
|
||||
drive = FakeDrive(b"")
|
||||
|
||||
Reference in New Issue
Block a user