Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(banks): add trust bank credit card #184

Merged
merged 4 commits into from
Jan 14, 2025
Merged

Conversation

rapiz1
Copy link
Contributor

@rapiz1 rapiz1 commented Jan 5, 2025

add trust bank creditcard

I've attached an example statement in tests. It has "Previous Balance" and "Outstanding Balance" in transactions. I'm not sure if we should exclude them and enable safety check.

Notable difference for Trust credit card statement

  1. For mutli-line transaction description, the description can start the previous line before the $amount line.
  2. Number like +64.2 is CR. It's a prefix instead of suffix.
  3. The statement date sometimes can be multiline as well. But I've only observed it with 2024 Dec. Maybe it's a misformat on Trust end. The proposed change cannot handle such case.

Resolves #183

@rapiz1 rapiz1 changed the title feat(banks): add trust bank creditcard feat(banks): add trust bank credit card Jan 7, 2025
@rapiz1 rapiz1 force-pushed the trust branch 2 times, most recently from 0a89331 to 64093cb Compare January 8, 2025 13:42
Comment on lines 159 to 165
TRUST = (
rf"(?P<transaction_date>{ISO8601.DD_MMM})\s+"
+ SharedPatterns.DESCRIPTION
+ SharedPatterns.AMOUNT_EXTENDED
)
Copy link
Owner

@benjamin-awd benjamin-awd Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you add an optional capture group for suffix, it'll be able to catch the +682 in your statement -- the other transactions will default to negative

    TRUST = (
        rf"(?P<transaction_date>{ISO8601.DD_MMM})\s+"
        + SharedPatterns.DESCRIPTION
        + r"(?P<suffix>\+)?"
        + SharedPatterns.AMOUNT
    )

This means you won't need to modify the OPTIONAL_NEGATIVE_SYMBOL (I should probably put it only for the specific bank that needs it)

Copy link
Owner

@benjamin-awd benjamin-awd Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the same time you can replace the description pattern with a custom one using a negative lookahead, so that it excludes totals:

TRUST = (
        rf"(?P<transaction_date>{ISO8601.DD_MMM})\s+"
        + r"(?P<description>(?:(?!Total outstanding balance).)*?)"
        + r"(?P<suffix>\+)?"
        + SharedPatterns.AMOUNT
    )

This will then allow the safety check to work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I wasn't familiar with the negative lookahead pattern until some searching. Is this a more readable pattern for descrpition?

+ r"(?P<description>(?:.(?!Total outstanding balance))*)"

I find lots of examples about negative lookahead but the "lookahead" is after some token. I cannot tell why the line you provide works because there's no token before the lookahead

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with modifying the transaction pattern regex here, but the pattern you mentioned doesn't seem to work 😕

There is actually a token before, which is \s+, but isn't reflected well in the multiline string unfortunately

it should work out to something like 12 Oct\s+(?!\s+Total outstanding balance)\s+.*
https://regex101.com/r/tQGJVE/1

Comment on lines 154 to 168
if include_prev and idx - 1 > 0:
prev_line = lines[idx - 1]
if prev_line:
# if previous line is a transaction, it cannot be part of the description
if not self.pattern.search(prev_line):
prev_line_text = prev_line.strip()
prev_line_start_pos = prev_line.find(prev_line_text.split(" ")[0])
# don't process line if the description across both lines
# doesn't align with a margin of three spaces
if (
abs(description_pos - prev_line_start_pos)
<= include_prev_margin
):
description = prev_line_text + " " + description

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have an example of a multiline transaction that isn't currently well handled? I looked at your example statement but everything appears on a single line

Comment on lines +70 to +71
if total_amount_found:
return True
Copy link
Owner

@benjamin-awd benjamin-awd Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! It's weird that no other banks that I have so far give a total amount like this.

Comment on lines 75 to 82
try:
logger.debug("Running debit statement safety check for credit statement")
return True
if DebitStatement.perform_safety_check(self):
return True
# the try-catch is needed to prevent a SafetyCheckError from being raised
# a more verbose exception is raised later
except SafetyCheckError:
pass
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think with the new regex pattern this bit isn't needed anymore

@benjamin-awd
Copy link
Owner

@rapiz1 Thanks for raising the PR! A few comments, but otherwise this looks pretty good

@rapiz1 rapiz1 force-pushed the trust branch 2 times, most recently from b868b5f to f517a7d Compare January 12, 2025 14:59
@benjamin-awd benjamin-awd force-pushed the trust branch 3 times, most recently from 047286c to 64785f7 Compare January 14, 2025 14:49
@benjamin-awd benjamin-awd merged commit f1dce96 into benjamin-awd:main Jan 14, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

trust bank credit card support
2 participants