fix some func to get balance

This commit is contained in:
Tim Gröger 2024-01-17 13:04:29 +01:00
parent 001ef13014
commit 4f20a94f60
1 changed files with 5 additions and 5 deletions

View File

@ -36,7 +36,7 @@ def get_limit(user: User) -> float:
def get_balance(user, start: datetime = None, end: datetime = None): def get_balance(user, start: datetime = None, end: datetime = None):
query = db.session.query(func.sum(Transaction.amount)) query = db.session.query(func.sum(Transaction._amount))
if start: if start:
query = query.filter(start <= Transaction.time) query = query.filter(start <= Transaction.time)
if end: if end:
@ -75,8 +75,8 @@ def get_balances(
@debit.expression @debit.expression
def debit(cls): def debit(cls):
a = ( a = (
db.select(func.sum(Transaction.amount)) db.select(func.sum(Transaction._amount))
.where(cls.id_ == Transaction._sender_id, Transaction.amount) .where(cls.id_ == Transaction._sender_id, Transaction._amount)
.scalar_subquery() .scalar_subquery()
) )
return case([(a, a)], else_=0) return case([(a, a)], else_=0)
@ -88,8 +88,8 @@ def get_balances(
@credit.expression @credit.expression
def credit(cls): def credit(cls):
b = ( b = (
db.select(func.sum(Transaction.amount)) db.select(func.sum(Transaction._amount))
.where(cls.id_ == Transaction._receiver_id, Transaction.amount) .where(cls.id_ == Transaction._receiver_id, Transaction._amount)
.scalar_subquery() .scalar_subquery()
) )
return case([(b, b)], else_=0) return case([(b, b)], else_=0)