feat(dispatch): 수퍼 관리자 전용 기간별 발송 수량 엑셀 다운로드
- GET /dispatch/period-export?date_from=&date_to= (서버 측 is_super_admin 검사, 최대 366일) - 시트 「날짜별」(날짜/아이템코드/상품이름/수량) + 「아이템별 요약」(아이템×날짜 피벗, 합계) - seller_sku _N 배수 반영, 콤보는 발송된 그대로(분해 안 함), 상품명은 itemcode_db 우선 - 배치 목록 오른쪽에 기간 선택 카드(수퍼 관리자에게만 표시) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -477,6 +477,56 @@ def stock_export(
|
||||
)
|
||||
|
||||
|
||||
_PERIOD_MAX_DAYS = 366
|
||||
|
||||
|
||||
@router.get("/period-export")
|
||||
def period_export(
|
||||
request: Request,
|
||||
date_from: str,
|
||||
date_to: str,
|
||||
user: dict[str, Any] = Depends(_require_user),
|
||||
) -> Response:
|
||||
"""기간(양끝 포함) 날짜별·아이템별 발송 수량 xlsx — 슈퍼 관리자 전용.
|
||||
|
||||
seller_sku 의 _N 배수는 반영, 콤보는 분해하지 않고 발송된 그대로 센다.
|
||||
"""
|
||||
if not bool(user.get("is_super_admin")):
|
||||
raise HTTPException(status_code=403, detail="기간별 발송 수량은 슈퍼 관리자만 받을 수 있습니다.")
|
||||
st = _store(request)
|
||||
if st is None:
|
||||
raise HTTPException(status_code=503, detail="dispatch_db 미설정")
|
||||
d_from = export._parse_date(date_from)
|
||||
d_to = export._parse_date(date_to)
|
||||
if d_from is None or d_to is None:
|
||||
raise HTTPException(status_code=400, detail="시작일·종료일을 YYYY-MM-DD 로 입력하세요.")
|
||||
if d_from > d_to:
|
||||
d_from, d_to = d_to, d_from
|
||||
if (d_to - d_from).days + 1 > _PERIOD_MAX_DAYS:
|
||||
raise HTTPException(status_code=400, detail=f"기간은 최대 {_PERIOD_MAX_DAYS}일까지 가능합니다.")
|
||||
|
||||
f, t = d_from.isoformat(), d_to.isoformat()
|
||||
rows = st.shipped_by_date_range(date_from=f, date_to=t)
|
||||
if not rows:
|
||||
raise HTTPException(status_code=404, detail=f"{f} ~ {t} 기간의 발송 데이터가 없습니다.")
|
||||
|
||||
xlsx_bytes = export.build_period_xlsx(
|
||||
rows=rows, date_from=f, date_to=t, name_map=_itemcode_name_map(request)
|
||||
)
|
||||
fname = export.period_filename(f, t)
|
||||
headers = {
|
||||
"Content-Disposition": (
|
||||
f"attachment; filename=\"shipped_{f}_{t}.xlsx\"; "
|
||||
f"filename*=UTF-8''{quote(fname)}"
|
||||
)
|
||||
}
|
||||
return Response(
|
||||
content=xlsx_bytes,
|
||||
media_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
|
||||
@router.post("/stock-deduct")
|
||||
def stock_deduct(
|
||||
request: Request,
|
||||
|
||||
Reference in New Issue
Block a user