Skip to content

Commit

Permalink
Support 8 columns in Schwab transactions CSV (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
KapJI committed Jan 22, 2023
1 parent 03d20b3 commit 5c18196
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
11 changes: 6 additions & 5 deletions cgt_calc/parsers/schwab.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ def __init__(
file: str,
):
"""Create transaction from CSV row."""
if len(row) != 9:
raise UnexpectedColumnCountError(row, 9, file)
if row[8] != "":
if len(row) < 8 or len(row) > 9:
# Old transactions had empty 9th column.
raise UnexpectedColumnCountError(row, 8, file)
if len(row) == 9 and row[8] != "":
raise ParsingError(file, "Column 9 should be empty")
as_of_str = " as of "
if as_of_str in row[0]:
Expand Down Expand Up @@ -172,11 +173,11 @@ def read_schwab_transactions(
"'Transactions for account ...'",
)

if len(lines[1]) != 9:
if len(lines[1]) < 8 or len(lines[1]) > 9:
raise ParsingError(
transactions_file,
"Second line of Schwab transactions file must be a header"
" with 9 columns",
" with 8 columns",
)

if "Total" not in lines[-1][0]:
Expand Down
24 changes: 12 additions & 12 deletions tests/test_data/schwab_transactions.csv
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"Transactions for account XXXX-1234 as of 01/23/2021 14:29:39 ET"
"Date","Action","Symbol","Description","Quantity","Price","Fees & Comm","Amount",
"04/02/2021","Buy","FOO","FOO INC","30.5","$30.2","$4","-$925.1",
"03/06/2021","Sell","FOO","FOO INC","90","$33","$5","$2965",
"03/06/2021","Buy","FOO","FOO INC","90","$32","$5","-$2885",
"03/03/2021","Sell","FOO","FOO INC","104","$31","$5","$3219",
"03/03/2021","Buy","FOO","FOO INC","4","$30","$0","-$120",
"03/03/2021","Buy","FOO","FOO INC","100","$29","$5","-$2905",
"03/03/2021","Sell","FOO","FOO INC","50","$28","$5","$1395",
"03/03/2021","Buy","FOO","FOO INC","50","$27","$5","-$1355",
"03/03/2021","Sell","FOO","FOO INC","100","$26","$5","$2595",
"03/02/2021","Buy","FOO","FOO INC","100","$25","$6","-$2506",
"03/01/2016","MoneyLink Transfer","","Tfr BANK","","","","$10000.00",
"Date","Action","Symbol","Description","Quantity","Price","Fees & Comm","Amount"
"04/02/2021","Buy","FOO","FOO INC","30.5","$30.2","$4","-$925.1"
"03/06/2021","Sell","FOO","FOO INC","90","$33","$5","$2965"
"03/06/2021","Buy","FOO","FOO INC","90","$32","$5","-$2885"
"03/03/2021","Sell","FOO","FOO INC","104","$31","$5","$3219"
"03/03/2021","Buy","FOO","FOO INC","4","$30","$0","-$120"
"03/03/2021","Buy","FOO","FOO INC","100","$29","$5","-$2905"
"03/03/2021","Sell","FOO","FOO INC","50","$28","$5","$1395"
"03/03/2021","Buy","FOO","FOO INC","50","$27","$5","-$1355"
"03/03/2021","Sell","FOO","FOO INC","100","$26","$5","$2595"
"03/02/2021","Buy","FOO","FOO INC","100","$25","$6","-$2506"
"03/01/2016","MoneyLink Transfer","","Tfr BANK","","","","$10000.00"
Transactions Total,"","","","","","",

0 comments on commit 5c18196

Please sign in to comment.