From 5ee45f97d179ce2d32b3f19eeb6fd01989a30ca7 Mon Sep 17 00:00:00 2001 From: Fringg Date: Mon, 23 Feb 2026 19:12:51 +0300 Subject: [PATCH] fix: show negative amounts for withdrawals in admin transaction list Admin endpoints returned amount_kopeks as always-positive from DB, causing withdrawals and subscription payments to display as credits in the admin panel. User-facing balance.py already handled this correctly. --- app/cabinet/routes/admin_users.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/cabinet/routes/admin_users.py b/app/cabinet/routes/admin_users.py index f0b70bb1..a294eb96 100644 --- a/app/cabinet/routes/admin_users.py +++ b/app/cabinet/routes/admin_users.py @@ -575,12 +575,14 @@ async def get_user_detail( transactions_result = await db.execute(transactions_q) transactions = transactions_result.scalars().all() + _EXPENSE_TYPES = {TransactionType.WITHDRAWAL.value, TransactionType.SUBSCRIPTION_PAYMENT.value} + recent_transactions = [ UserTransactionItem( id=t.id, type=t.type, - amount_kopeks=t.amount_kopeks, - amount_rubles=t.amount_kopeks / 100, + amount_kopeks=-t.amount_kopeks if t.type in _EXPENSE_TYPES else t.amount_kopeks, + amount_rubles=-t.amount_kopeks / 100 if t.type in _EXPENSE_TYPES else t.amount_kopeks / 100, description=t.description, payment_method=t.payment_method, is_completed=t.is_completed, @@ -2097,12 +2099,14 @@ async def get_user_transactions( result = await db.execute(query) transactions = result.scalars().all() + _EXPENSE_TYPES = {TransactionType.WITHDRAWAL.value, TransactionType.SUBSCRIPTION_PAYMENT.value} + items = [ UserTransactionItem( id=t.id, type=t.type, - amount_kopeks=t.amount_kopeks, - amount_rubles=t.amount_kopeks / 100, + amount_kopeks=-t.amount_kopeks if t.type in _EXPENSE_TYPES else t.amount_kopeks, + amount_rubles=-t.amount_kopeks / 100 if t.type in _EXPENSE_TYPES else t.amount_kopeks / 100, description=t.description, payment_method=t.payment_method, is_completed=t.is_completed,