fix some func to get balance
This commit is contained in:
parent
001ef13014
commit
4f20a94f60
|
@ -36,7 +36,7 @@ def get_limit(user: User) -> float:
|
|||
|
||||
|
||||
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:
|
||||
query = query.filter(start <= Transaction.time)
|
||||
if end:
|
||||
|
@ -75,8 +75,8 @@ def get_balances(
|
|||
@debit.expression
|
||||
def debit(cls):
|
||||
a = (
|
||||
db.select(func.sum(Transaction.amount))
|
||||
.where(cls.id_ == Transaction._sender_id, Transaction.amount)
|
||||
db.select(func.sum(Transaction._amount))
|
||||
.where(cls.id_ == Transaction._sender_id, Transaction._amount)
|
||||
.scalar_subquery()
|
||||
)
|
||||
return case([(a, a)], else_=0)
|
||||
|
@ -88,8 +88,8 @@ def get_balances(
|
|||
@credit.expression
|
||||
def credit(cls):
|
||||
b = (
|
||||
db.select(func.sum(Transaction.amount))
|
||||
.where(cls.id_ == Transaction._receiver_id, Transaction.amount)
|
||||
db.select(func.sum(Transaction._amount))
|
||||
.where(cls.id_ == Transaction._receiver_id, Transaction._amount)
|
||||
.scalar_subquery()
|
||||
)
|
||||
return case([(b, b)], else_=0)
|
||||
|
|
Loading…
Reference in New Issue