diff --git a/accountant/models/accounts.py b/accountant/models/accounts.py index be6bba8..566bfbf 100644 --- a/accountant/models/accounts.py +++ b/accountant/models/accounts.py @@ -69,15 +69,13 @@ class Account(db.Model): query = db.session.query( db.func.sum( db.case( - [(db.func.sign(Operation.value) == -1, - Operation.value)], + [(db.func.sign(Operation.value) == -1, Operation.value)], else_=0 ) ).label("expenses"), db.func.sum( db.case( - [(db.func.sign(Operation.value) == 1, - Operation.value)], + [(db.func.sign(Operation.value) == 1, Operation.value)], else_=0 ) ).label("revenues"), diff --git a/accountant/models/scheduled_operations.py b/accountant/models/scheduled_operations.py index 9535802..d8de21e 100644 --- a/accountant/models/scheduled_operations.py +++ b/accountant/models/scheduled_operations.py @@ -99,29 +99,27 @@ class ScheduledOperation(db.Model): stop_date = arrow.get(self.stop_date) # Iterate over the range. - for c_date in arrow.Arrow.range( - "month", start_date, stop_date - )[::self.frequency]: + date_range = arrow.Arrow.range("month", start_date, stop_date) + dates = date_range[::self.frequency] + for date in dates: # If a date day is below the first date day, next dates will not # have the right day. day = min(self.day, monthrange( - c_date.year, c_date.month)[1]) + date.year, date.month)[1]) - c_date = c_date.replace(day=day) + date = date.replace(day=day) # Search if a close operation exists. - if not db.session.query( - Operation - ).filter( - Operation.account_id == self.account_id, - Operation.scheduled_operation_id == self.id, - Operation.operation_date >= c_date.replace(weeks=-2).date(), - Operation.operation_date <= c_date.replace(weeks=+2).date() + if not db.session.query(Operation).filter( + Operation.account_id == self.account_id, + Operation.scheduled_operation_id == self.id, + Operation.operation_date >= date.replace(weeks=-2).date(), + Operation.operation_date <= date.replace(weeks=+2).date() ).count(): # Create not confirmed operation if not found. operation = Operation( - operation_date=c_date.date(), + operation_date=date.date(), label=self.label, value=self.value, category=self.category,