Clarified user_memo. Created auto_memo impl for Transaction.

This commit is contained in:
scoobybejesus 2019-09-23 20:00:27 -04:00
parent 4bbab2b04e
commit 3485e26f3d
4 changed files with 65 additions and 8 deletions

View File

@ -268,7 +268,7 @@ pub fn _4_transaction_mvmt_detail_to_csv(
let date = txn.date.format("%Y/%m/%d").to_string();
let tx_number = txn.tx_number.to_string();
let tx_type = txn.transaction_type(&ars, &raw_acct_map, &acct_map)?;
let memo = txn.memo.to_string();
let memo = txn.user_memo.to_string();
let mut amount = d128!(0);
amount += mvmt.amount; // To prevent printing -5E+1 instead of 50, for example
let ticker = raw_acct.ticker.to_string();
@ -354,7 +354,7 @@ pub fn _5_transaction_mvmt_summaries_to_csv(
let txn_date_string = txn.date.format("%Y/%m/%d").to_string();
let tx_num_string = "Txn ".to_string() + &txn.tx_number.to_string();
let tx_type_string = txn.transaction_type(ars, &raw_acct_map, &acct_map)?.to_string();
let tx_memo_string = txn.memo.to_string();
let tx_memo_string = txn.user_memo.to_string();
let mut term_st: Option<Term> = None;
let mut term_lt: Option<Term> = None;
let mut ticker: Option<String> = None;
@ -508,7 +508,8 @@ pub fn _6_transaction_mvmt_detail_to_csv_w_orig(
"Date".to_string(),
"Txn#".to_string(),
"Type".to_string(),
"Memo".to_string(),
"User Memo".to_string(),
"Auto Memo".to_string(),
"Amount".to_string(),
"Ticker".to_string(),
"Term".to_string(),
@ -546,7 +547,8 @@ pub fn _6_transaction_mvmt_detail_to_csv_w_orig(
let date = txn.date.format("%Y/%m/%d").to_string();
let tx_number = txn.tx_number.to_string();
let tx_type = txn.transaction_type(&ars, &raw_acct_map, &acct_map)?;
let memo = txn.memo.to_string();
let user_memo = txn.user_memo.to_string();
let auto_memo = txn.get_auto_memo(ars, raw_acct_map,acct_map)?;
let mut amount = d128!(0);
amount += mvmt.amount; // To prevent printing -5E+1 instead of 50, for example
let ticker = raw_acct.ticker.to_string();
@ -574,7 +576,8 @@ pub fn _6_transaction_mvmt_detail_to_csv_w_orig(
row.push(date);
row.push("Txn ".to_string() + &tx_number);
row.push(tx_type.to_string());
row.push(memo);
row.push(user_memo);
row.push(auto_memo);
row.push(amount.to_string());
row.push(ticker);
row.push(term);

View File

@ -208,7 +208,7 @@ pub(crate) fn import_transactions(
tx_number: this_tx_number,
date_as_string: this_tx_date.to_string(),
date: tx_date,
memo: this_memo.to_string(),
user_memo: this_memo.to_string(),
proceeds: proceeds_parsed,
action_record_idx_vec: action_records_map_keys_vec,
};

View File

@ -19,7 +19,7 @@ pub struct Transaction {
pub tx_number: u32, // Does NOT start at zero. First txn is 1.
pub date_as_string: String,
pub date: NaiveDate,
pub memo: String,
pub user_memo: String,
pub proceeds: f32,
pub action_record_idx_vec: Vec<u32>,
}
@ -209,6 +209,60 @@ impl Transaction {
Ok(both_are_non_home_curr)
}
pub fn get_auto_memo(
&self,
ars: &HashMap<u32, ActionRecord>,
raw_accts: &HashMap<u16, RawAccount>,
acct_map: &HashMap<u16, Account>
) -> Result<String, Box<dyn Error>> {
let auto_memo = if self.action_record_idx_vec.len() == 2 {
let marginness = self.marginness(ars, raw_accts, acct_map);
if (marginness == TxHasMargin::NoARs) | (marginness == TxHasMargin::TwoARs) {
let og_amt = ars.get(&self.action_record_idx_vec[0]).unwrap().amount;
let og_acct_key = ars.get(&self.action_record_idx_vec[0]).unwrap().account_key;
let og_acct = acct_map.get(&og_acct_key).unwrap();
let og_raw_acct = raw_accts.get(&og_acct.raw_key).unwrap();
let og_ticker = &og_raw_acct.ticker;
let ic_amt = ars.get(&self.action_record_idx_vec[1]).unwrap().amount;
let ic_acct_key = ars.get(&self.action_record_idx_vec[1]).unwrap().account_key;
let ic_acct = acct_map.get(&ic_acct_key).unwrap();
let ic_raw_acct = raw_accts.get(&ic_acct.raw_key).unwrap();
let ic_ticker = &ic_raw_acct.ticker;
format!("Paid {} {} for {} {}", og_amt, og_ticker, ic_amt, ic_ticker)
} else {
format!("Margin profit or loss")
}
} else {
let amt = ars.get(&self.action_record_idx_vec[0]).unwrap().amount;
let acct_key = ars.get(&self.action_record_idx_vec[0]).unwrap().account_key;
let acct = acct_map.get(&acct_key).unwrap();
let raw_acct = raw_accts.get(&acct.raw_key).unwrap();
let ticker = &raw_acct.ticker;
if amt > d128!(0.0) {
format!("Received {} {}", amt, ticker)
} else {
format!("Spent {} {}", amt, ticker)
}
};
Ok(auto_memo)
}
}
#[derive(Clone, Debug)]

View File

@ -134,7 +134,7 @@ Enable like-kind treatment: {}",
mvmt.transaction_key,
tx_type,
mvmt.date_as_string,
txn.memo
txn.user_memo
);
writeln!(file, "{}", description_str)?;