feat: add payment stornation with history-preserving allocations and card layout fixes
This commit is contained in:
@@ -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)
|
||||
Reference in New Issue
Block a user