data.Account: Add is_income method.
This commit is contained in:
parent
b7089f5ddf
commit
7cd569be7b
3 changed files with 17 additions and 1 deletions
|
@ -35,6 +35,9 @@ from .beancount_types import (
|
||||||
class Account(str):
|
class Account(str):
|
||||||
SEP = bc_account.sep
|
SEP = bc_account.sep
|
||||||
|
|
||||||
|
def is_income(self) -> bool:
|
||||||
|
return self.is_under('Income:', 'UnearnedIncome:') is not None
|
||||||
|
|
||||||
def is_real_asset(self) -> bool:
|
def is_real_asset(self) -> bool:
|
||||||
return bool(
|
return bool(
|
||||||
self.is_under('Assets:')
|
self.is_under('Assets:')
|
||||||
|
|
|
@ -43,7 +43,7 @@ class MetaIncomeType(core._NormalizePostingMetadataHook):
|
||||||
}
|
}
|
||||||
|
|
||||||
def _run_on_post(self, txn: Transaction, post: data.Posting) -> bool:
|
def _run_on_post(self, txn: Transaction, post: data.Posting) -> bool:
|
||||||
return post.account.is_under('Income:', 'UnearnedIncome:') is not None
|
return post.account.is_income()
|
||||||
|
|
||||||
def _default_value(self, txn: Transaction, post: data.Posting) -> MetaValueEnum:
|
def _default_value(self, txn: Transaction, post: data.Posting) -> MetaValueEnum:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -45,6 +45,19 @@ def test_is_under_multi_arg(acct_name, expected):
|
||||||
expected += ':'
|
expected += ':'
|
||||||
assert data.Account(acct_name).is_under('Income:', 'UnearnedIncome:') == expected
|
assert data.Account(acct_name).is_under('Income:', 'UnearnedIncome:') == expected
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('acct_name,expected', [
|
||||||
|
('Accrued:AccountsReceivable', False),
|
||||||
|
('Assets:Cash', False),
|
||||||
|
('Expenses:General', False),
|
||||||
|
('Income:Donations', True),
|
||||||
|
('Income:Sales', True),
|
||||||
|
('Income:Other', True),
|
||||||
|
('Liabilities:CreditCard', False),
|
||||||
|
('UnearnedIncome:MatchPledges', True),
|
||||||
|
])
|
||||||
|
def test_is_income(acct_name, expected):
|
||||||
|
assert data.Account(acct_name).is_income() == expected
|
||||||
|
|
||||||
@pytest.mark.parametrize('acct_name,expected', [
|
@pytest.mark.parametrize('acct_name,expected', [
|
||||||
('Accrued:AccountsPayable', False),
|
('Accrued:AccountsPayable', False),
|
||||||
('Accrued:AccountsReceivable', False),
|
('Accrued:AccountsReceivable', False),
|
||||||
|
|
Loading…
Reference in a new issue