Skip to content

Commit

Permalink
Recognize monthly service fee reversal (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtlynch authored Mar 7, 2024
1 parent aa0683b commit 1b91dda
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
16 changes: 14 additions & 2 deletions beancount_chase/checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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
22 changes: 20 additions & 2 deletions beancount_chase/checking_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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()

Expand Down

0 comments on commit 1b91dda

Please sign in to comment.