From d29b91c7c0c5ebdcf9d80f09a5678815c3ba10c1 Mon Sep 17 00:00:00 2001 From: Dave Date: Mon, 17 Aug 2026 08:27:36 +0200 Subject: [PATCH] feat(collection-confirm): update stock item filtering logic in listCollectedItems - Modified the filter criteria in the `listCollectedItems` function to exclude stock lines that have been fully received, ensuring only pending items are displayed. - Updated related tests to reflect the new filtering logic, enhancing clarity on the conditions under which stock items are included in the list. - Improved documentation comments to explain the filtering behavior and its implications for the stock confirmation process. --- src/lib/server/collection-confirm-service.test.ts | 11 +++++++++-- src/lib/server/collection-confirm-service.ts | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/lib/server/collection-confirm-service.test.ts b/src/lib/server/collection-confirm-service.test.ts index ea2a995..ecc4894 100644 --- a/src/lib/server/collection-confirm-service.test.ts +++ b/src/lib/server/collection-confirm-service.test.ts @@ -184,11 +184,18 @@ describe("listCollectedItems", () => { // Stock rows have no customer side. expect(row.expand?.order).toBeUndefined(); - // Stock leg filter must be the status-based variant (NOT item_status). + // Stock leg filter excludes lines the warehouse has already + // fully received (`quantity_received >= quantity`). The + // confirm-stock endpoint and the qty pencil both land the line + // at full received; the row should drop off the list either + // way. The status field stays at "collected" — only the + // accountant's booking flow flips it to "booked". expect(stockItemsGetFullList).toHaveBeenCalledTimes(1); const stockOpts = stockItemsGetFullList.mock.calls[0]?.[0] as { filter?: string; expand?: string } | undefined; - expect(stockOpts?.filter).toBe('status = "collected"'); + expect(stockOpts?.filter).toBe( + 'status = "collected" && quantity_received < quantity', + ); expect(stockOpts?.expand).toBe( "purchase.supplier,purchase.stock_item,purchase.additional_attachments", ); diff --git a/src/lib/server/collection-confirm-service.ts b/src/lib/server/collection-confirm-service.ts index bc81c46..e0d4960 100644 --- a/src/lib/server/collection-confirm-service.ts +++ b/src/lib/server/collection-confirm-service.ts @@ -276,7 +276,20 @@ export async function listCollectedItems(): Promise { }; } >({ - filter: 'status = "collected"', + // Filter: status is "collected" AND the warehouse hasn't + // fully received the line yet. The warehouse-side + // `confirmStockRows` call snaps `quantity_received` to + // `quantity`; the qty pencil (collection-confirm page) does + // the same when the operator manually snaps the qty to the + // full amount. Either path lands `quantity_received >= + // quantity` and the row drops off the list. Conversely, a + // line where `quantity_received` is below `quantity` is + // still pending the warehouse's action and stays on the + // page. The status field is deliberately left at + // "collected" — only the accountant's booking flow flips + // it to "booked" (and is gated on the warehouse's + // `confirmStockRows` having run first). + filter: 'status = "collected" && quantity_received < quantity', sort: "-created", expand: "purchase.supplier,purchase.stock_item,purchase.additional_attachments", })