Skip to content

Commit

Permalink
Fix None reference (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtlynch authored Jul 26, 2024
1 parent c58a1f7 commit 7800583
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions beancount_chase/checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ def _extract_transaction_from_row(self, row, metadata):
meta=None)
]
for pattern, account_name in self._account_patterns:
if pattern.search(payee) or pattern.search(
narration) or pattern.search(payee + narration):
if _pattern_matches_transaction(pattern, payee, narration):
postings.append(
data.Posting(account=account_name,
units=-transaction_amount,
Expand Down Expand Up @@ -140,7 +139,7 @@ def _extract_transaction_from_row(self, row, metadata):
_MONTHLY_SERVICE_FEE_REVERSAL_PATTERN = re.compile(
r'^Monthly Service Fee Reversal ', re.IGNORECASE)

_REAL_TIME_PAYMENT_FEE_PATTERN = re.compile(r'^RTP/(.+)', re.IGNORECASE)
_REAL_TIME_PAYMENT_FEE_PATTERN = re.compile(r'^RTP/', re.IGNORECASE)


def _parse_description(description):
Expand All @@ -164,5 +163,15 @@ def _parse_description(description):
return description, None
match = _REAL_TIME_PAYMENT_FEE_PATTERN.search(description)
if match:
return 'Real-Time Payments: ' + match.group(1), None
return description, None
return None, None


def _pattern_matches_transaction(pattern, payee, narration):
targets = [payee]
if narration:
targets.extend([narration, payee + narration])
for target in targets:
if pattern.search(target):
return True
return False
2 changes: 1 addition & 1 deletion beancount_chase/checking_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def test_extracts_real_time_payment_fee(tmp_path):
lastfour='1234').extract(f)

assert _unindent("""
2024-06-03 * "Real-Time Payments: Same Day - Low Value" ""
2024-06-03 * "RTP/Same Day - Low Value" ""
Assets:Checking:Chase -1.75 USD
""".rstrip()) == _stringify_directives(directives).strip()

Expand Down

0 comments on commit 7800583

Please sign in to comment.