diff --git a/web/src/pages/MinStock.jsx b/web/src/pages/MinStock.jsx index 12a0f9b..989b15d 100644 --- a/web/src/pages/MinStock.jsx +++ b/web/src/pages/MinStock.jsx @@ -93,10 +93,16 @@ export default function MinStock() { return out; }, [products, groups, locations]); - // Eine Lagerort-Bedarfsliste mit einem geänderten/entfernten Eintrag neu bauen. - const mergeLoc = (list, locId, num) => (list || []) - .map((e) => ({ location_id: e.location_id, min_stock: e.location_id === locId ? num : e.min_stock })) - .filter((e) => e.min_stock != null && e.min_stock > 0); + // Eine Lagerort-Bedarfsliste mit einem geänderten/neuen/entfernten Eintrag neu + // bauen. Der Endpunkt ersetzt die komplette Liste – neue Lagerorte müssen also + // ergänzt (nicht nur bestehende geändert) werden, sonst wird nie einer angelegt. + const mergeLoc = (list, locId, num) => { + const out = (list || []).map((e) => ({ location_id: e.location_id, min_stock: e.min_stock })); + const hit = out.find((e) => String(e.location_id) === String(locId)); + if (hit) hit.min_stock = num; + else out.push({ location_id: locId, min_stock: num }); + return out.filter((e) => e.min_stock != null && e.min_stock > 0); + }; async function saveSoll(row, value) { const roh = String(value).trim().replace(",", ".");