Changeset - 9ae974009b13
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-06-27 20:31:27
brettcsmith@brettcsmith.org
fund: Add outstanding balances to text fund report.
2 files changed with 60 insertions and 33 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reports/fund.py
Show inline comments
...
 
@@ -82,3 +82,9 @@ FundPosts = Tuple[MetaValue, AccountsMap]
 

	
 
BALANCE_ACCOUNTS = ['Equity', 'Income', 'Expenses']
 
EQUITY_ACCOUNTS = ['Equity', 'Income', 'Expenses']
 
INFO_ACCOUNTS = [
 
    'Assets:Receivable',
 
    'Assets:Prepaid',
 
    'Liabilities:Payable',
 
    'Liabilities:UnearnedIncome',
 
]
 
PROGNAME = 'fund-report'
...
 
@@ -172,3 +178,3 @@ class TextReport:
 
        total_fmt = f'{fund} balance as of {{}}'
 
        for acct_s, balance in core.account_balances(account_map, BALANCE_ACCOUNTS):
 
        for acct_s, balance in core.account_balances(account_map, EQUITY_ACCOUNTS):
 
            if acct_s is core.OPENING_BALANCE_NAME:
...
 
@@ -178,2 +184,7 @@ class TextReport:
 
            yield acct_s, (-balance).format(None, sep='\0').split('\0')
 
        for _, account in core.sort_and_filter_accounts(account_map, INFO_ACCOUNTS):
 
            balance = account_map[account].stop_bal
 
            if not balance.is_zero():
 
                balance = core.normalize_amount_func(account)(balance)
 
                yield account, balance.format(None, sep='\0').split('\0')
 

	
...
 
@@ -321,3 +332,2 @@ def main(arglist: Optional[Sequence[str]]=None,
 
        if post.meta.date < args.stop_date
 
        and post.account.is_under(*BALANCE_ACCOUNTS)
 
    )
tests/test_reports_fund.py
Show inline comments
...
 
@@ -42,2 +42,4 @@ STOP_DATE = datetime.date(2020, 3, 1)
 

	
 
EQUITY_ROOT_ACCOUNTS = ('Expenses:', 'Equity:', 'Income:')
 

	
 
