Moved LK fn as Txn impl. Resolves #41.

This commit is contained in:
scoobybejesus 2019-09-21 21:25:55 -04:00
parent b5cc8a857b
commit b5633ccb56
2 changed files with 26 additions and 21 deletions

View File

@ -393,19 +393,13 @@ fn perform_likekind_treatment_on_txn(
let txn = txns_map.get(&txn_num).unwrap(); let txn = txns_map.get(&txn_num).unwrap();
let tx_type = txn.transaction_type(ars, raw_acct_map, acct_map)?; let tx_type = txn.transaction_type(ars, raw_acct_map, acct_map)?;
let home_currency = &settings.home_currency;
match tx_type { match tx_type {
TxType::Exchange => { TxType::Exchange => {
let og_ar = ars.get(&txn.action_record_idx_vec.first().unwrap()).unwrap(); if txn.both_exch_ars_are_non_home_curr(ars, raw_acct_map, acct_map, home_currency)? {
let ic_ar = ars.get(&txn.action_record_idx_vec.last().unwrap()).unwrap();
let og_acct = acct_map.get(&og_ar.account_key).unwrap();
let ic_acct = acct_map.get(&ic_ar.account_key).unwrap();
let raw_og_acct = raw_acct_map.get(&og_acct.raw_key).unwrap();
let raw_ic_acct = raw_acct_map.get(&ic_acct.raw_key).unwrap();
if _both_are_non_home_curr(raw_og_acct, raw_ic_acct, settings) {
let mut sum_of_outgoing_lk_cost_basis_in_ar = d128!(0); let mut sum_of_outgoing_lk_cost_basis_in_ar = d128!(0);
@ -487,18 +481,5 @@ fn perform_likekind_treatment_on_txn(
} }
} }
fn _both_are_non_home_curr(
raw_og_acct: &RawAccount,
raw_ic_acct: &RawAccount,
settings: &ImportProcessParameters
) -> bool {
let og_is_home_curr = raw_og_acct.is_home_currency(&settings.home_currency);
let ic_is_home_curr = raw_ic_acct.is_home_currency(&settings.home_currency);
let both_are_non_home_curr = !ic_is_home_curr && !og_is_home_curr;
both_are_non_home_curr
}
Ok(()) Ok(())
} }

View File

@ -185,6 +185,30 @@ impl Transaction {
} }
Ok(flow_or_outgoing_exchange_movements) Ok(flow_or_outgoing_exchange_movements)
} }
pub fn both_exch_ars_are_non_home_curr(
&self,
ars: &HashMap<u32, ActionRecord>,
raw_acct_map: &HashMap<u16, RawAccount>,
acct_map: &HashMap<u16, Account>,
home_currency: &String,
) -> Result<bool, Box<dyn Error>> {
assert_eq!(self.action_record_idx_vec.len(), (2 as usize));
let og_ar = ars.get(&self.action_record_idx_vec.first().unwrap()).unwrap();
let ic_ar = ars.get(&self.action_record_idx_vec.last().unwrap()).unwrap();
let og_acct = acct_map.get(&og_ar.account_key).unwrap();
let ic_acct = acct_map.get(&ic_ar.account_key).unwrap();
let raw_og_acct = raw_acct_map.get(&og_acct.raw_key).unwrap();
let raw_ic_acct = raw_acct_map.get(&ic_acct.raw_key).unwrap();
let og_is_home_curr = raw_og_acct.is_home_currency(&home_currency);
let ic_is_home_curr = raw_ic_acct.is_home_currency(&home_currency);
let both_are_non_home_curr = !ic_is_home_curr && !og_is_home_curr;
Ok(both_are_non_home_curr)
}
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]