From ba665923f64a2e11ea857cb1b69cf408d508a97b Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Tue, 12 Jan 2016 22:21:37 +0100 Subject: [PATCH] Improve filtering on date. --- accountant/api/models/operations.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/accountant/api/models/operations.py b/accountant/api/models/operations.py index b6ae971..15db841 100644 --- a/accountant/api/models/operations.py +++ b/accountant/api/models/operations.py @@ -158,15 +158,18 @@ class Operation(db.Model): db.func.sum(cls.value).label("balance") ).filter( cls.account_id == account_id - ).filter( - cls.operation_date >= str(begin), - cls.operation_date <= str(end) ).order_by( cls.category ).group_by( cls.category ) + if begin: + query = query.filter(cls.operation_date >= str(begin)) + + if end: + query = query.filter(cls.operation_date <= str(end)) + return query @classmethod