Skip to content

Commit

Permalink
Fix savings_goal report
Browse files Browse the repository at this point in the history
- remove multiplier from configuration, needs to be implemented differently (in a way that supports account walkers).
- Allow for null accounts in account walker, for when data is going to be updated by hand
- savings_goal report now uses account walker for calculating the value of accounts and descendants.
  • Loading branch information
rerobins committed Apr 1, 2018
1 parent fd49d63 commit 9a51f35
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
20 changes: 5 additions & 15 deletions gnucash_reports/reports/savings_goals.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
from gnucash_reports.configuration.current_date import get_today
from gnucash_reports.configuration.currency import get_currency
from gnucash_reports.periods import PeriodStart
from gnucash_reports.wrapper import get_account, get_balance_on_date, account_walker
from gnucash_reports.wrapper import get_account, get_balance_on_date, account_walker, parse_walker_parameters


def savings_goal(definition):
accounts = definition['account']
if isinstance(accounts, basestring):
accounts = [accounts]
walker_params = parse_walker_parameters(definition['savings'])

goal_amount = Decimal(definition.get('goal', Decimal(0.0)))

Expand All @@ -27,17 +25,9 @@ def savings_goal(definition):
total_balance = Decimal('0.0')
currency = get_currency()

for account_description in accounts:
multiplier = Decimal('1.0')
if isinstance(account_description, basestring):
account = account_description
else:
account = account_description[0]
multiplier = Decimal(account_description[1])

for account_name in account_walker([account]):
balance = get_balance_on_date(account_name, as_of.date, currency)
total_balance += (balance * multiplier)
for account in account_walker(**walker_params):
balance = get_balance_on_date(account, as_of.date, currency)
total_balance += balance

for contribution in contributions:
total_balance += Decimal(contribution)
Expand Down
8 changes: 8 additions & 0 deletions gnucash_reports/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ def account_walker(accounts, ignores=None, place_holders=False, recursive=True,
if not ignores:
ignores = []

# Allow for a none account list to be provided
if accounts is None:
accounts = []

_account_list = [a for a in accounts]

while _account_list:
Expand Down Expand Up @@ -125,6 +129,10 @@ def parse_walker_parameters(definition):
'recursive': True
}

# Allow for a none definition to be provided and overwrite to an empty list
if definition is None:
definition = []

if isinstance(definition, dict):
return_value.update(definition)
elif isinstance(definition, list) or isinstance(definition, set):
Expand Down

0 comments on commit 9a51f35

Please sign in to comment.