diff options
-rw-r--r-- | thallium-backend/src/routes/orders.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/thallium-backend/src/routes/orders.py b/thallium-backend/src/routes/orders.py index af659bd..f52a2f9 100644 --- a/thallium-backend/src/routes/orders.py +++ b/thallium-backend/src/routes/orders.py @@ -21,8 +21,6 @@ async def create_order(request: Request, db: DBSession, client: PrintfulClient, If the voucher does not have enough funds, the order is cancelled. """ voucher: Voucher = request.state.voucher - stmt = select(DBVoucher).where(DBVoucher.id == voucher.id).with_for_update() - db_voucher = await db.scalar(stmt) resp = await client.post( "/orders/estimate-costs", @@ -31,6 +29,9 @@ async def create_order(request: Request, db: DBSession, client: PrintfulClient, ) resp.raise_for_status() cost = OrderCosts.model_validate(resp.json()["result"]["costs"]) + + stmt = select(DBVoucher).where(DBVoucher.id == voucher.id).with_for_update() + db_voucher = await db.scalar(stmt) if cost.total > db_voucher.balance: raise HTTPException( status_code=400, |