Handle foreign currency purchases in DKB importer
Dependencies
- [2]
7URE4HPLAdd an importer for DKB account statements
Change contents
- edit in importers/dkb/src/lib.rs at line 350
if let Some(info) = record.exchange_information {posting.set_price(info.exchange_rate);} - replacement in importers/dkb/src/lib.rs at line 355
.build_posting(opposite_account, |_posting| {});.build_posting(opposite_account, |posting| { - edit in importers/dkb/src/lib.rs at line 360
if let Some(info) = record.exchange_information {posting.set_amount(info.foreign_total);}}); - edit in importers/dkb/src/lib.rs at line 443
exchange_information: Option<CurrencyExchangeInformation>, - edit in importers/dkb/src/lib.rs at line 470
#[derive(Clone, Copy, Debug)]struct CurrencyExchangeInformation {exchange_rate: Amount,foreign_total: Amount,}impl CurrencyExchangeInformation {fn extract_from_description(description: &str) -> Result<Option<Self>, Error> {description.find("Original ").map(|index| {let (foreign_total, rest) = split_off_amount(&description[index + 9..])?; - edit in importers/dkb/src/lib.rs at line 484
let exchange_rate = if let Some(rest) = rest.strip_prefix("1 Euro=") {split_off_amount(rest)?.0} else if let Some(rest) = rest.strip_prefix("Kurs ") {let (amount, _rest) = rest.split_once(' ').unwrap_or((rest, ""));Amount::new(Decimal::from_str_exact(amount).map_err(|_| todo!())?,foreign_total.commodity,)} else {todo!("handle {rest:?}")};Ok(Self {exchange_rate,foreign_total,})}).transpose()}} - edit in importers/dkb/src/lib.rs at line 624
let exchange_information =CurrencyExchangeInformation::extract_from_description(description).map_err(Self::Error::custom)?; - edit in importers/dkb/src/lib.rs at line 634
exchange_information, - edit in importers/dkb/src/lib.rs at line 711
- edit in importers/dkb/src/lib.rs at line 714[2.15692]
fn split_off_amount(v: &str) -> Result<(Amount, &str), Error> {let index = v.find(' ').ok_or_else(|| todo!())?;let index = v[index + 1..].find(' ').map_or(v.len(), |new| new + index + 1);let (amount, rest) = v.split_at(index);let amount = parse_german_amount(amount)?;// Remove whitespace from the beginninglet rest = rest.trim_start();Ok((amount, rest))}