Changeset - e05f55659a89
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-08-18 05:28:37
brettcsmith@brettcsmith.org
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.
2 files changed with 4 insertions and 11 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reports/balance_sheet.py
Show inline comments
...
 
@@ -75,17 +75,12 @@ class BalanceKey(NamedTuple):
 
    period: Period
 
    fund: Fund
 
    post_type: Optional[str]
 

	
 

	
 
class Balances:
 
    POST_TYPES = {
 
        'Income': 'income-type',
 
        'Expenses': 'expense-type',
 
    }
 

	
 
    def __init__(self,
 
                 postings: Iterable[data.Posting],
 
                 start_date: datetime.date,
 
                 stop_date: datetime.date,
 
                 fund_key: str='project',
 
                 unrestricted_fund_value: str='Conservancy',
...
 
@@ -121,15 +116,15 @@ class Balances:
 
                if isinstance(classification_s, str):
 
                    classification = data.Account(classification_s)
 
                else:
 
                    raise TypeError()
 
            except (KeyError, TypeError):
 
                classification = account
 
            try:
 
                post_type = post.meta[self.POST_TYPES[account.root_part()]]
 
            except KeyError:
 
            if account.root_part() == 'Expenses':
 
                post_type = post.meta.get('expense-type')
 
            else:
 
                post_type = None
 
            key = BalanceKey(account, classification, period, fund, post_type)
 
            self.balances[key] += post.at_cost()
 

	
 
    def total(self,
 
              account: Optional[str]=None,
tests/test_reports_balance_sheet.py
Show inline comments
...
 
@@ -84,19 +84,17 @@ def income_expense_balances():
 
    ({'classification': 'Services'}, 20),
 
    ({'classification': 'Nonexistent'}, None),
 
    ({'period': Period.PRIOR, 'account': 'Income'}, '-9.60'),
 
    ({'period': Period.PERIOD, 'account': 'Expenses'}, 26),
 
    ({'fund': Fund.RESTRICTED, 'account': 'Income'}, -10),
 
    ({'fund': Fund.UNRESTRICTED, 'account': 'Expenses'}, 25),
 
    ({'post_type': 'Donations'}, -10),
 
    ({'post_type': 'fundraising'}, 20),
 
    ({'post_type': 'management'}, 10),
 
    ({'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),
 
    ({'period': Period.PERIOD, 'fund': Fund.UNRESTRICTED, 'post_type': 'RBI'}, '-2.60'),
 
    ({'period': Period.PRIOR, 'fund': Fund.RESTRICTED, 'post_type': 'program'}, '4.80'),
 
    ({'period': Period.PERIOD, 'fund': Fund.RESTRICTED, 'post_type': 'ΓΈ'}, None),
 
])
 
def test_balance_total(income_expense_balances, kwargs, expected):
 
    actual = income_expense_balances.total(**kwargs)
 
    if expected is None:
0 comments (0 inline, 0 general)