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.
This commit is contained in:
Dave 2026-08-17 08:27:36 +02:00
parent 9d80d52c17
commit d29b91c7c0
2 changed files with 23 additions and 3 deletions

View file

@ -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",
);

View file

@ -276,7 +276,20 @@ export async function listCollectedItems(): Promise<ConfirmRow[]> {
};
}
>({
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",
})