Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
fix: guard against infinite loops in reorder policies
Brad Barbin78cde0fc4419
diff --git a/apps/erp/app/modules/items/ui/Item/ItemReorderPolicy.tsx b/apps/erp/app/modules/items/ui/Item/ItemReorderPolicy.tsxindex befc7be4f1..3ca29bd5b7 100644--- a/apps/erp/app/modules/items/ui/Item/ItemReorderPolicy.tsx+++ b/apps/erp/app/modules/items/ui/Item/ItemReorderPolicy.tsx@@ -169,7 +169,8 @@ function calculateOrders({ itemPlanning, periods }: BaseOrderParams): {reorderPoint - (projectedQuantity + orderedQuantity);let day = 0;- while (remainingQuantityNeeded > 0 && day < 5) {+ let maxIterations = 100; // Safety counter to prevent infinite loops+ while (remainingQuantityNeeded > 0 && day < 5 && maxIterations-- > 0) {const dueDate = parseDate(period.startDate).add({ days: day });const startDate = dueDate.subtract({days: leadTime,@@ -201,7 +202,8 @@ function calculateOrders({ itemPlanning, periods }: BaseOrderParams): {reorderPoint - (projectedQuantity + orderedQuantity);let day = 0;- while (remainingQuantityNeeded > 0 && day < 5) {+ let maxIterations = 100; // Safety counter to prevent infinite loops+ while (remainingQuantityNeeded > 0 && day < 5 && maxIterations-- > 0) {const dueDate = parseDate(period.startDate).add({ days: day });const startDate = dueDate.subtract({days: leadTime,@@ -214,6 +216,11 @@ function calculateOrders({ itemPlanning, periods }: BaseOrderParams): {// Adjust quantity based on order constraintslet orderQuantity = Math.max(minimumOrderQuantity, requiredQuantity);+ // Ensure orderQuantity is positive to prevent infinite loop+ if (orderQuantity <= 0) {+ break;+ }+// Round to nearest multiple if specifiedif (orderMultiple && orderMultiple > 1) {orderQuantity =