From 73bbc1e4ec8add613fd4dc156accfe7246b89bdf Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Fri, 16 Oct 2020 10:05:23 -0400 Subject: [PATCH] data: Define EQUITY_ACCOUNTS and FUND_ACCOUNTS. --- conservancy_beancount/data.py | 11 +++++++++++ .../reports/balance_sheet.py | 11 +++++------ .../tools/opening_balances.py | 19 ++----------------- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/conservancy_beancount/data.py b/conservancy_beancount/data.py index 24d04b5..cd04b23 100644 --- a/conservancy_beancount/data.py +++ b/conservancy_beancount/data.py @@ -62,6 +62,17 @@ from .beancount_types import ( DecimalCompat = Union[decimal.Decimal, int] +EQUITY_ACCOUNTS = frozenset([ + 'Equity', + 'Expenses', + 'Income', +]) +FUND_ACCOUNTS = EQUITY_ACCOUNTS | frozenset([ + 'Assets:Prepaid', + 'Assets:Receivable', + 'Liabilities:Payable', + 'Liabilities:UnearnedIncome', +]) LINK_METADATA = frozenset([ 'approval', 'bank-statement', diff --git a/conservancy_beancount/reports/balance_sheet.py b/conservancy_beancount/reports/balance_sheet.py index cbed0b7..f802a5a 100644 --- a/conservancy_beancount/reports/balance_sheet.py +++ b/conservancy_beancount/reports/balance_sheet.py @@ -56,7 +56,6 @@ from .. import config as configmod from .. import data from .. import ranges -EQUITY_ACCOUNTS = frozenset(['Equity', 'Income', 'Expenses']) PROGNAME = 'balance-sheet-report' logger = logging.getLogger('conservancy_beancount.reports.balance_sheet') @@ -186,7 +185,7 @@ class Balances: sort_period: Optional[int]=None, ) -> Sequence[data.Account]: if sort_period is None: - if account in EQUITY_ACCOUNTS: + if account in data.EQUITY_ACCOUNTS: sort_period = Period.PERIOD else: sort_period = Period.ANY @@ -399,7 +398,7 @@ class Report(core.BaseODS[Sequence[None], None]): preposition = "Without" if fund is Fund.UNRESTRICTED else "With" row = self.add_row(self.string_cell(f"{preposition} donor restrictions")) for kwargs, total_bal in zip(balance_kwargs, equity_totals): - balance = -self.balances.total(account=EQUITY_ACCOUNTS, fund=fund, **kwargs) + balance = -self.balances.total(account=data.EQUITY_ACCOUNTS, fund=fund, **kwargs) row.addElement(self.balance_cell(balance)) total_bal += balance self.write_totals_row( @@ -500,7 +499,7 @@ class Report(core.BaseODS[Sequence[None], None]): else: kwargs['period'] = Period.OPENING equity_totals = [ - -self.balances.total(account=EQUITY_ACCOUNTS, **kwargs) + -self.balances.total(account=data.EQUITY_ACCOUNTS, **kwargs) for kwargs in bal_kwargs ] self.write_totals_row("Beginning Net Assets", equity_totals) @@ -544,7 +543,7 @@ class Report(core.BaseODS[Sequence[None], None]): stylename=self.style_bold, )) equity_totals = [ - -self.balances.total(account=EQUITY_ACCOUNTS, **kwargs) + -self.balances.total(account=data.EQUITY_ACCOUNTS, **kwargs) for kwargs in bal_kwargs ] self.write_totals_row("Change in Net Assets", equity_totals, leading_rows=1) @@ -605,7 +604,7 @@ class Report(core.BaseODS[Sequence[None], None]): for acct_root in ['Assets', 'Liabilities', 'Income', 'Expenses', 'Equity']: norm_func = core.normalize_amount_func(f'{acct_root}:Dummy') - want_balance = acct_root not in EQUITY_ACCOUNTS + want_balance = acct_root not in data.EQUITY_ACCOUNTS self.add_row() for account in self.balances.iter_accounts(acct_root): period_bal = self.balances.total( diff --git a/conservancy_beancount/tools/opening_balances.py b/conservancy_beancount/tools/opening_balances.py index d9baa2e..9a488cd 100644 --- a/conservancy_beancount/tools/opening_balances.py +++ b/conservancy_beancount/tools/opening_balances.py @@ -70,21 +70,6 @@ from beancount.core.convert import get_cost from beancount.core.inventory import Inventory from beancount.core.position import Position, get_position -EQUITY_ACCOUNTS = frozenset([ - 'Equity', - 'Expenses', - 'Income', -]) -FUND_ACCOUNTS = frozenset([ - 'Assets:Prepaid', - 'Assets:Receivable', - 'Equity:Funds', - 'Equity:Realized', - 'Expenses', - 'Income', - 'Liabilities:Payable', - 'Liabilities:UnearnedIncome', -]) RESTRICTED_ACCOUNT = data.Account('Equity:Funds:Restricted') UNRESTRICTED_ACCOUNT = data.Account('Equity:Funds:Unrestricted') PROGNAME = 'opening-balances' @@ -206,8 +191,8 @@ def main(arglist: Optional[Sequence[str]]=None, if post.meta.date >= args.as_of_date: continue account = post.account - fund_acct_match = post.account.is_under(*FUND_ACCOUNTS) - is_equity = account.root_part() in EQUITY_ACCOUNTS + fund_acct_match = post.account.is_under(*data.FUND_ACCOUNTS) + is_equity = account.root_part() in data.EQUITY_ACCOUNTS if fund_acct_match is None: project: MetaValue = None else: