mirror of
https://origin.cursor.com/mrdevmx/panels.git
synced 2026-10-09 10:43:18 +00:00
fix: consolidar stock global en cliente si el API aún no agrupa
Co-authored-by: alberto.martinez <alberto.martinez@mrdev.mx>
This commit is contained in:
parent
e528d217d3
commit
af5bbd7566
1 changed files with 21 additions and 2 deletions
|
|
@ -456,11 +456,30 @@ async function loadWarehouses() {
|
|||
}));
|
||||
}
|
||||
|
||||
function aggregateClient(rows: StockRow[]): StockRow[] {
|
||||
const map = new Map<number, StockRow>();
|
||||
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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue