{
setEdit({
id: row.id,
- value: row.sku ?? "",
+ value: shownSku(row) ?? "",
error: null,
field: "sku",
});
@@ -329,8 +335,8 @@ export function ItemsTable({
/>
) : (
-
- {row.sku ?? "—"}
+
+ {shownSku(row) ?? "—"}
{showsAiFilledSku(row, row.ai_check) ? (
{
expect(byId.get("oi-3")).toMatchObject({ in_pos: false, pos_stock_item_id: null });
});
+ it("carries a stock row's own SKU as line_sku (and leaves sku as before)", async () => {
+ const { admin } = makeAiAdmin({
+ stockItems: [
+ { id: "spi-1", description: "x", quantity: 2, quantity_received: 1, status: "collected", stock_item: "st-1", sku: "SM2NUT9B506" },
+ { id: "spi-2", description: "y", quantity: 2, quantity_received: 1, status: "collected", stock_item: "st-2", sku: "" },
+ ],
+ });
+ vi.mocked(getAdminPocketBase).mockResolvedValue(admin as never);
+
+ const rows = await listCollectedItems();
+ const byId = new Map(rows.map((r) => [r.id, r]));
+
+ expect(byId.get("spi-1")?.line_sku).toBe("SM2NUT9B506");
+ expect(byId.get("spi-2")?.line_sku).toBe("");
+ expect(byId.get("spi-1")?.sku).toBeUndefined();
+ });
+
it("marks stock rows in_pos with their catalogue item", async () => {
const { admin, posGetFullList } = makeAiAdmin({
stockItems: [
diff --git a/src/lib/server/collection-confirm-service.ts b/src/lib/server/collection-confirm-service.ts
index 7ab761d..7f8ce05 100644
--- a/src/lib/server/collection-confirm-service.ts
+++ b/src/lib/server/collection-confirm-service.ts
@@ -109,6 +109,12 @@ export type ConfirmRow = {
// collection-confirm page's supplier-SKU pencil and written via
// `updateStockPurchaseItem` (patchable whitelist member).
supplier_sku?: string;
+ /**
+ * Stock-only: the line's own `stock_purchase_items.sku` (what a rep or
+ * the AI fill writes). Shown, ticked and robot-marked in place of `sku`
+ * when present.
+ */
+ line_sku?: string;
supplier?: string;
poNumber?: string;
/** AI check of this line against the driver's invoice photo. */
@@ -339,6 +345,7 @@ export async function listCollectedItems(): Promise {
stockRows as unknown as Array<{
id: string;
stock_item: string;
+ sku?: string | null;
description: string;
quantity: number;
quantity_received: number;
@@ -369,6 +376,7 @@ export async function listCollectedItems(): Promise {
quantity: s.quantity,
item_status: s.status ?? undefined,
sku: s.expand?.stock_item?.sku,
+ line_sku: typeof s.sku === "string" ? s.sku.trim() : "",
supplier: s.expand?.purchase?.expand?.supplier?.id ?? undefined,
stock_line_status: s.status ?? null,
ai_check: (s as { ai_check?: CollectionAiCheck | null }).ai_check ?? null,