Skip to content

Commit

Permalink
- Fix to revolut computation of profit and losses (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
jczaja authored Aug 14, 2024
1 parent 60d18f6 commit 4abcce9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
5 changes: 0 additions & 5 deletions src/csvparser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ fn extract_cash_with_currency(cashline: &str, currency: &str) -> Result<crate::C
log::info!("Entry cacheline: {cashline}");
log::info!("Entry currency: {currency}");

println!("Entry cacheline: {cashline}");
println!("Entry currency: {currency}");

let cashline_string: String = cashline.to_string().replace(",", "");
let mut pln_parser = tuple((double::<&str, Error<_>>, take(1usize), tag("PLN")));
let mut usd_parser = tuple((tag("$"), double::<&str, Error<_>>));
Expand Down Expand Up @@ -346,8 +343,6 @@ pub fn parse_revolut_transactions(
log::info!("Content of first to be DataFrame: {sales}");
log::info!("Content of second to be DataFrame: {others}");

println!("Content of second to be DataFrame: {others}");

let filtred_df = extract_dividends_transactions(&others)?;
log::info!("Filtered Data of interest: {filtred_df}");
dates = parse_investment_transaction_dates(&filtred_df)?;
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,10 @@ pub fn run_taxation(
let (gross_interests, _) = compute_div_taxation(&interests);
let (gross_div, tax_div) = compute_div_taxation(&transactions);
let (gross_sold, cost_sold) = compute_sold_taxation(&sold_transactions);
let (gross_revolut, _) = compute_div_taxation(&revolut_transactions);
let (gross_revolut, tax_revolut) = compute_div_taxation(&revolut_transactions);
Ok((
gross_interests + gross_div + gross_revolut,
tax_div,
tax_div + tax_revolut,
gross_sold, // We put sold and savings income into the same column
cost_sold,
interests,
Expand Down
27 changes: 27 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,33 @@ mod tests {
}
}

#[test]
fn test_revolut_dividends_pln() -> Result<(), clap::Error> {
// Get all brokerage with dividends only
let myapp = App::new("E-trade tax helper").setting(AppSettings::ArgRequiredElseHelp);
let rd: Box<dyn etradeTaxReturnHelper::Residency> = Box::new(pl::PL {});

let matches = create_cmd_line_pattern(myapp).get_matches_from_safe(vec![
"mytest",
"revolut_data/trading-pnl-statement_2024-01-01_2024-08-04_pl-pl_8e8783.csv",
])?;
let pdfnames = matches
.values_of("financial documents")
.expect_and_log("error getting brokarage statements pdfs names");
let pdfnames: Vec<String> = pdfnames.map(|x| x.to_string()).collect();

match etradeTaxReturnHelper::run_taxation(&rd, pdfnames) {
Ok((gross_div, tax_div, gross_sold, cost_sold, _, _, _, _)) => {
assert_eq!(
(gross_div, tax_div, gross_sold, cost_sold),
(6331.29, 871.17993, 0.0, 0.0),
);
Ok(())
}
Err(x) => panic!("Error in taxation process"),
}
}

#[test]
fn test_revolut_interests_taxation_pln() -> Result<(), clap::Error> {
// Get all brokerage with dividends only
Expand Down

0 comments on commit 4abcce9

Please sign in to comment.