From 66f23a34e9cbe9d542cc35b768a1d84acd51fd59 Mon Sep 17 00:00:00 2001 From: Dave Date: Wed, 28 Oct 2026 10:38:36 +0200 Subject: [PATCH] fix(orders): quote shortlist no longer requires the same customer contact The AI order assistant's shortlist filtered candidate quotes to the order's customer (or blank). A different contact at the same company is common, so the right quote was dropped and the AI was never asked (M24 nylock order 74288 vs Q202610684). The scorer still rewards a customer match. Co-Authored-By: Claude Sonnet 5.5 --- src/lib/server/order-quote-link-service.test.ts | 2 ++ src/lib/server/order-quote-link-service.ts | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib/server/order-quote-link-service.test.ts b/src/lib/server/order-quote-link-service.test.ts index 76de895..254658a 100644 --- a/src/lib/server/order-quote-link-service.test.ts +++ b/src/lib/server/order-quote-link-service.test.ts @@ -170,6 +170,8 @@ describe("suggestQuoteForOrder", () => { const opts = quotesGetList.mock.calls[0][2] as { filter: string; fields?: string }; expect(opts.filter).toContain('created >= "2026-05-31T10:00:00.000Z"'); expect(opts.filter).toContain('company = "co1"'); + // A different contact at the same company must still be a candidate. + expect(opts.filter).not.toContain("customer"); // `quotes` also carries email_body / ai_insights / migration_meta — // this query must not pull those to read five scalars. expect(opts.fields).toBe("id,quote_number,company,customer,created"); diff --git a/src/lib/server/order-quote-link-service.ts b/src/lib/server/order-quote-link-service.ts index e1a6bb8..1b7ce24 100644 --- a/src/lib/server/order-quote-link-service.ts +++ b/src/lib/server/order-quote-link-service.ts @@ -210,9 +210,9 @@ async function fuzzyPass( "is_template != true", ]; if (order.company) filters.push(`company = "${esc(order.company)}"`); - if (order.customer) { - filters.push(`(customer = "${esc(order.customer)}" || customer = "")`); - } + // No customer filter: one company has many contacts, and the person who + // asked for the quote is often not the person who placed the order + // (M24 nylock, 2026-10-28). The scorer still rewards a customer match. const candidates = await pb .collection(QUOTE_COLLECTION)