OPENING_BALANCES = {
...
 
@@ -53,2 +55,4 @@ BALANCES_BY_YEAR = {
 
        ('Expenses:Other', -4),
 
        ('Assets:Receivable:Accounts', 40),
 
        ('Liabilities:Payable:Accounts', 4),
 
    ],
...
 
@@ -58,2 +62,4 @@ BALANCES_BY_YEAR = {
 
        ('Equity:Realized:CurrencyConversion', Decimal('6.20')),
 
        ('Assets:Receivable:Accounts', -40),
 
        ('Liabilities:Payable:Accounts', -4),
 
    ],
...
 
@@ -61,2 +67,4 @@ BALANCES_BY_YEAR = {
 
        ('Income:Other', 60),
 
        ('Liabilities:UnearnedIncome', 30),
 
        ('Assets:Prepaid:Expenses', 20),
 
    ],
...
 
@@ -65,2 +73,4 @@ BALANCES_BY_YEAR = {
 
        ('Expenses:Other', -26),
 
        ('Assets:Prepaid:Expenses', -20),
 
        ('Liabilities:UnearnedIncome', -30),
 
    ],
...
 
@@ -78,10 +88,2 @@ def fund_entries():
 

	
 
def fund_postings(entries, project, stop_date):
 
    return (
 
        post for post in data.Posting.from_entries(entries)
 
        if post.meta.date < stop_date
 
        and post.account.is_under('Equity', 'Income', 'Expenses')
 
        and post.meta.get('project') == project
 
    )
 

	
 
def split_text_lines(output):
...
 
@@ -96,2 +98,13 @@ def format_amount(amount, currency='USD'):
 

	
 
def check_text_balances(actual, expected, *expect_accounts):
 
    balance = Decimal()
 
    for expect_account in expect_accounts:
 
        expect_amount = expected[expect_account]
 
        if expect_amount:
 
            actual_account, actual_amount = next(actual)
 
            assert actual_account == expect_account
 
            assert actual_amount == format_amount(expect_amount)
 
            balance += expect_amount
 
    return balance
 

	
 
def check_text_report(output, project, start_date, stop_date):
...
 
@@ -107,3 +120,3 @@ def check_text_report(output, project, start_date, stop_date):
 
            for account, amount in amounts:
 
                if year < start_date.year:
 
                if year < start_date.year and account.startswith(EQUITY_ROOT_ACCOUNTS):
 
                    balance_amount += amount
...
 
@@ -111,3 +124,2 @@ def check_text_report(output, project, start_date, stop_date):
 
                    expected[account] += amount
 
    expected.default_factory = None
 
    actual = split_text_lines(output)
...
 
@@ -119,16 +131,8 @@ def check_text_report(output, project, start_date, stop_date):
 
    assert open_amt == format_amount(balance_amount)
 
    for expect_account in [
 
            'Equity:Realized:CurrencyConversion',
 
            'Income:Other',
 
            'Expenses:Other',
 
    ]:
 
        try:
 
            expect_amount = expected[expect_account]
 
        except KeyError:
 
            continue
 
        else:
 
            actual_account, actual_amount = next(actual)
 
            assert actual_account == expect_account
 
            assert actual_amount == format_amount(expect_amount)
 
            balance_amount += expect_amount
 
    balance_amount += check_text_balances(
 
        actual, expected,
 
        'Equity:Realized:CurrencyConversion',
 
        'Income:Other',
 
        'Expenses:Other',
 
    )
 
    end_acct, end_amt = next(actual)
...
 
@@ -138,2 +142,9 @@ def check_text_report(output, project, start_date, stop_date):
 
    assert end_amt == format_amount(balance_amount)
 
    balance_amount += check_text_balances(
 
        actual, expected,
 
        'Assets:Receivable:Accounts',
 
        'Assets:Prepaid:Expenses',
 
        'Liabilities:Payable:Accounts',
 
        'Liabilities:UnearnedIncome',
 
    )
 
    assert next(actual, None) is None
...
 
@@ -145,3 +156,7 @@ def check_ods_report(ods, start_date, stop_date):
 
        'Expenses': Decimal(0),
 
        'Equity': Decimal(0),
 
        'Equity:Realized': Decimal(0),
 
        'Assets:Receivable': Decimal(0),
 
        'Assets:Prepaid': Decimal(0),
 
        'Liabilities:Payable': Decimal(0),
 
        'Liabilities': Decimal(0),  # UnearnedIncome
 
    }) for key, amount in sorted(OPENING_BALANCES.items()))
...
 
@@ -154,6 +169,6 @@ def check_ods_report(ods, start_date, stop_date):
 
            for account, amount in amounts:
 
                if year < start_date.year:
 
                if year < start_date.year and account.startswith(EQUITY_ROOT_ACCOUNTS):
 
                    acct_key = 'opening'
 
                else:
 
                    acct_key, _, _ = account.partition(':')
 
                    acct_key, _, _ = account.rpartition(':')
 
                account_bals[fund][acct_key] += amount
...
 
@@ -171,7 +186,9 @@ def check_ods_report(ods, start_date, stop_date):
 
            assert next(cells).value == -balances['Expenses']
 
            if balances['Equity']:
 
                assert next(cells).value == balances['Equity']
 
            if balances['Equity:Realized']:
 
                assert next(cells).value == balances['Equity:Realized']
 
            else:
 
                assert not next(cells).value
 
            assert next(cells).value == sum(balances.values())
 
            assert next(cells).value == sum(balances[key] for key in [
 
                'opening', 'Income', 'Expenses', 'Equity:Realized',
 
            ])
 
    assert not account_bals, "did not see all funds in report"
0 comments (0 inline, 0 general)