Add coelesce in income query.

This commit is contained in:
Alexis Lahouze 2017-05-25 22:46:35 +02:00
parent 554a531f57
commit d9e28fb5a9

View File

@ -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.coalesce(
db.func.sum(
Operation.value
).filter(
db.func.sign(Operation.value) == -1
), 0
).label("expenses"),
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,
)