fix(cupang): 출고리스트 작성 팝업은 항상 드라이브 엑셀 파일에만 기록
- 서버 CUPANG_SHEET_ID 가 구글 시트 문서이거나 드라이브 인증이 없으면 자동 판별이 구글 시트로 써서 팝업 내용이 계속 구글 시트에 들어갔다 - router._outbound_target: CUPANG_OUTBOUND_XLSX_ID(기본 1J74op7lBZOgE27p4R28I3RWsv0EtXdii)만 보고 항상 drive_xlsx. 인증이 없거나 .xlsx 가 아니면 구글 시트로 대신 쓰지 않고 503(사유 표시) - 입고센터 후보도 같은 엑셀 파일에서 읽음, 로그에 기록한 파일 id 남김 - [분배 확정]·출고 삭제 동기화(CUPANG_SHEET_ID)는 그대로 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -386,6 +386,28 @@ def _write_full_sheet(
|
||||
OUTBOUND_SHEET_METHODS: tuple[str, ...] = ("파렛트", "택배")
|
||||
_SHEET_CENTERS_TTL_SECONDS = 600
|
||||
_sheet_centers_cache: dict[str, Any] = {"at": 0.0, "sheet": "", "names": []}
|
||||
# 팝업이 쓰는 문서 — 항상 드라이브 엑셀(.xlsx) 파일. CUPANG_SHEET_ID(분배 확정 동기화)와 따로 둔다:
|
||||
# 서버의 CUPANG_SHEET_ID 가 구글 시트 문서를 가리켜도 팝업은 엑셀 파일에만 쓴다(구글 시트로 대신 쓰지 않음).
|
||||
DEFAULT_OUTBOUND_XLSX_ID = "1J74op7lBZOgE27p4R28I3RWsv0EtXdii"
|
||||
|
||||
|
||||
def _outbound_target() -> tuple[Any, str, dict[str, Any] | None]:
|
||||
"""(drive_xlsx writer, 엑셀 파일 id, skip 사유). 드라이브 인증이 없거나 .xlsx 가 아니면 skip."""
|
||||
import os # noqa: WPS433
|
||||
|
||||
from app.integrations import drive_xlsx # noqa: WPS433
|
||||
|
||||
file_id = (os.getenv("CUPANG_OUTBOUND_XLSX_ID") or "").strip() or DEFAULT_OUTBOUND_XLSX_ID
|
||||
writer = drive_xlsx.get_writer()
|
||||
if not writer.enabled:
|
||||
return None, "", {"ok": False, "skipped": True, "reason": writer.reason}
|
||||
try:
|
||||
kind = writer.file_kind(file_id)
|
||||
except Exception as exc: # noqa: BLE001 - 사유만(비밀값 없음)
|
||||
return None, "", {"ok": False, "skipped": True, "reason": str(exc) or type(exc).__name__}
|
||||
if kind != "xlsx":
|
||||
return None, "", {"ok": False, "skipped": True, "reason": f"출고리스트 파일이 엑셀(.xlsx)이 아닙니다({kind})"}
|
||||
return writer, file_id, None
|
||||
|
||||
|
||||
def _sheet_text(value: Any, *, label: str, max_len: int, required: bool = True) -> str:
|
||||
@@ -517,14 +539,14 @@ def outbound_sheet_centers(
|
||||
store = _store(request)
|
||||
names = {c["name"] for c in store.list_centers()} if store else set()
|
||||
reason = ""
|
||||
writer, spreadsheet_id, skip = _sheet_target(store)
|
||||
writer, spreadsheet_id, skip = _outbound_target()
|
||||
if skip:
|
||||
reason = str(skip.get("reason") or "")
|
||||
else:
|
||||
try:
|
||||
names.update(_sheet_centers(writer, spreadsheet_id))
|
||||
except Exception as exc: # noqa: BLE001 - 목록은 등록 센터만으로도 쓸 수 있다
|
||||
reason = f"출고리스트 파일을 읽지 못했습니다({type(exc).__name__})"
|
||||
reason = f"출고리스트 파일을 읽지 못했습니다({str(exc) or type(exc).__name__})"
|
||||
return JSONResponse({"centers": sorted(names), "reason": reason})
|
||||
|
||||
|
||||
@@ -535,10 +557,11 @@ def outbound_sheet_write(
|
||||
_: dict[str, Any] = Depends(_require_user),
|
||||
) -> JSONResponse:
|
||||
entry = _clean_outbound_entry(payload)
|
||||
writer, spreadsheet_id, skip = _sheet_target(_store(request))
|
||||
writer, spreadsheet_id, skip = _outbound_target()
|
||||
if skip:
|
||||
_log_sheet("manual-append", entry["ship_date"], skip)
|
||||
raise HTTPException(
|
||||
status_code=503, detail=f"출고리스트 파일에 쓸 수 없습니다: {skip.get('reason') or '설정 확인 필요'}"
|
||||
status_code=503, detail=f"출고리스트 엑셀 파일에 쓸 수 없습니다: {skip.get('reason') or '설정 확인 필요'}"
|
||||
)
|
||||
from app.integrations.drive_xlsx import XlsxChangedError # noqa: WPS433
|
||||
from app.integrations.google_drive import GoogleDriveError # noqa: WPS433
|
||||
@@ -557,7 +580,8 @@ def outbound_sheet_write(
|
||||
raise HTTPException(
|
||||
status_code=502, detail=f"출고리스트 파일에 기록하지 못했습니다({why}). 잠시 후 다시 시도해 주세요."
|
||||
) from exc
|
||||
_log_sheet("manual-append", entry["ship_date"], {"ok": True, "action": f"rows {res.get('first_row')}-{res.get('last_row')}"})
|
||||
_log_sheet("manual-append", entry["ship_date"],
|
||||
{"ok": True, "action": f"xlsx {spreadsheet_id} rows {res.get('first_row')}-{res.get('last_row')}"})
|
||||
center = entry["center_name_snapshot"]
|
||||
if center not in _sheet_centers_cache["names"] and _sheet_centers_cache["sheet"] == spreadsheet_id:
|
||||
_sheet_centers_cache["names"] = sorted([*_sheet_centers_cache["names"], center])
|
||||
|
||||
Reference in New Issue
Block a user