From b5633ccb56e015781ab308be7cb710c025ea0993 Mon Sep 17 00:00:00 2001 From: scoobybejesus Date: Sat, 21 Sep 2019 21:25:55 -0400 Subject: [PATCH] Moved LK fn as Txn impl. Resolves #41. --- src/import_cost_proceeds_etc.rs | 23 ++--------------------- src/transaction.rs | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/import_cost_proceeds_etc.rs b/src/import_cost_proceeds_etc.rs index 62e1f03..3558578 100644 --- a/src/import_cost_proceeds_etc.rs +++ b/src/import_cost_proceeds_etc.rs @@ -393,19 +393,13 @@ fn perform_likekind_treatment_on_txn( let txn = txns_map.get(&txn_num).unwrap(); let tx_type = txn.transaction_type(ars, raw_acct_map, acct_map)?; + let home_currency = &settings.home_currency; match tx_type { TxType::Exchange => { - let og_ar = ars.get(&txn.action_record_idx_vec.first().unwrap()).unwrap(); - 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) { + if txn.both_exch_ars_are_non_home_curr(ars, raw_acct_map, acct_map, home_currency)? { 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(()) } diff --git a/src/transaction.rs b/src/transaction.rs index eabf879..bc2f9c6 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -185,6 +185,30 @@ impl Transaction { } Ok(flow_or_outgoing_exchange_movements) } + + pub fn both_exch_ars_are_non_home_curr( + &self, + ars: &HashMap, + raw_acct_map: &HashMap, + acct_map: &HashMap, + home_currency: &String, + ) -> Result> { + + 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)]