fix: abs() for transaction amounts in admin notifications and subscription events

- send_subscription_purchase_notification: abs(transaction.amount_kopeks) when no explicit amount_kopeks passed
- send_subscription_renewal_notification: abs(transaction.amount_kopeks) for SubscriptionEvent storage
- Prevents negative amounts in admin Telegram messages and SubscriptionEvent records
This commit is contained in:
Fringg
2026-03-05 09:30:27 +03:00
parent de6f80694b
commit fd139b28a2

View File

@@ -403,7 +403,7 @@ class AdminNotificationService:
) -> bool:
try:
total_amount = (
amount_kopeks if amount_kopeks is not None else (transaction.amount_kopeks if transaction else 0)
amount_kopeks if amount_kopeks is not None else (abs(transaction.amount_kopeks) if transaction else 0)
)
await self._record_subscription_event(
@@ -846,7 +846,7 @@ class AdminNotificationService:
user=user,
subscription=subscription,
transaction=transaction,
amount_kopeks=transaction.amount_kopeks,
amount_kopeks=abs(transaction.amount_kopeks),
message='Subscription renewed',
occurred_at=transaction.completed_at or transaction.created_at,
extra={