FIx rule import for move money so it moves percentage amounts correctly

This commit is contained in:
Piv
2023-02-01 08:27:05 +10:30
parent 6f6084c605
commit 1168ca46db

View File

@@ -198,7 +198,12 @@ where
to_accounts, to_accounts,
all_from_accounts: false, all_from_accounts: false,
all_to_accounts: false, all_to_accounts: false,
amount: movement_rule.amount.unwrap_or(0.), amount: movement_rule.amount.unwrap_or(0.)
* (if movement_rule.is_percent == "%" {
0.01
} else {
1.
}),
is_percent: movement_rule.is_percent == "%", is_percent: movement_rule.is_percent == "%",
is_separator: movement_rule.apply == "-DIVIDER-", is_separator: movement_rule.apply == "-DIVIDER-",
}) })
@@ -265,6 +270,7 @@ pub fn move_money_1() {}
// Note that the movement happens on a line-by-line level. So we can stream the data from disk, and potentially apply this // Note that the movement happens on a line-by-line level. So we can stream the data from disk, and potentially apply this
// to every. It's also much more memory efficient than approach 1. // to every. It's also much more memory efficient than approach 1.
// TODO: Time both approaches to seee which is faster depending on the size of the input data/number of rules // TODO: Time both approaches to seee which is faster depending on the size of the input data/number of rules
// Verdict: This is already pretty fast, at least much faster than ppm for BigDataset
pub fn move_money_2( pub fn move_money_2(
initial_totals: HashMap<Unit, f64>, initial_totals: HashMap<Unit, f64>,
rules: &Vec<MovementRule>, rules: &Vec<MovementRule>,
@@ -321,7 +327,7 @@ mod tests {
csv::Reader::from_path("reclassrule.csv").unwrap(), csv::Reader::from_path("reclassrule.csv").unwrap(),
csv::Reader::from_path("line.csv").unwrap(), csv::Reader::from_path("line.csv").unwrap(),
csv::Writer::from_path("output.csv").unwrap(), csv::Writer::from_path("output.csv").unwrap(),
false, true,
); );
} }
} }