Skip to content

Commit

Permalink
Fix to parsing CSV statement with empty fields separated with separat…
Browse files Browse the repository at this point in the history
…ors(commas) (#138)

* UT for robo advisor crashing implemented

* - Fix to crashing scenario

* Bumped version to 0.7.1

* - clarification of warning message
  • Loading branch information
jczaja authored Jan 4, 2025
1 parent 28a9a29 commit 211b615
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "etradeTaxReturnHelper"
version = "0.7.0"
version = "0.7.1"
edition = "2021"
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)"
license = "BSD-3-Clause"
Expand Down
14 changes: 14 additions & 0 deletions revolut_data/trading-pnl-statement_2024-01-robo-2.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Income from Sells,,,,,,,,,,
Date acquired,Date sold,Symbol,Security name,ISIN,Country,Quantity,Cost basis,Gross proceeds,Gross PnL,Currency
,,,,,,,,,,
Other income & fees,,,,,,,,,,
Date,Symbol,Security name,ISIN,Country,Gross amount,Withholding tax,Net Amount,Currency,,
2024-06-04,QDVY,iShares Floating Rate Bond ETF (Dist),IE00BZ048462,IE,2.8,0.68 PLN,2.12 PLN,PLN,,
2024-06-20,EXI2,iShares Dow Jones Global Titans 50 ETF (Dist),DE0006289382,DE,0.34,0.08 PLN,0.26 PLN,PLN,,
2024-06-28,IS3K,iShares Short Duration High Yield Corporate Bond ETF (Dist),IE00BCRY6003,IE,3.79,0.94 PLN,2.85 PLN,PLN,,
2024-07-01,IBCD,iShares Corporate Bond ETF (Dist),IE0032895942,IE,1.07,0.25 PLN,0.82 PLN,PLN,,
2024-09-27,IBCD,iShares Corporate Bond ETF (Dist),IE0032895942,IE,1.02,0.25 PLN,0.77 PLN,PLN,,
2024-09-27,IUSU,iShares USD Treasury Bond 1-3yr ETF (Dist),IE00B14X4S71,IE,1.71,0.42 PLN,1.29 PLN,PLN,,
2024-11-29,QDVY,iShares Floating Rate Bond ETF (Dist),IE00BZ048462,IE,2.92,0.73 PLN,2.19 PLN,PLN,,
2024-12-17,EXI2,iShares Dow Jones Global Titans 50 ETF (Dist),DE0006289382,DE,0.04,0 PLN,0.04 PLN,PLN,,
2024-12-31,IBCD,iShares Corporate Bond ETF (Dist),IE0032895942,IE,1.07,0.25 PLN,0.82 PLN,PLN,,
62 changes: 62 additions & 0 deletions src/csvparser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ pub fn parse_revolut_transactions(
.map_err(|e| format!("Error reading CSV: {e}"))?;

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

Expand Down Expand Up @@ -1540,6 +1541,67 @@ mod tests {
Ok(())
}

#[test]
fn test_parse_revolut_investment_with_commas_gain_and_losses_dividends() -> Result<(), String> {
let expected_result = Ok((
vec![
(
"06/04/24".to_owned(),
crate::Currency::PLN(2.80),
crate::Currency::PLN(0.68),
),
(
"06/20/24".to_owned(),
crate::Currency::PLN(0.34),
crate::Currency::PLN(0.08),
),
(
"06/28/24".to_owned(),
crate::Currency::PLN(3.79),
crate::Currency::PLN(0.94),
),
(
"07/01/24".to_owned(),
crate::Currency::PLN(1.07),
crate::Currency::PLN(0.25),
),
(
"09/27/24".to_owned(),
crate::Currency::PLN(1.02),
crate::Currency::PLN(0.25),
),
(
"09/27/24".to_owned(),
crate::Currency::PLN(1.71),
crate::Currency::PLN(0.42),
),
(
"11/29/24".to_owned(),
crate::Currency::PLN(2.92),
crate::Currency::PLN(0.73),
),
(
"12/17/24".to_owned(),
crate::Currency::PLN(0.04),
crate::Currency::PLN(0.0),
),
(
"12/31/24".to_owned(),
crate::Currency::PLN(1.07),
crate::Currency::PLN(0.25),
),
],
vec![],
));

assert_eq!(
parse_revolut_transactions("revolut_data/trading-pnl-statement_2024-01-robo-2.csv"),
expected_result
);

Ok(())
}

#[test]
fn test_parse_revolut_investment_gain_and_losses_sells_and_dividends() -> Result<(), String> {
let expected_result = Ok((
Expand Down
26 changes: 25 additions & 1 deletion src/pdfparser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1222,9 +1222,12 @@ mod tests {
#[ignore]
fn test_combined_account_statement() -> Result<(), String> {
assert_eq!(
parse_statement("etrade_data_2024/ClientStatements_110324.pdf"),
parse_statement("etrade_data_2024/ClientStatements_010325.pdf"),
(Ok((
vec![
("12/2/24".to_owned(), 4.88),
("10/1/24".to_owned(), 24.91),
("11/1/24".to_owned(), 25.09),
("9/3/24".to_owned(), 23.65), // Interest rates
("8/1/24".to_owned(), 4.34),
("7/1/24".to_owned(), 3.72),
Expand All @@ -1238,6 +1241,27 @@ mod tests {
("3/1/24".to_owned(), 380.25, 57.04)
],
vec![
(
"12/4/24".to_owned(),
"12/5/24".to_owned(),
30.0,
22.5,
674.98
),
(
"12/5/24".to_owned(),
"12/6/24".to_owned(),
55.0,
21.96,
1207.76
),
(
"11/1/24".to_owned(),
"11/4/24".to_owned(),
15.0,
23.32,
349.79
),
(
"9/3/24".to_owned(),
"9/4/24".to_owned(),
Expand Down
4 changes: 2 additions & 2 deletions src/pl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ impl etradeTaxReturnHelper::Residency for PL {
cost_sold
));
if tax_div > tax_pl {
(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")))
(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%)")))
} else {
(presentation, None)
}
Expand Down Expand Up @@ -362,7 +362,7 @@ mod tests {
.zip(&ref_results)
.for_each(|(a, b)| assert_eq!(a, b));

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();
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();

match warning {
Some(msg) => assert_eq!(msg, ref_msg),
Expand Down

0 comments on commit 211b615

Please # to comment.