data: Add Account.keeps_balance() method.

This commit is contained in:
Brett Smith 2020-07-17 09:33:59 -04:00
parent 88ae03302f
commit a0372d4b73
2 changed files with 30 additions and 0 deletions

View file

@ -285,6 +285,12 @@ class Account(str):
return prefix
return None
def keeps_balance(self) -> bool:
return self.is_under(
self._options_map['name_assets'],
self._options_map['name_liabilities'],
) is not None
def _find_part_slice(self, index: int) -> slice:
if index < 0:
raise ValueError(f"bad part index {index!r}")

View file

@ -160,6 +160,30 @@ def test_is_credit_card(acct_name, expected):
def test_is_opening_equity(acct_name, expected):
assert data.Account(acct_name).is_opening_equity() == expected
@pytest.mark.parametrize('acct_name', [
'Assets:Cash',
'Assets:Prepaid:Expenses',
'Assets:Receivable:Accounts',
'Expenses:Other',
'Equity:Funds:Restricted',
'Equity:OpeningBalance',
'Income:Other',
'Liabilities:CreditCard',
'Liabilities:Payable:Accounts',
'Liabilities:UnearnedIncome:Donations',
])
def test_keeps_balance(acct_name):
expected = acct_name.startswith(('Assets:', 'Liabilities:'))
assert data.Account(acct_name).keeps_balance() == expected
def test_keeps_balance_uses_options(clean_account_meta):
config = bc_options.OPTIONS_DEFAULTS.copy()
config['name_liabilities'] = 'Debts'
data.Account.load_options_map(config)
assert not data.Account('Liabilities:CreditCard').keeps_balance()
assert data.Account('Debts:Payable').keeps_balance()
assert data.Account('Assets:Receivable').keeps_balance()
@pytest.mark.parametrize('acct_name', [
'Assets:Cash',
'Assets:Receivable:Accounts',