From 5c181963964745f24a35d7b1b124c2ef2b10f953 Mon Sep 17 00:00:00 2001 From: Ruslan Sayfutdinov Date: Sun, 22 Jan 2023 23:18:50 +0000 Subject: [PATCH] Support 8 columns in Schwab transactions CSV (#319) --- cgt_calc/parsers/schwab.py | 11 ++++++----- tests/test_data/schwab_transactions.csv | 24 ++++++++++++------------ 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/cgt_calc/parsers/schwab.py b/cgt_calc/parsers/schwab.py index 327405da..6a17ffe3 100644 --- a/cgt_calc/parsers/schwab.py +++ b/cgt_calc/parsers/schwab.py @@ -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]: @@ -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]: diff --git a/tests/test_data/schwab_transactions.csv b/tests/test_data/schwab_transactions.csv index e7351363..dc8af0b4 100644 --- a/tests/test_data/schwab_transactions.csv +++ b/tests/test_data/schwab_transactions.csv @@ -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,"","","","","","",