Skip to content

Commit

Permalink
fixes #201 - ensure that if a periodic budget has $0 starting balance…
Browse files Browse the repository at this point in the history
… and much greater spend than allocated, we properly calculate remaining for the payperiod
  • Loading branch information
jantman committed Sep 15, 2018
1 parent 5e90da5 commit 8086d8c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
Unreleased Changes
------------------

* `Issue #201 <https://github.com/jantman/biweeklybudget/issues/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) <https://docs.sqlalchemy.org/en/latest/changelog/changelog_12.html#change-2cca6c216347ab83d04c766452b48c1a>`_.
Expand Down
6 changes: 4 additions & 2 deletions biweeklybudget/biweeklypayperiod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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):
Expand Down

0 comments on commit 8086d8c

Please sign in to comment.