Changeset - cc1767a09d1d
[Not reviewed]
0 4 0
Brett Smith - 4 years ago 2020-08-22 13:25:53
brettcsmith@brettcsmith.org
fund: Incorporate Equity accounts into Release from Restrictions.

This matches what we do on our Statement of Activities in the
balance sheet report.
4 files changed with 34 insertions and 12 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reports/fund.py
Show inline comments
...
 
@@ -159,6 +159,9 @@ class ODSReport(core.BaseODS[FundPosts, None]):
 
        totals = [core.MutableBalance() for _ in bal_indexes]
 
        threshold = Decimal('.5')
 
        for fund, balances in self.balances.items():
 
            balances = [balances[index] for index in bal_indexes]
 
        for fund, source_bals in self.balances.items():
 
            balances = [source_bals[index] for index in bal_indexes]
 
            # Incorporate Equity changes to Release from Restrictions.
 
            # Note that using -= mutates the balance in a way we don't want.
 
            balances[2] = balances[2] - source_bals[3]
 
            if (not all(bal.clean_copy(threshold).le_zero() for bal in balances)
 
                and fund != UNRESTRICTED_FUND):
tests/books/fund.beancount
Show inline comments
...
 
@@ -110,6 +110,12 @@ option "inferred_tolerance_default" "USD:0.01"
 
  Assets:Checking  200 USD
 

	
 
2019-12-03 * "Delta income"
 
2019-09-06 * "Delta income"
 
  project: "Delta"
 
  Income:Other    -4.60 USD
 
  Assets:Checking  4.60 USD
 

	
 
2019-12-03 * "Charlie release from restriction"
 
  Equity:Funds:Restricted     100 USD
 
  project: "Charlie"
 
  Equity:Funds:Unrestricted  -100 USD
 
  project: "Conservancy"
tests/test_opening_balances.py
Show inline comments
...
 
@@ -147,6 +147,6 @@ def test_2020_opening(arg):
 
        FlatPosting.make(A_RESTRICTED, -3064, project='Alpha'),
 
        FlatPosting.make(A_RESTRICTED, -2180, project='Bravo'),
 
        FlatPosting.make(A_RESTRICTED, -1000, project='Charlie'),
 
        FlatPosting.make(A_RESTRICTED, -900, project='Charlie'),
 
        FlatPosting.make(A_RESTRICTED, -5, project='Delta'),
 
        FlatPosting.make(A_UNRESTRICTED, -4080, project='Conservancy'),
 
        FlatPosting.make(A_UNRESTRICTED, -4180, project='Conservancy'),
 
    ]
tests/test_reports_fund.py
Show inline comments
...
 
@@ -61,4 +61,5 @@ BALANCES_BY_YEAR = {
 
        ('Income:Other', 42),
 
        ('Expenses:Other', Decimal('-4.20')),
 
        ('Equity:Funds:Unrestricted', 100),
 
        ('Equity:Realized:CurrencyConversion', Decimal('6.20')),
 
        ('Assets:Receivable:Accounts', -40),
...
 
@@ -82,4 +83,7 @@ BALANCES_BY_YEAR = {
 
        ('Income:Other', 200),
 
    ],
 
    ('Charlie', 2019): [
 
        ('Equity:Funds:Restricted', -100),
 
    ],
 
    ('Delta', 2018): [
 
        ('Income:Other', Decimal('.40')),
...
 
@@ -139,4 +143,6 @@ def check_text_report(output, project, start_date, stop_date):
 
    balance_amount += check_text_balances(
 
        actual, expected,
 
        'Equity:Funds:Restricted',
 
        'Equity:Funds:Unrestricted',
 
        'Equity:Realized:CurrencyConversion',
 
        'Income:Other',
...
 
@@ -174,5 +180,5 @@ def check_ods_sheet(sheet, account_balances, *, full):
 
        }
 
        totals = {key: Decimal() for key in
 
                  ['opening', 'Income', 'Expenses', 'Equity:Realized']}
 
                  ['opening', 'Income', 'Expenses', 'Equity']}
 
        for fund, balances in account_bals.items():
 
            for key in totals:
...
 
@@ -191,9 +197,13 @@ def check_ods_sheet(sheet, account_balances, *, full):
 
        check_cell_balance(next(cells), balances['opening'])
 
        check_cell_balance(next(cells), balances['Income'])
 
        check_cell_balance(next(cells), -balances['Expenses'])
 
        if full:
 
            check_cell_balance(next(cells), balances['Equity:Realized'])
 
            check_cell_balance(next(cells), -balances['Expenses'])
 
            check_cell_balance(next(cells), balances['Equity'])
 
        else:
 
            check_cell_balance(
 
                next(cells), -sum(balances[key] for key in ['Expenses', 'Equity']),
 
            )
 
        check_cell_balance(next(cells), sum(balances[key] for key in [
 
            'opening', 'Income', 'Expenses', 'Equity:Realized',
 
            'opening', 'Income', 'Expenses', 'Equity',
 
        ]))
 
        if full:
...
 
@@ -210,5 +220,5 @@ def check_ods_report(ods, start_date, stop_date):
 
        'Income': Decimal(0),
 
        'Expenses': Decimal(0),
 
        'Equity:Realized': Decimal(0),
 
        'Equity': Decimal(0),
 
        'Assets:Receivable': Decimal(0),
 
        'Assets:Prepaid': Decimal(0),
...
 
@@ -223,6 +233,9 @@ def check_ods_report(ods, start_date, stop_date):
 
        else:
 
            for account, amount in amounts:
 
                if year < start_date.year and account.startswith(EQUITY_ROOT_ACCOUNTS):
 
                    acct_key = 'opening'
 
                if account.startswith(EQUITY_ROOT_ACCOUNTS):
 
                    if year < start_date.year:
 
                        acct_key = 'opening'
 
                    else:
 
                        acct_key, _, _ = account.partition(':')
 
                else:
 
                    acct_key, _, _ = account.rpartition(':')
0 comments (0 inline, 0 general)