diff --git a/beancount_chase/checking.py b/beancount_chase/checking.py index 3e6d8b9..ac069ef 100644 --- a/beancount_chase/checking.py +++ b/beancount_chase/checking.py @@ -75,6 +75,8 @@ def _extract_transaction_from_row(self, row, metadata): if transaction_description: narration = (titlecase.titlecase(transaction_description) if self._title_case else transaction_description) + else: + narration = None if row[_COLUMN_AMOUNT]: transaction_amount = self._parse_amount(row[_COLUMN_AMOUNT]) else: @@ -129,6 +131,12 @@ def _extract_transaction_from_row(self, row, metadata): _INBOUND_TRANSFER_PATTERN = re.compile( r'Online Transfer \d+ from (.+?)\s*transaction #', re.IGNORECASE) +_MONTHLY_SERVICE_FEE_PATTERN = re.compile(r'^MONTHLY SERVICE FEE$', + re.IGNORECASE) + +_MONTHLY_SERVICE_FEE_REVERSAL_PATTERN = re.compile( + r'^Monthly Service Fee Reversal ', re.IGNORECASE) + def _parse_description(description): match = _DESCRIPTION_PATTERN.search(description) @@ -140,6 +148,10 @@ def _parse_description(description): match = _INBOUND_TRANSFER_PATTERN.search(description) if match: return match.group(1), description - if description == 'MONTHLY SERVICE FEE': - return description, description + match = _MONTHLY_SERVICE_FEE_PATTERN.search(description) + if match: + return description, None + match = _MONTHLY_SERVICE_FEE_REVERSAL_PATTERN.search(description) + if match: + return description, None return None, None diff --git a/beancount_chase/checking_test.py b/beancount_chase/checking_test.py index 65399f8..9858ce5 100644 --- a/beancount_chase/checking_test.py +++ b/beancount_chase/checking_test.py @@ -61,11 +61,29 @@ def test_extracts_monthly_account_fee(tmp_path): lastfour='1234').extract(f) assert _unindent(""" - 2023-08-31 * "Monthly Service Fee" "Monthly Service Fee" + 2023-08-31 * "Monthly Service Fee" "" Assets:Checking:Chase -15.00 USD """.rstrip()) == _stringify_directives(directives).strip() +def test_extracts_monthly_account_fee_refund(tmp_path): + chase_file = tmp_path / 'Chase1234_Activity_20240309.CSV' + chase_file.write_text( + _unindent(""" + Details,Posting Date,Description,Amount,Type,Balance,Check or Slip # + CREDIT,02/01/2024,"Monthly Service Fee Reversal January 2024",15.00,REFUND_TRANSACTION,2521.99,, + """)) + + with chase_file.open() as f: + directives = CheckingImporter(account='Assets:Checking:Chase', + lastfour='1234').extract(f) + + assert _unindent(""" + 2024-02-01 * "Monthly Service Fee Reversal January 2024" "" + Assets:Checking:Chase 15.00 USD + """.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( @@ -80,7 +98,7 @@ def test_doesnt_title_case_if_asked_not_to(tmp_path): title_case=False).extract(f) assert _unindent(""" - 2023-08-31 * "MONTHLY SERVICE FEE" "MONTHLY SERVICE FEE" + 2023-08-31 * "MONTHLY SERVICE FEE" "" Assets:Checking:Chase -15.00 USD """.rstrip()) == _stringify_directives(directives).strip()