Changeset - d473ed54fc6b
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-06-27 20:51:35
brettcsmith@brettcsmith.org
fund: Add outstanding balances to ODS fund report.
2 files changed with 25 insertions and 10 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reports/fund.py
Show inline comments
...
 
@@ -100,13 +100,13 @@ class ODSReport(core.BaseODS[FundPosts, None]):
 

	
 
    def section_key(self, row: FundPosts) -> None:
 
        return None
 

	
 
    def start_spreadsheet(self) -> None:
 
        self.use_sheet("Fund Report")
 
        for width in [2.5, 1.5, 1.2, 1.2, 1.2, 1.5]:
 
        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))
 
        center_bold = self.merge_styles(self.style_centertext, self.style_bold)
 
        self.add_row(
 
            self.string_cell(
 
                "Fund", stylename=self.merge_styles(self.style_endtext, self.style_bold),
...
 
@@ -115,12 +115,16 @@ class ODSReport(core.BaseODS[FundPosts, None]):
 
                                stylename=center_bold),
 
            self.string_cell("Income", stylename=center_bold),
 
            self.string_cell("Expenses", stylename=center_bold),
 
            self.multiline_cell(["Realized", "Gain/Loss"], stylename=center_bold),
 
            self.multiline_cell(["Balance as of", self.stop_date.isoformat()],
 
                                stylename=center_bold),
 
            self.multiline_cell(["Of Which", "Receivable"], stylename=center_bold),
 
            self.multiline_cell(["Of Which", "Prepaid Expenses"], stylename=center_bold),
 
            self.multiline_cell(["Of Which", "Payable"], stylename=center_bold),
 
            self.multiline_cell(["Of Which", "Unearned Income"], stylename=center_bold),
 
        )
 
        self.lock_first_row()
 
        self.add_row()
 
        self.add_row(self.string_cell(
 
            f"Fund Report From {self.start_date.isoformat()} To {self.stop_date.isoformat()}",
 
            stylename=center_bold,
...
 
@@ -140,12 +144,16 @@ class ODSReport(core.BaseODS[FundPosts, None]):
 
                balances[acct_root] += balance
 
        for key in key_order:
 
            if key == 'Expenses':
 
                yield balances[key]
 
            else:
 
                yield -balances[key]
 
        for info_key in INFO_ACCOUNTS:
 
            for _, balance in core.account_balances(accounts_map, [info_key]):
 
                pass
 
            yield core.normalize_amount_func(info_key)(balance)
 

	
 
    def write_row(self, row: FundPosts) -> None:
 
        fund, accounts_map = row
 
        if fund == UNRESTRICTED_FUND:
 
            assert not self.unrestricted
 
            self.unrestricted = accounts_map
tests/test_reports_fund.py
Show inline comments
...
 
@@ -146,12 +146,18 @@ def check_text_report(output, project, start_date, stop_date):
 
        'Assets:Prepaid:Expenses',
 
        'Liabilities:Payable:Accounts',
 
        'Liabilities:UnearnedIncome',
 
    )
 
    assert next(actual, None) is None
 

	
 
def check_cell_balance(cell, balance):
 
    if balance:
 
        assert cell.value == balance
 
    else:
 
        assert not cell.value
 

	
 
def check_ods_report(ods, start_date, stop_date):
 
    account_bals = collections.OrderedDict((key, {
 
        'opening': Decimal(amount),
 
        'Income': Decimal(0),
 
        'Expenses': Decimal(0),
 
        'Equity:Realized': Decimal(0),
...
 
@@ -178,22 +184,23 @@ def check_ods_report(ods, start_date, stop_date):
 
        try:
 
            fund = next(cells).firstChild.text
 
        except (AttributeError, StopIteration):
 
            fund = None
 
        if fund in account_bals:
 
            balances = account_bals.pop(fund)
 
            assert next(cells).value == balances['opening']
 
            assert next(cells).value == balances['Income']
 
            assert next(cells).value == -balances['Expenses']
 
            if balances['Equity:Realized']:
 
                assert next(cells).value == balances['Equity:Realized']
 
            else:
 
                assert not next(cells).value
 
            assert next(cells).value == sum(balances[key] for key in [
 
            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"
 

	
 
def run_main(out_type, arglist, config=None):
 
    if config is None:
 
        config = testutil.TestConfig(
 
            books_path=testutil.test_path('books/fund.beancount'),
0 comments (0 inline, 0 general)