feat(inout): 수퍼관리자 발주 삭제(발주 목록)

- 발주 목록 줄 끝 휴지통 — 수퍼관리자에게만 보이고 서버도 수퍼관리자만 허용(ERP 관리자도 403)
- 확인 창 후 품목·입고 기록·입고증 사진·발주 메일 기록까지 완전히 삭제(CASCADE), 서버 로그에 남김
- 지운 뒤 보던 목록(거르기 그대로)으로 — 다른 사이트 주소는 무시

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-17 01:44:18 +09:00
parent f1e8dd5bf5
commit 215b937f1e
11 changed files with 117 additions and 7 deletions
+26 -1
View File
@@ -21,6 +21,7 @@
from __future__ import annotations
import logging
from datetime import date
from typing import Any
from urllib.parse import urlencode
@@ -33,6 +34,8 @@ from app.timezone import today_kst
from . import store
from .db import OverReceipt
_log = logging.getLogger(__name__)
router = APIRouter(prefix="/inout", tags=["inout"])
@@ -82,7 +85,8 @@ def _perms(st: Any, user: dict[str, Any]) -> dict[str, bool]:
admin = _is_admin(user)
roles = set() if admin else st.roles_of(user.get("email", ""))
return {"admin": admin, "can_order": admin or store.ROLE_ORDER in roles,
"can_receive": admin or store.ROLE_RECEIVE in roles}
"can_receive": admin or store.ROLE_RECEIVE in roles,
"super": bool(user.get("is_super_admin"))} # 발주 삭제(2026-10-17) — 수퍼관리자 한 명만
def _require(st: Any, user: dict[str, Any], what: str) -> dict[str, bool]:
@@ -93,6 +97,8 @@ def _require(st: Any, user: dict[str, Any], what: str) -> dict[str, bool]:
raise HTTPException(status_code=403, detail="입고 담당만 할 수 있습니다(입출고 관리 → 옵션에서 지정).")
if what == "admin" and not p["admin"]:
raise HTTPException(status_code=403, detail="옵션은 ERP 관리자만 바꿀 수 있습니다.")
if what == "super" and not p["super"]:
raise HTTPException(status_code=403, detail="발주 삭제는 수퍼관리자만 할 수 있습니다.")
return p
@@ -393,6 +399,25 @@ def order_cancel(request: Request, order_id: int) -> Any:
return _redirect(f"/inout/orders/{order_id}", "발주서를 취소했습니다.")
@router.post("/orders/{order_id}/delete")
async def order_delete(request: Request, order_id: int) -> Any:
"""발주 목록 🗑 — 수퍼관리자만. 품목·입고 기록·입고증 사진·메일 기록까지 완전히 지운다(되돌릴 수 없음)."""
got = _ctx(request)
if not isinstance(got, tuple):
return got
st, user = got
_require(st, user, "super")
form = await request.form()
back = str(form.get("back") or "")
back = back if back.startswith("/inout/") and "//" not in back else "/inout/" # 보던 목록(거르기)으로 — 다른 사이트로는 안 보냄
try:
r = st.delete_order(order_id)
except LookupError as exc:
return _redirect(back, str(exc))
_log.warning("inout order deleted: %s (receipts=%d) by %s", r["order_no"], r["receipts"], user.get("email", ""))
return _redirect(back, f"발주서 {r['order_no']}를 삭제했습니다" + (f"(입고 기록 {r['receipts']}건 포함)." if r["receipts"] else "."))
# ────────────────────────────────────────────────────────────
# 입고
# ────────────────────────────────────────────────────────────