diff --git a/src/move_money.rs b/src/move_money.rs index 06d9c4c..451320c 100644 --- a/src/move_money.rs +++ b/src/move_money.rs @@ -179,12 +179,6 @@ where .sorted() .collect() }; - let line_departments_sorted = lines - .keys() - .map(|key| key.department.clone()) - .unique() - .sorted() - .collect(); let all_departments_sorted = cost_centres_reader .deserialize::() .map(|cc| cc.unwrap().code) @@ -213,7 +207,6 @@ where extract_range( movement_rule.source_from_account, movement_rule.source_to_account, - false, &all_accounts_sorted, ) } @@ -235,7 +228,6 @@ where extract_range( movement_rule.dest_from_account, movement_rule.dest_to_account, - false, &all_accounts_sorted, ) } @@ -246,9 +238,7 @@ where extract_range( movement_rule.source_from_department, movement_rule.source_to_department, - false, - // Don't use all departments, as we only need ones that actually have costs - &line_departments_sorted, + &all_departments_sorted, ) }; let to_departments = if is_separator { @@ -257,19 +247,18 @@ where extract_range( movement_rule.dest_from_department, movement_rule.dest_to_department, - false, &all_departments_sorted, ) }; rules.push(MovementRule { + all_from_departments: from_departments.is_empty(), + all_to_departments: to_departments.is_empty(), from_departments, to_departments, - all_from_departments: false, - all_to_departments: false, + all_from_accounts: from_accounts.is_empty(), + all_to_accounts: to_accounts.is_empty(), from_accounts, to_accounts, - all_from_accounts: false, - all_to_accounts: false, amount: movement_rule.amount.unwrap_or(0.) * (if movement_rule.is_percent == "%" { 0.01 @@ -299,9 +288,9 @@ where Ok(()) } -fn extract_range(from: String, to: String, all: bool, options: &Vec) -> HashSet { - if all || (from.is_empty() && to.is_empty()) { - return options.clone().into_iter().collect(); +fn extract_range(from: String, to: String, options: &Vec) -> HashSet { + if from.is_empty() && to.is_empty() { + return HashSet::new(); } let start_index = options .iter()