diff --git a/CHANGES.rst b/CHANGES.rst index b84a8b52..07a8f4a6 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,7 @@ Changelog Unreleased Changes ------------------ +* `Issue #201 `_ - Fix **major** bug in calculation of "Remaining" amount for pay periods, when one or more periodic budgets have a greater amount spent than allocated and a $0 starting balance. In that case, we were using the allocated amount instead of the spent amount (i.e. if we had a periodic budget with a $0 starting balance and a $2 ScheduledTransaction, and converted that ScheduledTransaction to a $1000 Transaction, the overall PayPeriod remaining amount would be based on the $2 not the $1000). * Add testing for Python 3.7, and make 3.7 the default for tests and tox environments. * TravisCI updates for Python 3.7. * Upgrade SQLAlchemy from 1.2.0 to 1.2.11 for `python 3 bug fix (4291) `_. diff --git a/biweeklybudget/biweeklypayperiod.py b/biweeklybudget/biweeklypayperiod.py index 6b49ce4c..34ecc786 100644 --- a/biweeklybudget/biweeklypayperiod.py +++ b/biweeklybudget/biweeklypayperiod.py @@ -533,6 +533,7 @@ def _make_overall_sums(self): :return: dict describing sums for the pay period :rtype: dict """ + budgets_total = Decimal('0.0') res = { 'allocated': Decimal('0.0'), 'spent': Decimal('0.0'), @@ -548,10 +549,11 @@ def _make_overall_sums(self): continue res['allocated'] += max(b['allocated'], b['budget_amount']) res['spent'] += b['spent'] - if res['spent'] > res['allocated'] or self.is_in_past: + budgets_total += max(b['trans_total'], b['budget_amount']) + if self.is_in_past: res['remaining'] = res['income'] - res['spent'] else: - res['remaining'] = res['income'] - res['allocated'] + res['remaining'] = res['income'] - budgets_total return res def _trans_dict(self, t):