diff --git a/beancount_chase/checking.py b/beancount_chase/checking.py index b45dc44..3e6d8b9 100644 --- a/beancount_chase/checking.py +++ b/beancount_chase/checking.py @@ -24,11 +24,13 @@ def __init__(self, account, lastfour=None, currency='USD', - account_patterns=None): + account_patterns=None, + title_case=True): self._account = account self._last_four_account_digits = lastfour self._currency = currency self._account_patterns = [] + self._title_case = title_case if account_patterns: for pattern, account_name in account_patterns: self._account_patterns.append( @@ -67,11 +69,12 @@ def _extract_transaction_from_row(self, row, metadata): '%m/%d/%Y').date() payee, transaction_description = _parse_description(row[_COLUMN_PAYEE]) if payee: - payee = titlecase.titlecase(payee) + payee = titlecase.titlecase(payee) if self._title_case else payee else: raise ValueError(f'failed to parse {row[_COLUMN_PAYEE]}') if transaction_description: - narration = titlecase.titlecase(transaction_description) + narration = (titlecase.titlecase(transaction_description) + if self._title_case else transaction_description) if row[_COLUMN_AMOUNT]: transaction_amount = self._parse_amount(row[_COLUMN_AMOUNT]) else: diff --git a/beancount_chase/checking_test.py b/beancount_chase/checking_test.py index 0e3813f..65399f8 100644 --- a/beancount_chase/checking_test.py +++ b/beancount_chase/checking_test.py @@ -66,6 +66,25 @@ def test_extracts_monthly_account_fee(tmp_path): """.rstrip()) == _stringify_directives(directives).strip() +def test_doesnt_title_case_if_asked_not_to(tmp_path): + chase_file = tmp_path / 'Chase1234_Activity_20230919.CSV' + chase_file.write_text( + _unindent(""" + Details,Posting Date,Description,Amount,Type,Balance,Check or Slip # + DEBIT,08/31/2023,"MONTHLY SERVICE FEE",-15.00,FEE_TRANSACTION,2118.39,, + """)) + + with chase_file.open() as f: + directives = CheckingImporter(account='Assets:Checking:Chase', + lastfour='1234', + title_case=False).extract(f) + + assert _unindent(""" + 2023-08-31 * "MONTHLY SERVICE FEE" "MONTHLY SERVICE FEE" + Assets:Checking:Chase -15.00 USD + """.rstrip()) == _stringify_directives(directives).strip() + + def test_extracts_credit(tmp_path): chase_file = tmp_path / 'Chase1234_Activity_20211019.CSV' chase_file.write_text( diff --git a/beancount_chase/credit.py b/beancount_chase/credit.py index 3a83937..ff0f93d 100644 --- a/beancount_chase/credit.py +++ b/beancount_chase/credit.py @@ -24,11 +24,13 @@ def __init__(self, account, lastfour=None, currency='USD', - account_patterns=None): + account_patterns=None, + title_case=True): self._account = account self._last_four_account_digits = lastfour self._currency = currency self._account_patterns = [] + self._title_case = title_case if account_patterns: for pattern, account_name in account_patterns: self._account_patterns.append( @@ -67,7 +69,8 @@ def _extract_transaction_from_row(self, row, metadata): '%m/%d/%Y').date() payee = row[_COLUMN_PAYEE] - transaction_description = titlecase.titlecase(payee) + transaction_description = (titlecase.titlecase(payee) + if self._title_case else payee) if row[_COLUMN_AMOUNT]: transaction_amount = self._parse_amount(row[_COLUMN_AMOUNT]) diff --git a/beancount_chase/credit_test.py b/beancount_chase/credit_test.py index 06a3648..4c5558f 100644 --- a/beancount_chase/credit_test.py +++ b/beancount_chase/credit_test.py @@ -86,6 +86,31 @@ def test_extracts_spend_with_matching_transaction(tmp_path): """.rstrip()) == _stringify_directives(directives).strip() +def test_doesnt_title_case_if_asked_not_to(tmp_path): + chase_file = tmp_path / 'Chase1234_Activity20210103_20210202_20210214.CSV' + chase_file.write_text( + _unindent(""" + Card,Transaction Date,Post Date,Description,Category,Type,Amount,Memo + 1234,10/29/2021,10/31/2021,GOOGLE *CLOUD_02BB66-C,Professional Services,Sale,-25.35, + """)) + + with chase_file.open() as f: + directives = CreditImporter( + account='Liabilities:Credit-Cards:Chase', + lastfour='1234', + account_patterns=[ + ('Google.*Cloud', + 'Expenses:Cloud-Services:Google-Cloud-Platform'), + ], + title_case=False).extract(f) + + assert _unindent(""" + 2021-10-29 * "GOOGLE *CLOUD_02BB66-C" + Liabilities:Credit-Cards:Chase -25.35 USD + Expenses:Cloud-Services:Google-Cloud-Platform 25.35 USD + """.rstrip()) == _stringify_directives(directives).strip() + + def test_extracts_refund(tmp_path): chase_file = tmp_path / 'Chase1234_Activity20210103_20210202_20210214.CSV' chase_file.write_text(