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.
This commit is contained in:
@@ -295,15 +295,22 @@ export const templateToIngredientCreate = (
|
|||||||
template: IngredientTemplate,
|
template: IngredientTemplate,
|
||||||
customName?: string
|
customName?: string
|
||||||
): Omit<IngredientCreate, 'tenant_id'> => {
|
): Omit<IngredientCreate, 'tenant_id'> => {
|
||||||
|
// 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 {
|
return {
|
||||||
name: customName || template.name,
|
name: customName || template.name,
|
||||||
category: template.category,
|
category: template.category,
|
||||||
unit_of_measure: template.unit_of_measure,
|
unit_of_measure: template.unit_of_measure,
|
||||||
description: template.description,
|
description: template.description,
|
||||||
standard_cost: template.estimatedCost,
|
standard_cost: template.estimatedCost,
|
||||||
low_stock_threshold: 10,
|
low_stock_threshold: lowStock,
|
||||||
reorder_point: 20,
|
max_stock_level: maxStock, // Added: prevents validation error
|
||||||
reorder_quantity: 50,
|
reorder_point: reorderPoint,
|
||||||
|
reorder_quantity: reorderQty,
|
||||||
is_perishable: [IngredientCategory.DAIRY, IngredientCategory.EGGS].includes(template.category),
|
is_perishable: [IngredientCategory.DAIRY, IngredientCategory.EGGS].includes(template.category),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user