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

Update mapping for new Schwab CSV format #121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
58 changes: 7 additions & 51 deletions csv2ofx/mappings/schwabchecking.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,20 @@
from operator import itemgetter
import re

# Default value if account_id not found in header rows.
schwab_account_id = "12345"


def is_real(transaction):
# Filter-out header line & lines that only have one column
type = transaction.get('Type')
return type and (type != "Type")


def schwab_filter(transaction):
if is_real(transaction):
return True

# Sanity check header row in CSV matches custom_header
line = transaction.get(mapping["custom_header"][0])
if line in mapping["custom_header"]:
for column in mapping["custom_header"]:
found_col = transaction.get(column)
if found_col != column:
raise ValueError("Header row mismatch (expected: '" + column +
"', found: '" + found_col + "')")

# Look for account_id in one of the lines being filtered out
global schwab_account_id
match = re.search(r'^Transactions for .* account (\.*\d*) as of', line)
if match:
schwab_account_id = match.group(1)
return False


def get_account_id(transaction):
global schwab_account_id
return schwab_account_id


mapping = {
# Technically Schwab Bank CSVs do have a header, but we want to extract
# the account_id from the line that comes before the header, so we use
# custom_header instead of parsing it from the second line of the CSV.
'custom_header': ["Date","Type","Check #","Description","Withdrawal (-)",
"Deposit (+)","RunningBalance"],
'has_header': False,
'filter': schwab_filter,
'has_header': True,
'filter': lambda tr: True if tr.get('Status') == 'Posted' else False,
'is_split': False,
'bank': 'Charles Schwab Bank, N.A.',
'bank_id': '121202211',
'account_id': get_account_id,
'account_id': '12345', # Change to your actual account number if desired
'currency': 'USD',
'account': 'Charles Schwab Checking',
# Schwab Bank includes three lines of text in their CSV which otherwise
# break date parsing. Filtering by lines with no "Type" (and faking out
# the date for those lines) avoids the problem.
'date': lambda tr: tr.get('Date') if is_real(tr) else "1-1-1970",
'check_num': itemgetter('Check #'),
'date': itemgetter('Date'),
'check_num': itemgetter('CheckNumber'),
'payee': itemgetter('Description'),
'desc': itemgetter('Description'),
'type': lambda tr: 'debit' if tr.get('Withdrawal (-)') != '' else 'credit',
'amount': lambda tr: tr.get('Deposit (+)') or tr.get('Withdrawal (-)'),
'type': lambda tr: 'debit' if tr.get('Withdrawal') != '' else 'credit',
'amount': lambda tr: tr.get('Deposit') or tr.get('Withdrawal'),
'balance': itemgetter('RunningBalance'),
}
2 changes: 1 addition & 1 deletion data/converted/schwab-checking-baltest-case1.ofx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ENCODING:UTF-8
<CURDEF>USD</CURDEF>
<BANKACCTFROM>
<BANKID>121202211</BANKID>
<ACCTID>...123</ACCTID>
<ACCTID>12345</ACCTID>
<ACCTTYPE>CHECKING</ACCTTYPE>
</BANKACCTFROM>
<BANKTRANLIST>
Expand Down
2 changes: 1 addition & 1 deletion data/converted/schwab-checking-baltest-case2.ofx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ENCODING:UTF-8
<CURDEF>USD</CURDEF>
<BANKACCTFROM>
<BANKID>121202211</BANKID>
<ACCTID>...123</ACCTID>
<ACCTID>12345</ACCTID>
<ACCTTYPE>CHECKING</ACCTTYPE>
</BANKACCTFROM>
<BANKTRANLIST>
Expand Down
2 changes: 1 addition & 1 deletion data/converted/schwab-checking-baltest-case3.ofx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ENCODING:UTF-8
<CURDEF>USD</CURDEF>
<BANKACCTFROM>
<BANKID>121202211</BANKID>
<ACCTID>...123</ACCTID>
<ACCTID>12345</ACCTID>
<ACCTTYPE>CHECKING</ACCTTYPE>
</BANKACCTFROM>
<BANKTRANLIST>
Expand Down
2 changes: 1 addition & 1 deletion data/converted/schwab-checking-baltest-case4.ofx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ENCODING:UTF-8
<CURDEF>USD</CURDEF>
<BANKACCTFROM>
<BANKID>121202211</BANKID>
<ACCTID>...123</ACCTID>
<ACCTID>12345</ACCTID>
<ACCTTYPE>CHECKING</ACCTTYPE>
</BANKACCTFROM>
<BANKTRANLIST>
Expand Down
2 changes: 1 addition & 1 deletion data/converted/schwab-checking-baltest-case5.ofx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ENCODING:UTF-8
<CURDEF>USD</CURDEF>
<BANKACCTFROM>
<BANKID>121202211</BANKID>
<ACCTID>...123</ACCTID>
<ACCTID>12345</ACCTID>
<ACCTTYPE>CHECKING</ACCTTYPE>
</BANKACCTFROM>
<BANKTRANLIST>
Expand Down
2 changes: 1 addition & 1 deletion data/converted/schwab-checking-baltest-case6.ofx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ENCODING:UTF-8
<CURDEF>USD</CURDEF>
<BANKACCTFROM>
<BANKID>121202211</BANKID>
<ACCTID>...123</ACCTID>
<ACCTID>12345</ACCTID>
<ACCTTYPE>CHECKING</ACCTTYPE>
</BANKACCTFROM>
<BANKTRANLIST>
Expand Down
2 changes: 1 addition & 1 deletion data/converted/schwab-checking-baltest-case7.ofx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ENCODING:UTF-8
<CURDEF>USD</CURDEF>
<BANKACCTFROM>
<BANKID>121202211</BANKID>
<ACCTID>...123</ACCTID>
<ACCTID>12345</ACCTID>
<ACCTTYPE>CHECKING</ACCTTYPE>
</BANKACCTFROM>
<BANKTRANLIST>
Expand Down
2 changes: 1 addition & 1 deletion data/converted/schwab-checking-msmoney.ofx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ NEWFILEUID:NONE
<CURDEF>USD</CURDEF>
<BANKACCTFROM>
<BANKID>121202211</BANKID>
<ACCTID>...123</ACCTID>
<ACCTID>12345</ACCTID>
<ACCTTYPE>CHECKING</ACCTTYPE>
</BANKACCTFROM>
<BANKTRANLIST>
Expand Down
2 changes: 1 addition & 1 deletion data/converted/schwab-checking.ofx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ENCODING:UTF-8
<CURDEF>USD</CURDEF>
<BANKACCTFROM>
<BANKID>121202211</BANKID>
<ACCTID>...123</ACCTID>
<ACCTID>12345</ACCTID>
<ACCTTYPE>CHECKING</ACCTTYPE>
</BANKACCTFROM>
<BANKTRANLIST>
Expand Down
13 changes: 5 additions & 8 deletions data/test/schwab-checking-baltest-case1.csv
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
"Transactions for Checking account ...123 as of 08/20/2022 04:04:41 PM ET"
"Date","Type","Check #","Description","Withdrawal (-)","Deposit (+)","RunningBalance"
"Pending Transactions are not reflected within this sort criterion."
"Posted Transactions"
"08/17/2022","DEPOSIT","","Deposit Mobile Banking","","$20.00","$878.47"
"08/14/2022","ATM","","BMO HARRIS BANK","$103.00","","$858.47"
"08/09/2022","CHECK","558","Check Paid #558","$75.00","","$961.47"
"08/04/2022","ACH","","PAYPAL INST XFER 220803~ Tran: ACHDW","$57.27","","$1,036.47"
"Date","Status","Type","CheckNumber","Description","Withdrawal","Deposit","RunningBalance"
"08/17/2022","Posted","DEPOSIT","","Deposit Mobile Banking","","$20.00","$878.47"
"08/14/2022","Posted","ATM","","BMO HARRIS BANK","$103.00","","$858.47"
"08/09/2022","Posted","CHECK","558","Check Paid #558","$75.00","","$961.47"
"08/04/2022","Posted","ACH","","PAYPAL INST XFER 220803~ Tran: ACHDW","$57.27","","$1,036.47"
13 changes: 5 additions & 8 deletions data/test/schwab-checking-baltest-case2.csv
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
"Transactions for Checking account ...123 as of 08/20/2022 04:04:41 PM ET"
"Date","Type","Check #","Description","Withdrawal (-)","Deposit (+)","RunningBalance"
"Pending Transactions are not reflected within this sort criterion."
"Posted Transactions"
"08/17/2022","DEPOSIT","","Deposit Mobile Banking","","$20.00","$878.47"
"08/17/2022","ATM","","BMO HARRIS BANK","$103.00","","$858.47"
"08/04/2022","ACH","","PAYPAL INST XFER 220803~ Tran: ACHDW","$57.27","","$1,036.47"
"08/09/2022","CHECK","558","Check Paid #558","$75.00","","$961.47"
"Date","Status","Type","CheckNumber","Description","Withdrawal","Deposit","RunningBalance"
"08/17/2022","Posted","DEPOSIT","","Deposit Mobile Banking","","$20.00","$878.47"
"08/17/2022","Posted","ATM","","BMO HARRIS BANK","$103.00","","$858.47"
"08/04/2022","Posted","ACH","","PAYPAL INST XFER 220803~ Tran: ACHDW","$57.27","","$1,036.47"
"08/09/2022","Posted","CHECK","558","Check Paid #558","$75.00","","$961.47"
13 changes: 5 additions & 8 deletions data/test/schwab-checking-baltest-case3.csv
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
"Transactions for Checking account ...123 as of 08/20/2022 04:04:41 PM ET"
"Date","Type","Check #","Description","Withdrawal (-)","Deposit (+)","RunningBalance"
"Pending Transactions are not reflected within this sort criterion."
"Posted Transactions"
"08/04/2022","ACH","","PAYPAL INST XFER 220803~ Tran: ACHDW","$57.27","","$1,036.47"
"08/09/2022","CHECK","558","Check Paid #558","$75.00","","$961.47"
"08/17/2022","ATM","","BMO HARRIS BANK","$103.00","","$858.47"
"08/17/2022","DEPOSIT","","Deposit Mobile Banking","","$20.00","$878.47"
"Date","Status","Type","CheckNumber","Description","Withdrawal","Deposit","RunningBalance"
"08/04/2022","Posted","ACH","","PAYPAL INST XFER 220803~ Tran: ACHDW","$57.27","","$1,036.47"
"08/09/2022","Posted","CHECK","558","Check Paid #558","$75.00","","$961.47"
"08/17/2022","Posted","ATM","","BMO HARRIS BANK","$103.00","","$858.47"
"08/17/2022","Posted","DEPOSIT","","Deposit Mobile Banking","","$20.00","$878.47"
13 changes: 5 additions & 8 deletions data/test/schwab-checking-baltest-case4.csv
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
"Transactions for Checking account ...123 as of 08/20/2022 04:04:41 PM ET"
"Date","Type","Check #","Description","Withdrawal (-)","Deposit (+)","RunningBalance"
"Pending Transactions are not reflected within this sort criterion."
"Posted Transactions"
"08/17/2022","DEPOSIT","","Deposit Mobile Banking","","$20.00","$878.47"
"08/17/2022","ATM","","BMO HARRIS BANK","$103.00","","$858.47"
"08/09/2022","CHECK","558","Check Paid #558","$75.00","","$961.47"
"08/04/2022","ACH","","PAYPAL INST XFER 220803~ Tran: ACHDW","$57.27","","$1,036.47"
"Date","Status","Type","CheckNumber","Description","Withdrawal","Deposit","RunningBalance"
"08/17/2022","Posted","DEPOSIT","","Deposit Mobile Banking","","$20.00","$878.47"
"08/17/2022","Posted","ATM","","BMO HARRIS BANK","$103.00","","$858.47"
"08/09/2022","Posted","CHECK","558","Check Paid #558","$75.00","","$961.47"
"08/04/2022","Posted","ACH","","PAYPAL INST XFER 220803~ Tran: ACHDW","$57.27","","$1,036.47"
13 changes: 5 additions & 8 deletions data/test/schwab-checking-baltest-case5.csv
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
"Transactions for Checking account ...123 as of 08/20/2022 04:04:41 PM ET"
"Date","Type","Check #","Description","Withdrawal (-)","Deposit (+)","RunningBalance"
"Pending Transactions are not reflected within this sort criterion."
"Posted Transactions"
"08/17/2022","ACH","","PAYPAL INST XFER 220803~ Tran: ACHDW","$57.27","","$1,036.47"
"08/17/2022","CHECK","558","Check Paid #558","$75.00","","$961.47"
"08/17/2022","ATM","","BMO HARRIS BANK","$103.00","","$858.47"
"08/17/2022","DEPOSIT","","Deposit Mobile Banking","","$20.00","$878.47"
"Date","Status","Type","CheckNumber","Description","Withdrawal","Deposit","RunningBalance"
"08/17/2022","Posted","ACH","","PAYPAL INST XFER 220803~ Tran: ACHDW","$57.27","","$1,036.47"
"08/17/2022","Posted","CHECK","558","Check Paid #558","$75.00","","$961.47"
"08/17/2022","Posted","ATM","","BMO HARRIS BANK","$103.00","","$858.47"
"08/17/2022","Posted","DEPOSIT","","Deposit Mobile Banking","","$20.00","$878.47"
13 changes: 5 additions & 8 deletions data/test/schwab-checking-baltest-case6.csv
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
"Transactions for Checking account ...123 as of 08/20/2022 04:04:41 PM ET"
"Date","Type","Check #","Description","Withdrawal (-)","Deposit (+)","RunningBalance"
"Pending Transactions are not reflected within this sort criterion."
"Posted Transactions"
"08/17/2022","DEPOSIT","","Deposit Mobile Banking","","$20.00","$878.47"
"08/17/2022","ATM","","BMO HARRIS BANK","$103.00","","$858.47"
"08/17/2022","CHECK","558","Check Paid #558","$75.00","","$961.47"
"08/17/2022","ACH","","PAYPAL INST XFER 220803~ Tran: ACHDW","$57.27","","$1,036.47"
"Date","Status","Type","CheckNumber","Description","Withdrawal","Deposit","RunningBalance"
"08/17/2022","Posted","DEPOSIT","","Deposit Mobile Banking","","$20.00","$878.47"
"08/17/2022","Posted","ATM","","BMO HARRIS BANK","$103.00","","$858.47"
"08/17/2022","Posted","CHECK","558","Check Paid #558","$75.00","","$961.47"
"08/17/2022","Posted","ACH","","PAYPAL INST XFER 220803~ Tran: ACHDW","$57.27","","$1,036.47"
9 changes: 3 additions & 6 deletions data/test/schwab-checking-baltest-case7.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
"Transactions for Checking account ...123 as of 08/20/2022 04:04:41 PM ET"
"Date","Type","Check #","Description","Withdrawal (-)","Deposit (+)","RunningBalance"
"Pending Transactions are not reflected within this sort criterion."
"Posted Transactions"
"08/17/2022","CHECK","558","Check Paid #558","$20.00","","$858.47"
"08/17/2022","DEPOSIT","","Deposit Mobile Banking","","$20.00","$878.47"
"Date","Status","Type","CheckNumber","Description","Withdrawal","Deposit","RunningBalance"
"08/17/2022","Posted","CHECK","558","Check Paid #558","$20.00","","$858.47"
"08/17/2022","Posted","DEPOSIT","","Deposit Mobile Banking","","$20.00","$878.47"
13 changes: 5 additions & 8 deletions data/test/schwab-checking.csv
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
"Transactions for Checking account ...123 as of 08/20/2022 04:04:41 PM ET"
"Date","Type","Check #","Description","Withdrawal (-)","Deposit (+)","RunningBalance"
"Pending Transactions are not reflected within this sort criterion."
"Posted Transactions"
"08/17/2022","DEPOSIT","","Deposit Mobile Banking","","$20.00","$878.47"
"08/14/2022","ATM","","BMO HARRIS BANK","$103.00","","$858.47"
"08/09/2022","CHECK","558","Check Paid #558","$75.00","","$961.47"
"08/04/2022","ACH","","PAYPAL INST XFER 220803~ Tran: ACHDW","$57.27","","$1,036.47"
"Date","Status","Type","CheckNumber","Description","Withdrawal","Deposit","RunningBalance"
"08/17/2022","Posted","DEPOSIT","","Deposit Mobile Banking","","$20.00","$878.47"
"08/14/2022","Posted","ATM","","BMO HARRIS BANK","$103.00","","$858.47"
"08/09/2022","Posted","CHECK","558","Check Paid #558","$75.00","","$961.47"
"08/04/2022","Posted","ACH","","PAYPAL INST XFER 220803~ Tran: ACHDW","$57.27","","$1,036.47"