fund: Add totals rows to the full report.
This is easy to do with the current infrastructure, and it's nice to have.
This commit is contained in:
parent
404a88de1d
commit
1fcab6af32
3 changed files with 23 additions and 8 deletions
|
@ -214,7 +214,9 @@ class ODSReport(core.BaseODS[str, None]):
|
|||
# Write the expanded fund report. start_spreadsheet() will see we've
|
||||
# written the first sheet and adapt.
|
||||
super().write(iter(row_list))
|
||||
self.write_balance_row("", self.sheet_totals, self.style_total)
|
||||
self.write_balances("Unrestricted", fund=core.Fund.UNRESTRICTED)
|
||||
self.write_balance_row("", self.sheet_totals, self.style_bottomline)
|
||||
self.set_open_sheet(self.sheet)
|
||||
|
||||
|
||||
|
|
2
setup.py
2
setup.py
|
@ -5,7 +5,7 @@ from setuptools import setup
|
|||
setup(
|
||||
name='conservancy_beancount',
|
||||
description="Plugin, library, and reports for reading Conservancy's books",
|
||||
version='1.12.1',
|
||||
version='1.12.2',
|
||||
author='Software Freedom Conservancy',
|
||||
author_email='info@sfconservancy.org',
|
||||
license='GNU AGPLv3+',
|
||||
|
|
|
@ -175,21 +175,29 @@ def check_cell_balance(cell, balance):
|
|||
assert not cell.value
|
||||
|
||||
def check_ods_sheet(sheet, account_balances, *, full):
|
||||
total_keys = ['opening', 'Income', 'Expenses', 'Equity']
|
||||
if full:
|
||||
account_bals = account_balances.copy()
|
||||
account_bals['Unrestricted'] = account_bals.pop('Conservancy')
|
||||
unrestricted = account_bals.pop('Conservancy')
|
||||
total_keys += [
|
||||
'Assets:Receivable',
|
||||
'Assets:Prepaid',
|
||||
'Liabilities',
|
||||
'Liabilities:Payable',
|
||||
]
|
||||
else:
|
||||
account_bals = {
|
||||
key: balances
|
||||
for key, balances in account_balances.items()
|
||||
if key != 'Conservancy' and any(v >= .5 for v in balances.values())
|
||||
}
|
||||
totals = {key: Decimal() for key in
|
||||
['opening', 'Income', 'Expenses', 'Equity']}
|
||||
for fund, balances in account_bals.items():
|
||||
for key in totals:
|
||||
totals[key] += balances[key]
|
||||
account_bals[''] = totals
|
||||
totals = {key: Decimal() for key in total_keys}
|
||||
for fund, balances in account_bals.items():
|
||||
for key in totals:
|
||||
totals[key] += balances[key]
|
||||
account_bals[''] = totals
|
||||
if full:
|
||||
account_bals['Unrestricted'] = unrestricted
|
||||
for row in itertools.islice(sheet.getElementsByType(odf.table.TableRow), 4, None):
|
||||
cells = iter(testutil.ODSCell.from_row(row))
|
||||
try:
|
||||
|
@ -218,6 +226,11 @@ def check_ods_sheet(sheet, account_balances, *, full):
|
|||
check_cell_balance(next(cells), balances['Liabilities'])
|
||||
check_cell_balance(next(cells), balances['Liabilities:Payable'])
|
||||
assert next(cells, None) is None
|
||||
if full and fund == 'Unrestricted':
|
||||
assert '' not in account_bals, "Unrestricted funds reported before subtotals"
|
||||
for key, bal in balances.items():
|
||||
totals[key] += bal
|
||||
account_bals[''] = totals
|
||||
assert not account_bals, "did not see all funds in report"
|
||||
|
||||
def check_ods_report(ods, start_date, stop_date):
|
||||
|
|
Loading…
Reference in a new issue