Changeset - 40573cb6dc30
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-06-27 22:26:03
brettcsmith@brettcsmith.org
fund: Split ODS into two sheets.

The first only has equity numbers the auditors look at.
The second includes balances of additional accounts.
2 files changed with 41 insertions and 22 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reports/fund.py
Show inline comments
...
 
@@ -102,7 +102,7 @@ class ODSReport(core.BaseODS[FundPosts, None]):
 
        return None
 

	
 
    def start_spreadsheet(self) -> None:
 
        self.use_sheet("Fund Report")
 
        self.use_sheet("With Breakdowns")
 
        for width in [2.5, 1.5, 1.2, 1.2, 1.2, 1.5, 1.2, 1.3, 1.2, 1.3]:
 
            col_style = self.column_style(width)
 
            self.sheet.addElement(odf.table.TableColumn(stylename=col_style))
...
 
@@ -132,6 +132,14 @@ class ODSReport(core.BaseODS[FundPosts, None]):
 
        ))
 
        self.add_row()
 

	
 
    def end_spreadsheet(self) -> None:
 
        sheet = self.copy_element(self.sheet)
 
        sheet.setAttribute('name', 'Fund Report')
 
        for row in sheet.childNodes:
 
            row.childNodes = row.childNodes[:6]
 
        self.lock_first_row(sheet)
 
        self.document.spreadsheet.insertBefore(sheet, self.sheet)
 

	
 
    def _row_balances(self, accounts_map: AccountsMap) -> Iterable[core.Balance]:
 
        acct_order = ['Income', 'Expenses', 'Equity']
 
        key_order = [core.OPENING_BALANCE_NAME, *acct_order, core.ENDING_BALANCE_NAME]
tests/test_reports_fund.py
Show inline comments
...
 
@@ -155,6 +155,34 @@ def check_cell_balance(cell, balance):
 
    else:
 
        assert not cell.value
 

	
 
def check_ods_sheet(sheet, account_balances, *, full):
 
    account_bals = account_balances.copy()
 
    unrestricted = account_bals.pop('Conservancy')
 
    if full:
 
        account_bals['Unrestricted'] = unrestricted
 
    for row in sheet.getElementsByType(odf.table.TableRow):
 
        cells = iter(testutil.ODSCell.from_row(row))
 
        try:
 
            fund = next(cells).firstChild.text
 
        except (AttributeError, StopIteration):
 
            fund = None
 
        if fund in account_bals:
 
            balances = account_bals.pop(fund)
 
            check_cell_balance(next(cells), balances['opening'])
 
            check_cell_balance(next(cells), balances['Income'])
 
            check_cell_balance(next(cells), -balances['Expenses'])
 
            check_cell_balance(next(cells), balances['Equity:Realized'])
 
            check_cell_balance(next(cells), sum(balances[key] for key in [
 
                'opening', 'Income', 'Expenses', 'Equity:Realized',
 
            ]))
 
            if full:
 
                check_cell_balance(next(cells), balances['Assets:Receivable'])
 
                check_cell_balance(next(cells), balances['Assets:Prepaid'])
 
                check_cell_balance(next(cells), balances['Liabilities:Payable'])
 
                check_cell_balance(next(cells), balances['Liabilities'])
 
            assert next(cells, None) is None
 
    assert not account_bals, "did not see all funds in report"
 

	
 
def check_ods_report(ods, start_date, stop_date):
 
    account_bals = collections.OrderedDict((key, {
 
        'opening': Decimal(amount),
...
 
@@ -178,27 +206,10 @@ def check_ods_report(ods, start_date, stop_date):
 
                else:
 
                    acct_key, _, _ = account.rpartition(':')
 
                account_bals[fund][acct_key] += amount
 
    account_bals['Unrestricted'] = account_bals.pop('Conservancy')
 
    for row in ods.getElementsByType(odf.table.TableRow):
 
        cells = iter(testutil.ODSCell.from_row(row))
 
        try:
 
            fund = next(cells).firstChild.text
 
        except (AttributeError, StopIteration):
 
            fund = None
 
        if fund in account_bals:
 
            balances = account_bals.pop(fund)
 
            check_cell_balance(next(cells), balances['opening'])
 
            check_cell_balance(next(cells), balances['Income'])
 
            check_cell_balance(next(cells), -balances['Expenses'])
 
            check_cell_balance(next(cells), balances['Equity:Realized'])
 
            check_cell_balance(next(cells), sum(balances[key] for key in [
 
                'opening', 'Income', 'Expenses', 'Equity:Realized',
 
            ]))
 
            check_cell_balance(next(cells), balances['Assets:Receivable'])
 
            check_cell_balance(next(cells), balances['Assets:Prepaid'])
 
            check_cell_balance(next(cells), balances['Liabilities:Payable'])
 
            check_cell_balance(next(cells), balances['Liabilities'])
 
    assert not account_bals, "did not see all funds in report"
 
    sheets = iter(ods.getElementsByType(odf.table.Table))
 
    check_ods_sheet(next(sheets), account_bals, full=False)
 
    check_ods_sheet(next(sheets), account_bals, full=True)
 
    assert next(sheets, None) is None, "found unexpected sheet"
 

	
 
def run_main(out_type, arglist, config=None):
 
    if config is None:
0 comments (0 inline, 0 general)