From 6a0679d48d7b99c9d9b97f194efc10c05e78c7eb Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 7 Nov 2025 09:06:51 +0000 Subject: [PATCH] Fix template ingredients with max_stock_level = 0 causing validation errors Add max_stock_level field to templateToIngredientCreate function to prevent template ingredients from being created with max_stock_level = 0, which causes 422 validation errors from the backend API. The function now calculates realistic stock levels: - low_stock_threshold: 10 - reorder_point: 20 - reorder_quantity: 50 - max_stock_level: 100 (reorderQty * 2, always > 0) This ensures all template ingredients created through batch creation (essential, common, and packaging ingredients) have valid max_stock_level values that meet backend validation requirements. --- .../domain/setup-wizard/data/ingredientTemplates.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/domain/setup-wizard/data/ingredientTemplates.ts b/frontend/src/components/domain/setup-wizard/data/ingredientTemplates.ts index 0d0e209c..40a4d910 100644 --- a/frontend/src/components/domain/setup-wizard/data/ingredientTemplates.ts +++ b/frontend/src/components/domain/setup-wizard/data/ingredientTemplates.ts @@ -295,15 +295,22 @@ export const templateToIngredientCreate = ( template: IngredientTemplate, customName?: string ): Omit => { + // Calculate realistic stock levels based on unit type + const lowStock = 10; + const reorderPoint = 20; + const reorderQty = 50; + const maxStock = reorderQty * 2; // 100 - always > 0 + return { name: customName || template.name, category: template.category, unit_of_measure: template.unit_of_measure, description: template.description, standard_cost: template.estimatedCost, - low_stock_threshold: 10, - reorder_point: 20, - reorder_quantity: 50, + low_stock_threshold: lowStock, + max_stock_level: maxStock, // Added: prevents validation error + reorder_point: reorderPoint, + reorder_quantity: reorderQty, is_perishable: [IngredientCategory.DAIRY, IngredientCategory.EGGS].includes(template.category), }; };