Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transaction type filter in paypal import #18

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/importers/paypal.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::str::FromStr;
use std::{collections::HashSet, str::FromStr};

use bigdecimal::{BigDecimal, Zero};
use chrono::NaiveDate;
Expand Down Expand Up @@ -40,6 +40,12 @@ impl HledgerImporter for PaypalPdfImporter {
None => return Err(ImportError::MissingConfig("paypal".to_string())),
};

let exclude_types = if let Some(exclude_types) = &paypal_config.exclude_types {
exclude_types.iter().collect()
} else {
HashSet::new()
};

let mut transactions = Vec::new();
let mut reader = csv::ReaderBuilder::new()
.delimiter(b'\t')
Expand All @@ -51,6 +57,11 @@ impl HledgerImporter for PaypalPdfImporter {

for record in reader.deserialize::<PayPalTransaction>() {
let record = record.map_err(|e| ImportError::InputParse(e.to_string()))?;

if exclude_types.contains(&record.transaction_type) {
continue;
}

let transaction = ConfiguredPaypalTransaction {
config: paypal_config,
transaction: &record,
Expand Down Expand Up @@ -102,6 +113,7 @@ pub struct PayPalConfig {
pub asset_account: String,
pub clearing_account: String,
pub empty_payee: String,
pub exclude_types: Option<Vec<String>>,
}

impl TryInto<Transaction> for ConfiguredPaypalTransaction<'_> {
Expand Down
Loading