balance_sheet: Balance only considers post_type for Expenses.
This simplifies the code and slightly optimizes it, since now Balance won't store and keep re-summing income-type breakdowns that nothing needs.
This commit is contained in:
parent
b7f9903d1f
commit
e05f55659a
2 changed files with 4 additions and 11 deletions
|
@ -78,11 +78,6 @@ class BalanceKey(NamedTuple):
|
||||||
|
|
||||||
|
|
||||||
class Balances:
|
class Balances:
|
||||||
POST_TYPES = {
|
|
||||||
'Income': 'income-type',
|
|
||||||
'Expenses': 'expense-type',
|
|
||||||
}
|
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
postings: Iterable[data.Posting],
|
postings: Iterable[data.Posting],
|
||||||
start_date: datetime.date,
|
start_date: datetime.date,
|
||||||
|
@ -124,9 +119,9 @@ class Balances:
|
||||||
raise TypeError()
|
raise TypeError()
|
||||||
except (KeyError, TypeError):
|
except (KeyError, TypeError):
|
||||||
classification = account
|
classification = account
|
||||||
try:
|
if account.root_part() == 'Expenses':
|
||||||
post_type = post.meta[self.POST_TYPES[account.root_part()]]
|
post_type = post.meta.get('expense-type')
|
||||||
except KeyError:
|
else:
|
||||||
post_type = None
|
post_type = None
|
||||||
key = BalanceKey(account, classification, period, fund, post_type)
|
key = BalanceKey(account, classification, period, fund, post_type)
|
||||||
self.balances[key] += post.at_cost()
|
self.balances[key] += post.at_cost()
|
||||||
|
|
|
@ -87,13 +87,11 @@ def income_expense_balances():
|
||||||
({'period': Period.PERIOD, 'account': 'Expenses'}, 26),
|
({'period': Period.PERIOD, 'account': 'Expenses'}, 26),
|
||||||
({'fund': Fund.RESTRICTED, 'account': 'Income'}, -10),
|
({'fund': Fund.RESTRICTED, 'account': 'Income'}, -10),
|
||||||
({'fund': Fund.UNRESTRICTED, 'account': 'Expenses'}, 25),
|
({'fund': Fund.UNRESTRICTED, 'account': 'Expenses'}, 25),
|
||||||
({'post_type': 'Donations'}, -10),
|
|
||||||
({'post_type': 'fundraising'}, 20),
|
({'post_type': 'fundraising'}, 20),
|
||||||
({'post_type': 'management'}, 10),
|
({'post_type': 'management'}, 10),
|
||||||
({'post_type': 'Nonexistent'}, None),
|
({'post_type': 'Nonexistent'}, None),
|
||||||
({'period': Period.PRIOR, 'post_type': 'RBI'}, '-4.80'),
|
({'period': Period.PRIOR, 'post_type': 'fundraising'}, '9.60'),
|
||||||
({'fund': Fund.RESTRICTED, 'post_type': 'program'}, 10),
|
({'fund': Fund.RESTRICTED, 'post_type': 'program'}, 10),
|
||||||
({'period': Period.PERIOD, 'fund': Fund.UNRESTRICTED, 'post_type': 'RBI'}, '-2.60'),
|
|
||||||
({'period': Period.PRIOR, 'fund': Fund.RESTRICTED, 'post_type': 'program'}, '4.80'),
|
({'period': Period.PRIOR, 'fund': Fund.RESTRICTED, 'post_type': 'program'}, '4.80'),
|
||||||
({'period': Period.PERIOD, 'fund': Fund.RESTRICTED, 'post_type': 'ø'}, None),
|
({'period': Period.PERIOD, 'fund': Fund.RESTRICTED, 'post_type': 'ø'}, None),
|
||||||
])
|
])
|
||||||
|
|
Loading…
Reference in a new issue