Fixed mvmt.proceeds and mvmt.get_expense() for margin loss txns to report at 0.00. Hopefully made add_proceeds_to_mvmts() faster.
This commit is contained in:
parent
29a84d617e
commit
30c22c05d1
|
@ -291,8 +291,19 @@ impl Movement {
|
|||
let ar = ar_map.get(&self.action_record_key).unwrap();
|
||||
|
||||
if ar.direction() == Polarity::Outgoing {
|
||||
|
||||
let acct = acct_map.get(&ar.account_key).unwrap();
|
||||
let raw_acct = raw_accts.get(&acct.raw_key).unwrap();
|
||||
|
||||
if !raw_acct.is_margin {
|
||||
|
||||
Ok(d128!(0))
|
||||
|
||||
} else {
|
||||
|
||||
let expense = -self.proceeds_lk.get();
|
||||
Ok(expense)
|
||||
}
|
||||
}
|
||||
else { Ok(d128!(0)) }
|
||||
}
|
||||
|
|
|
@ -197,8 +197,12 @@ pub(crate) fn add_proceeds_to_movements(
|
|||
for ar_num in txn.action_record_idx_vec.iter() {
|
||||
|
||||
let ar = ars.get(ar_num).unwrap();
|
||||
let acct = acct_map.get(&ar.account_key).unwrap();
|
||||
let raw_acct = raw_acct_map.get(&acct.raw_key).unwrap();
|
||||
let movements = ar.get_mvmts_in_ar_in_date_order(acct_map, txns_map);
|
||||
|
||||
if !raw_acct.is_margin {
|
||||
|
||||
for mvmt in movements.iter() {
|
||||
|
||||
let polarity = ar.direction();
|
||||
|
@ -214,12 +218,19 @@ pub(crate) fn add_proceeds_to_movements(
|
|||
|
||||
Polarity::Outgoing => {
|
||||
|
||||
if (tx_type == TxType::Flow) && (txn.action_record_idx_vec.len() == 2) {
|
||||
|
||||
// Keep at 0.00 proceeds for margin loss
|
||||
continue
|
||||
}
|
||||
|
||||
let ratio = borrowed_mvmt.amount / ar.amount;
|
||||
let proceeds_unrounded = txn.proceeds.to_string().parse::<d128>().unwrap() * ratio;
|
||||
let proceeds_rounded = round_d128_1e2(&proceeds_unrounded);
|
||||
|
||||
mvmt.proceeds.set(proceeds_rounded);
|
||||
mvmt.proceeds_lk.set(proceeds_rounded);
|
||||
|
||||
}
|
||||
|
||||
Polarity::Incoming => {
|
||||
|
@ -241,6 +252,10 @@ pub(crate) fn add_proceeds_to_movements(
|
|||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Do nothing. Future changes can add a code path where margin txns "settle"
|
||||
// as they happen, though, if desired. Just need to write the code.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue