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:
Brett Smith 2020-10-16 16:39:46 -04:00
parent 404a88de1d
commit 1fcab6af32
3 changed files with 23 additions and 8 deletions

View file

@ -214,7 +214,9 @@ class ODSReport(core.BaseODS[str, None]):
# Write the expanded fund report. start_spreadsheet() will see we've # Write the expanded fund report. start_spreadsheet() will see we've
# written the first sheet and adapt. # written the first sheet and adapt.
super().write(iter(row_list)) 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_balances("Unrestricted", fund=core.Fund.UNRESTRICTED)
self.write_balance_row("", self.sheet_totals, self.style_bottomline)
self.set_open_sheet(self.sheet) self.set_open_sheet(self.sheet)

View file

@ -5,7 +5,7 @@ from setuptools import setup
setup( setup(
name='conservancy_beancount', name='conservancy_beancount',
description="Plugin, library, and reports for reading Conservancy's books", description="Plugin, library, and reports for reading Conservancy's books",
version='1.12.1', version='1.12.2',
author='Software Freedom Conservancy', author='Software Freedom Conservancy',
author_email='info@sfconservancy.org', author_email='info@sfconservancy.org',
license='GNU AGPLv3+', license='GNU AGPLv3+',

View file

@ -175,21 +175,29 @@ def check_cell_balance(cell, balance):
assert not cell.value assert not cell.value
def check_ods_sheet(sheet, account_balances, *, full): def check_ods_sheet(sheet, account_balances, *, full):
total_keys = ['opening', 'Income', 'Expenses', 'Equity']
if full: if full:
account_bals = account_balances.copy() 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: else:
account_bals = { account_bals = {
key: balances key: balances
for key, balances in account_balances.items() for key, balances in account_balances.items()
if key != 'Conservancy' and any(v >= .5 for v in balances.values()) if key != 'Conservancy' and any(v >= .5 for v in balances.values())
} }
totals = {key: Decimal() for key in totals = {key: Decimal() for key in total_keys}
['opening', 'Income', 'Expenses', 'Equity']} for fund, balances in account_bals.items():
for fund, balances in account_bals.items(): for key in totals:
for key in totals: totals[key] += balances[key]
totals[key] += balances[key] account_bals[''] = totals
account_bals[''] = totals if full:
account_bals['Unrestricted'] = unrestricted
for row in itertools.islice(sheet.getElementsByType(odf.table.TableRow), 4, None): for row in itertools.islice(sheet.getElementsByType(odf.table.TableRow), 4, None):
cells = iter(testutil.ODSCell.from_row(row)) cells = iter(testutil.ODSCell.from_row(row))
try: 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'])
check_cell_balance(next(cells), balances['Liabilities:Payable']) check_cell_balance(next(cells), balances['Liabilities:Payable'])
assert next(cells, None) is None 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" assert not account_bals, "did not see all funds in report"
def check_ods_report(ods, start_date, stop_date): def check_ods_report(ods, start_date, stop_date):