feat: enforce KS-2/KS-3 stornation integrity
This commit is contained in:
+8
-8
@@ -128,9 +128,12 @@ async def ks3_view(request: Request, project_id: int, ks3_id: int, db: Session =
|
||||
ks2_total = _ks2_total(link.ks2)
|
||||
total += ks2_total
|
||||
ks2_rows.append({"ks2": link.ks2, "total": ks2_total})
|
||||
from app.services.ks3_service import ks3_cancel_block_reason
|
||||
cancel_reason = ks3_cancel_block_reason(db, project_id, ks3_id) if document.status != "cancelled" else None
|
||||
return templates.TemplateResponse(name="ks3/view.html", context={
|
||||
"request": request, "project": project, "document": document,
|
||||
"ks2_rows": ks2_rows, "total": total,
|
||||
"cancel_blocked_reason": cancel_reason,
|
||||
})
|
||||
|
||||
|
||||
@@ -180,14 +183,11 @@ async def ks3_issue(project_id: int, ks3_id: int, db: Session = Depends(get_db))
|
||||
|
||||
@router.post("/{project_id}/ks3/{ks3_id}/cancel")
|
||||
async def ks3_cancel(project_id: int, ks3_id: int, db: Session = Depends(get_db)):
|
||||
from app.models.ks3 import KS3
|
||||
doc = db.query(KS3).filter(KS3.id == ks3_id, KS3.project_id == project_id).first()
|
||||
if doc is None:
|
||||
raise HTTPException(status_code=404, detail="KS-3 not found")
|
||||
if doc.status == "cancelled":
|
||||
raise HTTPException(status_code=400, detail="KS-3 already cancelled")
|
||||
doc.status = "cancelled"
|
||||
db.commit()
|
||||
from app.services.ks3_service import KS3ValidationError, cancel_ks3
|
||||
try:
|
||||
cancel_ks3(db, project_id, ks3_id)
|
||||
except KS3ValidationError as exc:
|
||||
raise HTTPException(status_code=409, detail=str(exc)) from exc
|
||||
return RedirectResponse(f"/projects/{project_id}/ks3/{ks3_id}", status_code=303)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user