diff --git a/src/routes/settings.import.tsx b/src/routes/settings.import.tsx index f1e3e47..224ab6e 100644 --- a/src/routes/settings.import.tsx +++ b/src/routes/settings.import.tsx @@ -1372,6 +1372,16 @@ function ImportPage() { } } + // Inserts must have a non-null client_id; fall back to placeholder + // ONLY for genuinely new invoices that never matched anything. + let placeholderClient: string | null = null; + const insertsNeedingClient = toInsertInv.filter((r) => !r.client_id); + if (insertsNeedingClient.length > 0) { + placeholderClient = await ensureArchivedClient("Imported (no client)", "imported-no-client"); + if (placeholderClient) { + for (const r of insertsNeedingClient) r.client_id = placeholderClient; + } + } for (let k = 0; k < toInsertInv.length; k += chunkSize) { const slice = toInsertInv.slice(k, k + chunkSize); const { data, error } = await supabase.from("invoices").insert(slice as any).select("*");