Adding admin operations to the balance

This commit is contained in:
Vladless
2025-11-16 03:30:00 +03:00
parent 1d5c80cd35
commit 8b77ccda9e
9 changed files with 257 additions and 177 deletions
+9 -7
View File
@@ -4,9 +4,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
from database.models import Payment, TrackingSource, User
from logger import logger
EXCLUDED_PAYMENT_MARKERS = ["coupon", "referral", "cashback"]
from core.constants import PAYMENT_SYSTEMS_EXCLUDED
async def create_tracking_source(session: AsyncSession, name: str, code: str, type_: str, created_by: int):
@@ -43,7 +41,11 @@ async def get_all_tracking_sources(session: AsyncSession) -> list[dict]:
payments_subq = (
select(func.count(func.distinct(Payment.tg_id)))
.join(User, Payment.tg_id == User.tg_id)
.where((User.source_code == TrackingSource.code) & (Payment.status == "success"))
.where(
(User.source_code == TrackingSource.code)
& (Payment.status == "success")
& Payment.payment_system.notin_(PAYMENT_SYSTEMS_EXCLUDED)
)
.correlate(TrackingSource)
.scalar_subquery()
)
@@ -103,7 +105,7 @@ async def get_tracking_source_stats(session: AsyncSession, code: str) -> dict |
.where(
(User.source_code == code)
& (Payment.status == "success")
& not_(Payment.payment_system.in_(EXCLUDED_PAYMENT_MARKERS))
& Payment.payment_system.notin_(PAYMENT_SYSTEMS_EXCLUDED)
& (Payment.created_at >= created_at)
)
.scalar_subquery()
@@ -115,7 +117,7 @@ async def get_tracking_source_stats(session: AsyncSession, code: str) -> dict |
.where(
(User.source_code == code)
& (Payment.status == "success")
& not_(Payment.payment_system.in_(EXCLUDED_PAYMENT_MARKERS))
& Payment.payment_system.notin_(PAYMENT_SYSTEMS_EXCLUDED)
& (Payment.created_at >= created_at)
)
.scalar_subquery()
@@ -146,7 +148,7 @@ async def get_tracking_source_stats(session: AsyncSession, code: str) -> dict |
.where(
(User.source_code == code)
& (Payment.status == "success")
& not_(Payment.payment_system.in_(EXCLUDED_PAYMENT_MARKERS))
& Payment.payment_system.notin_(PAYMENT_SYSTEMS_EXCLUDED)
& (Payment.created_at >= created_at)
)
.subquery()