Fix case submenus are ignored.

- Append submenus to iterate list

Signed-off-by: Pakin <pakin.t@forth.co.th>
This commit is contained in:
Pakin 2025-10-28 12:53:54 +07:00
parent a15f0d42f9
commit 669f789903
2 changed files with 22 additions and 34 deletions

View file

@ -3,6 +3,7 @@ pub struct Headers {}
impl Headers { impl Headers {
// will be deprecated by next version // will be deprecated by next version
#[deprecated]
pub fn get_recipe_table_sgp_24022025() -> Vec<&'static str> { pub fn get_recipe_table_sgp_24022025() -> Vec<&'static str> {
[ [
"Name", "Name",
@ -128,6 +129,7 @@ impl Headers {
.to_vec() .to_vec()
} }
#[deprecated]
pub fn get_recipe_table_dubai_16052025() -> Vec<&'static str> { pub fn get_recipe_table_dubai_16052025() -> Vec<&'static str> {
[ [
"Name", "Name",

View file

@ -1,6 +1,7 @@
use std::str::FromStr; use std::str::FromStr;
use log::{debug, info}; use log::{debug, info};
use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator};
use serde_json::{Number, Value}; use serde_json::{Number, Value};
use super::common::*; use super::common::*;
@ -339,7 +340,7 @@ pub fn import_menu(main_version: usize, country_name: &str, into_version: usize)
} }
pub fn generate_recipe_sheet_table(country_name: &str, into_version: usize) { pub fn generate_recipe_sheet_table(country_name: &str, into_version: usize) {
let mut latest_recipe = let latest_recipe =
create_recipe_model_from_file(create_recipe_path(country_name, into_version)); create_recipe_model_from_file(create_recipe_path(country_name, into_version));
let mut recipe_table = Table::new(); let mut recipe_table = Table::new();
@ -400,7 +401,24 @@ pub fn generate_recipe_sheet_table(country_name: &str, into_version: usize) {
} }
} }
latest_recipe.clone().Recipe01.iter_mut().for_each(|rpl| { // FIX: case sub menu is ignored
let sub_menu_fetched: Vec<Vec<crate::models::recipe::Recipe01>> = latest_recipe
.Recipe01
.clone()
.par_iter_mut()
.filter_map(|x| {
if x.SubMenu.clone().is_some_and(|xs| !xs.is_empty()) {
Some(x.SubMenu.clone().unwrap())
} else {
None
}
})
.collect();
let mut submenus = sub_menu_fetched.concat();
let mut recipe_iter = latest_recipe.clone().Recipe01;
recipe_iter.append(&mut submenus);
recipe_iter.iter_mut().for_each(|rpl| {
let binding = rpl.clone(); let binding = rpl.clone();
let mat_list = binding let mat_list = binding
.recipes .recipes
@ -452,19 +470,6 @@ pub fn generate_recipe_sheet_table(country_name: &str, into_version: usize) {
.enumerate() .enumerate()
.for_each(|(header_idx, header)| { .for_each(|(header_idx, header)| {
if header_idx > 1 && header.eq(&current_material.to_string()) { if header_idx > 1 && header.eq(&current_material.to_string()) {
// search mat settings for further info
// if rpl.productCode.clone().ends_with("0090") {
// debug!(
// "MAT [{}]: {} --> {} = pow:{:?},sy:{:?}",
// rpl.productCode.clone(),
// header_idx,
// repl.materialPathId.clone(),
// repl.powderGram,
// repl.syrupGram
// );
// }
let mat_setting = latest_recipe let mat_setting = latest_recipe
.search_material_settings(current_material.to_string()); .search_material_settings(current_material.to_string());
@ -488,29 +493,10 @@ pub fn generate_recipe_sheet_table(country_name: &str, into_version: usize) {
} }
} }
recipe::MaterialType::Syrup => { recipe::MaterialType::Syrup => {
// debug
// if rpl.productCode.clone().ends_with("0090") {
// println!(
// "SYRUP [{}]: {} --> {} = {:?}",
// rpl.productCode.clone(),
// header_idx,
// repl.materialPathId.clone(),
// repl.syrupGram
// );
// }
recipe_brewing_values_only[header_idx] += recipe_brewing_values_only[header_idx] +=
repl.syrupGram.as_i64().unwrap(); repl.syrupGram.as_i64().unwrap();
} }
recipe::MaterialType::Soda => { recipe::MaterialType::Soda => {
// println!(
// "SODA [{}]: {} --> {} = {:?}",
// rpl.productCode.clone(),
// header_idx,
// repl.materialPathId.clone(),
// repl.syrupGram
// );
recipe_brewing_values_only[header_idx] += recipe_brewing_values_only[header_idx] +=
repl.syrupGram.as_i64().unwrap(); repl.syrupGram.as_i64().unwrap();
} }