bitvend/models: fix 0 transaction users

master
bitvend 2023-10-02 20:17:07 +02:00
parent 1895d785c2
commit 404a4a5903
1 changed files with 3 additions and 3 deletions

View File

@ -65,13 +65,13 @@ class User(db.Model):
return "<User {0.uid} {0.balance}>".format(self)
balance = column_property(
select([func.sum(Transaction.amount)])
select([func.coalesce(func.sum(Transaction.amount), 0)])
.where(Transaction.uid == uid)
.correlate_except(Transaction)
)
purchase_count = column_property(
select([func.count(Transaction.amount)])
select([func.coalesce(func.count(Transaction.amount), 0)])
.where(and_(Transaction.uid == uid, Transaction.type == "purchase"))
.correlate_except(Transaction)
)
@ -84,7 +84,7 @@ class User(db.Model):
)
purchase_amount = column_property(
select([-func.sum(Transaction.amount)])
select([func.coalesce(-func.sum(Transaction.amount), 0)])
.where(and_(Transaction.uid == uid, Transaction.type == "purchase"))
.correlate_except(Transaction)
)