From af5bbd75669c52cf6ed9b60c135d6bfa2bef263c Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 8 Sep 2026 20:42:13 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20consolidar=20stock=20global=20en=20clien?= =?UTF-8?q?te=20si=20el=20API=20a=C3=BAn=20no=20agrupa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: alberto.martinez --- web-panel/pages/almacen.vue | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/web-panel/pages/almacen.vue b/web-panel/pages/almacen.vue index b3b8548..09f57fc 100644 --- a/web-panel/pages/almacen.vue +++ b/web-panel/pages/almacen.vue @@ -456,11 +456,30 @@ async function loadWarehouses() { })); } +function aggregateClient(rows: StockRow[]): StockRow[] { + const map = new Map(); + for (const row of rows) { + const id = Number(row.material_id); + if (!id) continue; + const cur = map.get(id); + if (!cur) { + map.set(id, { ...row, warehouse_id: undefined, warehouse_count: 1 }); + continue; + } + cur.qty_on_hand = Number(cur.qty_on_hand || 0) + Number(row.qty_on_hand || 0); + cur.stock_value = Number(cur.stock_value || 0) + Number(row.stock_value || 0); + cur.warehouse_count = Number(cur.warehouse_count || 1) + 1; + } + return [...map.values()]; +} + async function loadStock() { if (isGlobalView.value) { const r = await api<{ stock?: StockRow[]; consolidated?: StockRow[] }>("/v1/warehouses/stock/global"); - stockRows.value = withRowKeys(r.stock ?? [], "d"); - consolidated.value = withRowKeys(r.consolidated ?? [], "c"); + const detail = r.stock ?? []; + stockRows.value = withRowKeys(detail, "d"); + const cons = r.consolidated ?? []; + consolidated.value = withRowKeys(cons.length ? cons : aggregateClient(detail), "c"); return; } const id = selectedWarehouse.value?.id;