From 2d49f7dfbcf4ec09dd4d8e81175826750e2e5d3e Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Mon, 30 Mar 2020 15:01:25 -0400 Subject: [PATCH] data: Add Account.is_checking() method. --- conservancy_beancount/data.py | 3 +++ tests/test_data_account.py | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/conservancy_beancount/data.py b/conservancy_beancount/data.py index ddb3196..b8bd4cc 100644 --- a/conservancy_beancount/data.py +++ b/conservancy_beancount/data.py @@ -62,6 +62,9 @@ class Account(str): """ SEP = bc_account.sep + def is_checking(self) -> bool: + return self.is_real_asset() and ':Check' in self + def is_income(self) -> bool: return self.is_under('Income:', 'UnearnedIncome:') is not None diff --git a/tests/test_data_account.py b/tests/test_data_account.py index 4883be8..b2901d4 100644 --- a/tests/test_data_account.py +++ b/tests/test_data_account.py @@ -71,3 +71,22 @@ def test_is_income(acct_name, expected): ]) def test_is_real_asset(acct_name, expected): assert data.Account(acct_name).is_real_asset() == expected + +@pytest.mark.parametrize('acct_name,expected', [ + ('Accrued:AccountsPayable', False), + ('Accrued:AccountsReceivable', False), + ('Assets:Bank:Check9999', True), + ('Assets:Bank:CheckCard', True), + ('Assets:Bank:Checking', True), + ('Assets:Bank:Savings', False), + ('Assets:Cash', False), + ('Assets:Check9999', True), + ('Assets:CheckCard', True), + ('Assets:Checking', True), + ('Assets:PrepaidExpenses', False), + ('Assets:Savings', False), + ('Expenses:CheckingFees', False), + ('Income:Interest:Checking', False), +]) +def test_is_checking(acct_name, expected): + assert data.Account(acct_name).is_checking() == expected