Change filtering on begin and end dates.
This commit is contained in:
parent
30efb9312a
commit
21c98a1dcf
@ -30,7 +30,7 @@ class Account(db.Model):
|
||||
|
||||
@classmethod
|
||||
def query(cls, begin=None, end=None):
|
||||
status_query = db.session.query(
|
||||
query = db.session.query(
|
||||
Operation.account_id,
|
||||
db.func.sum(Operation.value).label("future"),
|
||||
db.func.sum(
|
||||
@ -49,10 +49,11 @@ class Account(db.Model):
|
||||
).label("current"),
|
||||
).group_by(
|
||||
Operation.account_id
|
||||
).subquery()
|
||||
)
|
||||
|
||||
if begin and end:
|
||||
balance_query = db.session.query(
|
||||
status_query = query.subquery()
|
||||
|
||||
query = db.session.query(
|
||||
Operation.account_id,
|
||||
db.func.sum(
|
||||
db.case(
|
||||
@ -69,12 +70,17 @@ class Account(db.Model):
|
||||
)
|
||||
).label("revenues"),
|
||||
db.func.sum(Operation.value).label("balance")
|
||||
).filter(
|
||||
Operation.operation_date >= str(begin),
|
||||
Operation.operation_date <= str(end)
|
||||
).group_by(
|
||||
Operation.account_id
|
||||
).subquery()
|
||||
)
|
||||
|
||||
if begin:
|
||||
query = query.filter(Operation.operation_date >= str(begin))
|
||||
|
||||
if end:
|
||||
query = query.filter(Operation.operation_date <= str(end))
|
||||
|
||||
balance_query = query.subquery()
|
||||
|
||||
query = db.session.query(
|
||||
cls.id,
|
||||
@ -97,20 +103,6 @@ class Account(db.Model):
|
||||
).outerjoin(
|
||||
balance_query, balance_query.c.account_id == cls.id
|
||||
)
|
||||
else:
|
||||
query = db.session.query(
|
||||
cls.id,
|
||||
cls.name,
|
||||
cls.authorized_overdraft,
|
||||
db.func.coalesce(status_query.c.current, 0).label('current'),
|
||||
db.func.coalesce(status_query.c.pointed, 0).label('pointed'),
|
||||
db.func.coalesce(status_query.c.future, 0).label('future'),
|
||||
db.literal_column("0").label('expenses'),
|
||||
db.literal_column("0").label('revenues'),
|
||||
db.literal_column("0").label('balance'),
|
||||
).outerjoin(
|
||||
status_query, status_query.c.account_id == cls.id
|
||||
)
|
||||
|
||||
return query.order_by(cls.name)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user