Skip to content

Commit 211b615

Browse files
authored
Fix to parsing CSV statement with empty fields separated with separators(commas) (#138)
* UT for robo advisor crashing implemented * - Fix to crashing scenario * Bumped version to 0.7.1 * - clarification of warning message
1 parent 28a9a29 commit 211b615

File tree

6 files changed

+106
-6
lines changed

6 files changed

+106
-6
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "etradeTaxReturnHelper"
3-
version = "0.7.0"
3+
version = "0.7.1"
44
edition = "2021"
55
description = "Parses etrade and revolut financial documents for transaction details (income, tax paid, cost basis) and compute total income and total tax paid according to chosen tax residency (currency)"
66
license = "BSD-3-Clause"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Income from Sells,,,,,,,,,,
2+
Date acquired,Date sold,Symbol,Security name,ISIN,Country,Quantity,Cost basis,Gross proceeds,Gross PnL,Currency
3+
,,,,,,,,,,
4+
Other income & fees,,,,,,,,,,
5+
Date,Symbol,Security name,ISIN,Country,Gross amount,Withholding tax,Net Amount,Currency,,
6+
2024-06-04,QDVY,iShares Floating Rate Bond ETF (Dist),IE00BZ048462,IE,2.8,0.68 PLN,2.12 PLN,PLN,,
7+
2024-06-20,EXI2,iShares Dow Jones Global Titans 50 ETF (Dist),DE0006289382,DE,0.34,0.08 PLN,0.26 PLN,PLN,,
8+
2024-06-28,IS3K,iShares Short Duration High Yield Corporate Bond ETF (Dist),IE00BCRY6003,IE,3.79,0.94 PLN,2.85 PLN,PLN,,
9+
2024-07-01,IBCD,iShares Corporate Bond ETF (Dist),IE0032895942,IE,1.07,0.25 PLN,0.82 PLN,PLN,,
10+
2024-09-27,IBCD,iShares Corporate Bond ETF (Dist),IE0032895942,IE,1.02,0.25 PLN,0.77 PLN,PLN,,
11+
2024-09-27,IUSU,iShares USD Treasury Bond 1-3yr ETF (Dist),IE00B14X4S71,IE,1.71,0.42 PLN,1.29 PLN,PLN,,
12+
2024-11-29,QDVY,iShares Floating Rate Bond ETF (Dist),IE00BZ048462,IE,2.92,0.73 PLN,2.19 PLN,PLN,,
13+
2024-12-17,EXI2,iShares Dow Jones Global Titans 50 ETF (Dist),DE0006289382,DE,0.04,0 PLN,0.04 PLN,PLN,,
14+
2024-12-31,IBCD,iShares Corporate Bond ETF (Dist),IE0032895942,IE,1.07,0.25 PLN,0.82 PLN,PLN,,

src/csvparser.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ pub fn parse_revolut_transactions(
359359
.map_err(|e| format!("Error reading CSV: {e}"))?;
360360

361361
let others = CsvReader::new(std::io::Cursor::new(content2.as_bytes()))
362+
.truncate_ragged_lines(true)
362363
.finish()
363364
.map_err(|e| format!("Error reading CSV: {e}"))?;
364365

@@ -1540,6 +1541,67 @@ mod tests {
15401541
Ok(())
15411542
}
15421543

1544+
#[test]
1545+
fn test_parse_revolut_investment_with_commas_gain_and_losses_dividends() -> Result<(), String> {
1546+
let expected_result = Ok((
1547+
vec![
1548+
(
1549+
"06/04/24".to_owned(),
1550+
crate::Currency::PLN(2.80),
1551+
crate::Currency::PLN(0.68),
1552+
),
1553+
(
1554+
"06/20/24".to_owned(),
1555+
crate::Currency::PLN(0.34),
1556+
crate::Currency::PLN(0.08),
1557+
),
1558+
(
1559+
"06/28/24".to_owned(),
1560+
crate::Currency::PLN(3.79),
1561+
crate::Currency::PLN(0.94),
1562+
),
1563+
(
1564+
"07/01/24".to_owned(),
1565+
crate::Currency::PLN(1.07),
1566+
crate::Currency::PLN(0.25),
1567+
),
1568+
(
1569+
"09/27/24".to_owned(),
1570+
crate::Currency::PLN(1.02),
1571+
crate::Currency::PLN(0.25),
1572+
),
1573+
(
1574+
"09/27/24".to_owned(),
1575+
crate::Currency::PLN(1.71),
1576+
crate::Currency::PLN(0.42),
1577+
),
1578+
(
1579+
"11/29/24".to_owned(),
1580+
crate::Currency::PLN(2.92),
1581+
crate::Currency::PLN(0.73),
1582+
),
1583+
(
1584+
"12/17/24".to_owned(),
1585+
crate::Currency::PLN(0.04),
1586+
crate::Currency::PLN(0.0),
1587+
),
1588+
(
1589+
"12/31/24".to_owned(),
1590+
crate::Currency::PLN(1.07),
1591+
crate::Currency::PLN(0.25),
1592+
),
1593+
],
1594+
vec![],
1595+
));
1596+
1597+
assert_eq!(
1598+
parse_revolut_transactions("revolut_data/trading-pnl-statement_2024-01-robo-2.csv"),
1599+
expected_result
1600+
);
1601+
1602+
Ok(())
1603+
}
1604+
15431605
#[test]
15441606
fn test_parse_revolut_investment_gain_and_losses_sells_and_dividends() -> Result<(), String> {
15451607
let expected_result = Ok((

src/pdfparser.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1222,9 +1222,12 @@ mod tests {
12221222
#[ignore]
12231223
fn test_combined_account_statement() -> Result<(), String> {
12241224
assert_eq!(
1225-
parse_statement("etrade_data_2024/ClientStatements_110324.pdf"),
1225+
parse_statement("etrade_data_2024/ClientStatements_010325.pdf"),
12261226
(Ok((
12271227
vec![
1228+
("12/2/24".to_owned(), 4.88),
1229+
("10/1/24".to_owned(), 24.91),
1230+
("11/1/24".to_owned(), 25.09),
12281231
("9/3/24".to_owned(), 23.65), // Interest rates
12291232
("8/1/24".to_owned(), 4.34),
12301233
("7/1/24".to_owned(), 3.72),
@@ -1238,6 +1241,27 @@ mod tests {
12381241
("3/1/24".to_owned(), 380.25, 57.04)
12391242
],
12401243
vec![
1244+
(
1245+
"12/4/24".to_owned(),
1246+
"12/5/24".to_owned(),
1247+
30.0,
1248+
22.5,
1249+
674.98
1250+
),
1251+
(
1252+
"12/5/24".to_owned(),
1253+
"12/6/24".to_owned(),
1254+
55.0,
1255+
21.96,
1256+
1207.76
1257+
),
1258+
(
1259+
"11/1/24".to_owned(),
1260+
"11/4/24".to_owned(),
1261+
15.0,
1262+
23.32,
1263+
349.79
1264+
),
12411265
(
12421266
"9/3/24".to_owned(),
12431267
"9/4/24".to_owned(),

src/pl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl etradeTaxReturnHelper::Residency for PL {
257257
cost_sold
258258
));
259259
if tax_div > tax_pl {
260-
(presentation,Some(format!("Warning: Tax paid in US({tax_div} PLN) is higher than the tax that you are to pay in Poland({tax_pl} PLN). This usually means that there was a problem with declaration of your residency to avoid double taxation")))
260+
(presentation,Some(format!("Warning: Tax paid in US({tax_div} PLN) is higher than the tax that you are to pay in Poland({tax_pl} PLN). This either means that there was a problem with declaration of your residency to avoid double taxation or you are having income from countries that are having higher tax at source than the one used in Poland(19%)")))
261261
} else {
262262
(presentation, None)
263263
}
@@ -362,7 +362,7 @@ mod tests {
362362
.zip(&ref_results)
363363
.for_each(|(a, b)| assert_eq!(a, b));
364364

365-
let ref_msg = "Warning: Tax paid in US(30 PLN) is higher than the tax that you are to pay in Poland(19 PLN). This usually means that there was a problem with declaration of your residency to avoid double taxation".to_string();
365+
let ref_msg = "Warning: Tax paid in US(30 PLN) is higher than the tax that you are to pay in Poland(19 PLN). This either means that there was a problem with declaration of your residency to avoid double taxation or you are having income from countries that are having higher tax at source than the one used in Poland(19%)".to_string();
366366

367367
match warning {
368368
Some(msg) => assert_eq!(msg, ref_msg),

0 commit comments

Comments
 (0)