Fix all to single department range
This commit is contained in:
@@ -179,12 +179,6 @@ where
|
|||||||
.sorted()
|
.sorted()
|
||||||
.collect()
|
.collect()
|
||||||
};
|
};
|
||||||
let line_departments_sorted = lines
|
|
||||||
.keys()
|
|
||||||
.map(|key| key.department.clone())
|
|
||||||
.unique()
|
|
||||||
.sorted()
|
|
||||||
.collect();
|
|
||||||
let all_departments_sorted = cost_centres_reader
|
let all_departments_sorted = cost_centres_reader
|
||||||
.deserialize::<PartialCostCentre>()
|
.deserialize::<PartialCostCentre>()
|
||||||
.map(|cc| cc.unwrap().code)
|
.map(|cc| cc.unwrap().code)
|
||||||
@@ -213,7 +207,6 @@ where
|
|||||||
extract_range(
|
extract_range(
|
||||||
movement_rule.source_from_account,
|
movement_rule.source_from_account,
|
||||||
movement_rule.source_to_account,
|
movement_rule.source_to_account,
|
||||||
false,
|
|
||||||
&all_accounts_sorted,
|
&all_accounts_sorted,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -235,7 +228,6 @@ where
|
|||||||
extract_range(
|
extract_range(
|
||||||
movement_rule.dest_from_account,
|
movement_rule.dest_from_account,
|
||||||
movement_rule.dest_to_account,
|
movement_rule.dest_to_account,
|
||||||
false,
|
|
||||||
&all_accounts_sorted,
|
&all_accounts_sorted,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -246,9 +238,7 @@ where
|
|||||||
extract_range(
|
extract_range(
|
||||||
movement_rule.source_from_department,
|
movement_rule.source_from_department,
|
||||||
movement_rule.source_to_department,
|
movement_rule.source_to_department,
|
||||||
false,
|
&all_departments_sorted,
|
||||||
// Don't use all departments, as we only need ones that actually have costs
|
|
||||||
&line_departments_sorted,
|
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
let to_departments = if is_separator {
|
let to_departments = if is_separator {
|
||||||
@@ -257,19 +247,18 @@ where
|
|||||||
extract_range(
|
extract_range(
|
||||||
movement_rule.dest_from_department,
|
movement_rule.dest_from_department,
|
||||||
movement_rule.dest_to_department,
|
movement_rule.dest_to_department,
|
||||||
false,
|
|
||||||
&all_departments_sorted,
|
&all_departments_sorted,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
rules.push(MovementRule {
|
rules.push(MovementRule {
|
||||||
|
all_from_departments: from_departments.is_empty(),
|
||||||
|
all_to_departments: to_departments.is_empty(),
|
||||||
from_departments,
|
from_departments,
|
||||||
to_departments,
|
to_departments,
|
||||||
all_from_departments: false,
|
all_from_accounts: from_accounts.is_empty(),
|
||||||
all_to_departments: false,
|
all_to_accounts: to_accounts.is_empty(),
|
||||||
from_accounts,
|
from_accounts,
|
||||||
to_accounts,
|
to_accounts,
|
||||||
all_from_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 == "%" {
|
* (if movement_rule.is_percent == "%" {
|
||||||
0.01
|
0.01
|
||||||
@@ -299,9 +288,9 @@ where
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extract_range(from: String, to: String, all: bool, options: &Vec<String>) -> HashSet<String> {
|
fn extract_range(from: String, to: String, options: &Vec<String>) -> HashSet<String> {
|
||||||
if all || (from.is_empty() && to.is_empty()) {
|
if from.is_empty() && to.is_empty() {
|
||||||
return options.clone().into_iter().collect();
|
return HashSet::new();
|
||||||
}
|
}
|
||||||
let start_index = options
|
let start_index = options
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
Reference in New Issue
Block a user