diff --git a/src/app/(app)/stock-orders/[id]/page.test.tsx b/src/app/(app)/stock-orders/[id]/page.test.tsx index ce8c10d..c8d205e 100644 --- a/src/app/(app)/stock-orders/[id]/page.test.tsx +++ b/src/app/(app)/stock-orders/[id]/page.test.tsx @@ -264,7 +264,8 @@ describe(" — driver picker", () => { status: "collected", quantity_received: 5, }); - expect(byId.get("si-1")?.drv_collected_at).toMatch(/^\d{4}-\d{2}-\d{2}T/); + // No `drv_collected_at` field on stock_purchase_items — collection + // moment is captured by PB's `updated` timestamp on the line row. expect(byId.get("si-2")).toMatchObject({ status: "collected", quantity_received: 10, diff --git a/src/app/(app)/stock-orders/[id]/page.tsx b/src/app/(app)/stock-orders/[id]/page.tsx index 54834a8..91b3cb2 100644 --- a/src/app/(app)/stock-orders/[id]/page.tsx +++ b/src/app/(app)/stock-orders/[id]/page.tsx @@ -535,10 +535,16 @@ export default function StockOrderDetailPage({ // The header is still "sent" until the operator clicks // "Confirm collection" — that final step is the audit // stamp that the warehouse-side has accepted the goods. + // + // NOTE: we deliberately do NOT write `drv_collected_at` + // here — that field exists on `order_items` but NOT on + // `stock_purchase_items` (PB schema gap; tracked in + // FEATURE-REQUESTS). PB would 500 the request. The + // collection timestamp is captured by PB's `updated` on + // the line row. await pb.collection("stock_purchase_items").update(line.id, { status: "collected", quantity_received: Number(line.quantity ?? 0), - drv_collected_at: now, }); } else { // Real driver: just bind the line to the driver. The diff --git a/src/lib/server/stock-purchase-items-service.test.ts b/src/lib/server/stock-purchase-items-service.test.ts index 1aca73d..df032da 100644 --- a/src/lib/server/stock-purchase-items-service.test.ts +++ b/src/lib/server/stock-purchase-items-service.test.ts @@ -395,7 +395,9 @@ describe("markLineCollectedWithPb", () => { expect(result.item.quantity_received).toBe(10); expect(result.previous_quantity_received).toBe(0); expect(result.new_quantity_received).toBe(10); - expect(result.item.drv_collected_at).toMatch(/^\d{4}-\d{2}-\d{2}T/); + // The collection moment is captured by PB's `updated` timestamp + // on the line row (no dedicated `drv_collected_at` field on + // stock_purchase_items — see FEATURE-REQUESTS gap). }); it("accepts the collection_pool auto-collect path", async () => { diff --git a/src/lib/server/stock-purchase-items-service.ts b/src/lib/server/stock-purchase-items-service.ts index db2831a..1b641ee 100644 --- a/src/lib/server/stock-purchase-items-service.ts +++ b/src/lib/server/stock-purchase-items-service.ts @@ -151,7 +151,13 @@ export async function updateStockPurchaseItemWithPb( const previous: Partial = {}; for (const key of STOCK_PURCHASE_ITEM_PATCHABLE_FIELDS) { if (key in input.patch) { - (previous as Record)[key] = (before as Record)[key]; + // `StockPurchaseItem` has no string index signature, so the + // direct `as Record` cast is rejected (TS2352). + // Detour through `unknown` — same pattern as the stock-items + // service. + (previous as unknown as Record)[key] = ( + before as unknown as Record + )[key]; } } @@ -457,12 +463,16 @@ export async function markLineCollectedWithPb( } const new_quantity_received = previous_quantity_received + quantity_collected; - const now = new Date().toISOString(); + // Note: `drv_collected_at` (the moment the driver handed the goods + // to the warehouse) does NOT exist on the `stock_purchase_items` + // PB collection — only `drv_id` + `assigned_at`. We track the + // collection moment via the line's `status` flip to `collected` + // and PB's `updated` timestamp. Adding a dedicated date field is + // a PB-admin task (FEATURE-REQUESTS gap #drv_collected_at_field). const patch: Record = { status: "collected", quantity_received: new_quantity_received, - drv_collected_at: before.drv_collected_at ?? now, }; const updated = (await pb