From 370a270b4cf021dd6cc8a4fc59aa719b644e0605 Mon Sep 17 00:00:00 2001 From: Dave Date: Sun, 30 Aug 2026 12:59:45 +0200 Subject: [PATCH] feat(orders): show a repeat-order pill when an order matches a delivery note MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Blue Truck pill on the orders list, distinct from the amber quote suggestion and the teal linked quote. Reads potential_delivery_note_number (denormalized, no expand needed) — the service writes the relation and the number in the same update call so the list query doesn't pay for a second expanded relation (see orders-service.ts:253 for why the codebase avoids that). Additive — an order can show both a quote pill and a delivery-note pill at once; they're independent facts (a repeat-order observation, not a provenance link). Added potential_delivery_note: string and potential_delivery_note_number: string to the Order interface in src/lib/types.ts so the page gets the new fields via full-record return from getOrdersDashboardData (no fields: projection in the list path). Co-Authored-By: Claude --- src/app/(app)/orders/page.tsx | 22 ++++++++++++++++++++++ src/lib/types.ts | 14 ++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/app/(app)/orders/page.tsx b/src/app/(app)/orders/page.tsx index 38d83f4..44b6fe0 100644 --- a/src/app/(app)/orders/page.tsx +++ b/src/app/(app)/orders/page.tsx @@ -733,6 +733,28 @@ function OrderCard({ Suggested )} + {/* Repeat-order pill — set by suggestDeliveryNoteForOrder + when this order's items exactly match a past + delivery note for the same company. Reads the + denormalized number field (no `expand` needed, see + orders-service.ts:253). Blue, distinct from the + quote pills' amber/teal — a different kind of fact + (a repeat-order observation, not a provenance link). */} + {order.potential_delivery_note_number && ( + + + {order.potential_delivery_note_number} + + )} {complete && } · diff --git a/src/lib/types.ts b/src/lib/types.ts index 495e249..c2639f3 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -655,6 +655,20 @@ export interface Order extends BaseRecord { quote_match_confidence: number; potential_quote: string; potential_quote_confidence: number; + /** + * Repeat-order detection — relation to a past delivery note whose + * items exactly matched this order's. Set by + * suggestDeliveryNoteForOrder at intake (see + * order-delivery-note-link-service.ts). Visibility only — a wrong + * flag costs nothing; the operator just ignores the pill. + */ + potential_delivery_note?: string; + /** Denormalized copy of the matched DN's delivery_note_number. + * Written alongside potential_delivery_note so the list pill can + * render the number without a second `expand` (see + * orders-service.ts:253). delivery_note_number is immutable once + * assigned, so copying carries no staleness risk. */ + potential_delivery_note_number?: string; is_repair_order: boolean; /** * Sales rep handling this order. Free-text — auto-populated from the