Add coelesce in income query.
This commit is contained in:
parent
554a531f57
commit
d9e28fb5a9
@ -56,17 +56,23 @@ class Account(db.Model):
|
||||
def income(self, begin, end):
|
||||
"""Return the income for a specific time period."""
|
||||
query = db.session.query(
|
||||
db.func.sum(
|
||||
Operation.value
|
||||
).filter(
|
||||
db.func.sign(Operation.value) == -1
|
||||
db.func.coalesce(
|
||||
db.func.sum(
|
||||
Operation.value
|
||||
).filter(
|
||||
db.func.sign(Operation.value) == -1
|
||||
), 0
|
||||
).label("expenses"),
|
||||
db.func.sum(
|
||||
Operation.value
|
||||
).filter(
|
||||
db.func.sign(Operation.value) == 1
|
||||
db.func.coalesce(
|
||||
db.func.sum(
|
||||
Operation.value
|
||||
).filter(
|
||||
db.func.sign(Operation.value) == 1
|
||||
), 0
|
||||
).label("revenues"),
|
||||
db.func.sum(Operation.value).label("income")
|
||||
db.func.coalesce(
|
||||
db.func.sum(Operation.value), 0
|
||||
).label("income")
|
||||
).filter(
|
||||
Operation.account_id == self.id,
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user