feat: add payment stornation with history-preserving allocations and card layout fixes

This commit is contained in:
Арсентьев Александр
2026-09-27 20:58:19 +03:00
parent 94571f9684
commit ea183854f8
13 changed files with 1365 additions and 34 deletions
+7 -9
View File
@@ -11,7 +11,7 @@ from app.database.database import get_db
from app.models.project import Project
from app.models.payment import Payment, PaymentAllocation
from app.services.payment_service import (
PaymentValidationError, available_ks3_for_payment, delete_payment,
PaymentValidationError, available_ks3_for_payment, cancel_payment, delete_payment,
project_payments, save_payment,
)
from app.utils.formatters import format_money
@@ -117,6 +117,8 @@ async def payment_view(request: Request, project_id: int, payment_id: int, db: S
async def payment_edit(request: Request, project_id: int, payment_id: int, db: Session = Depends(get_db)):
project = _project(db, project_id)
payment = _payment(db, project_id, payment_id)
if payment.status == "cancelled":
return RedirectResponse(f"/projects/{project_id}/payments/{payment_id}", status_code=303)
return _render_form(request, db, project, payment)
@@ -165,12 +167,8 @@ async def payment_delete(project_id: int, payment_id: int, db: Session = Depends
@router.post("/{project_id}/payments/{payment_id}/cancel")
async def payment_cancel(project_id: int, payment_id: int, db: Session = Depends(get_db)):
from app.models.payment import Payment
doc = db.query(Payment).filter(Payment.id == payment_id, Payment.project_id == project_id).first()
if doc is None:
raise HTTPException(status_code=404, detail="Payment not found")
if doc.status == "cancelled":
raise HTTPException(status_code=400, detail="Payment already cancelled")
doc.status = "cancelled"
db.commit()
try:
cancel_payment(db, project_id, payment_id)
except PaymentValidationError as exc:
raise HTTPException(status_code=400, detail=str(exc)) from exc
return RedirectResponse(f"/projects/{project_id}/payments/{payment_id}", status_code=303)