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

Make title-casing optional #112

Merged
merged 3 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions beancount_chase/checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down
19 changes: 19 additions & 0 deletions beancount_chase/checking_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 5 additions & 2 deletions beancount_chase/credit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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])
Expand Down
25 changes: 25 additions & 0 deletions beancount_chase/credit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down