From fbefe633f211e7670e5b219c970a28fde9453acb Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Thu, 20 Aug 2015 21:14:45 +0200 Subject: [PATCH] Fix filtering on date. --- accountant/api/models/operations.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/accountant/api/models/operations.py b/accountant/api/models/operations.py index c3f5de8..718099d 100644 --- a/accountant/api/models/operations.py +++ b/accountant/api/models/operations.py @@ -101,8 +101,6 @@ class Operation(db.Model): @classmethod def query(cls, session, begin=None, end=None): - end = arrow.now().ceil('month').date() if not end else end - # We have to use a join because the sold is not computed from the # begining. base_query = session.query( @@ -124,15 +122,18 @@ class Operation(db.Model): cls.canceled ).join( base_query, base_query.c.id == cls.id - ).filter( - cls.operation_date >= str(begin), - cls.operation_date <= str(end) ).order_by( desc(cls.operation_date), cls.value, cls.label, ) + if begin: + query = query.filter(cls.operation_date >= str(begin)) + + if end: + query = query.filter(cls.operation_date <= str(end)) + return query @classmethod