Create from a quote (AI file)
Download new-customer-quote-conversion.llm.md
# OB_WORKFLOW: new_customer.quote_conversion
version: 0.3-draft (2026-10-11). product: OrangeBoard (OB) PSA, https://ob.standardcomputer.com
goal: sales-hunted prospect -> quote sent -> accepted -> manual Convert to client -> ticket/project.
actor: sales staff. Convert to client is sales-all or admin.
## MODEL
- One organizations table. CRM side = Stage {Prospect, MQL (Marketing Qualified Lead), Lead, Lost}; also Vendor, Former Client (not convertible). Clients side = Relationship {Onboarding, Managed Client}. "Client" = any customer organization. Customer vs pre-customer is computed isCustomer. There is no /customers noun and no /api/v1/customers route.
- Crossing pre-customer -> customer is the audited UI action "Convert to client" only (sales-all or admin). Server action convertToClientAction -> convertOrgToClient. Optional QBO, contract-from-deal, and onboarding-ticket steps run inside that action. Not undone by a stage edit; people/notes/deals stay on record. No REST endpoint. PATCH /api/v1/clients/{id} that would cross pre-customer -> customer returns 422: "This stage change would make a pre-customer org a client. Use Convert to client (CRM)…".
- Convert dialog "Convert \"{org}\" to client": checkboxes "Create/link QBO customer" and "Open onboarding ticket" (both on by default). Admin defaults: /settings/crm "Conversion defaults" (QBO create/link, contract from deal MRR/term/renewal, onboarding ticket + template default "Plain onboarding ticket", Landing stage: Auto (onboarding → customer) / Managed Client / Onboarding, notify on conversion).
- Non-convertible: Vendor ("Not a sales stage"), Archived, Former Client. "Needs cleanup" flagged orgs require explicit human acknowledgement.
- UI label "Practice name*" = organization name (literal label; applies to any business).
- Quote accept is intended NOT to convert. Public /quote/{token} and staff Record outcome share one handler. It writes the quote only: status SENT→ACCEPTED, acceptedAt, frozen acceptedSnapshot, journal events. It never touches the company's relationship or isCustomer, the linked deal, or the pipeline stage. A lead that accepts stays a Lead until Convert to client. "Create ticket from this quote" is a separate staff-confirmed action, not an accept side effect. No quotes scope and no quotes API.
- Until the Add-client stage fix ships: add the prospect with "+ New lead" or POST /api/v1/crm/leads. The "+ Add client" Lead/MQL/Prospect choices save a customer-side row and skip Convert.
- CRM module off: /crm pages and the CRM API are disabled (redirect to /console). This workflow needs CRM on to add and convert the prospect.
## API (confirmed 2026-10-11)
- base: https://ob.standardcomputer.com/api/v1. Header: Authorization: Bearer, plus the key. Key string starts with the prefix obk_. Shown once at creation (Admin → Integrations → API keys); stored hashed. Content-Type: application/json. Never print a real key.
- Write implies read within an area. 13 areas: tickets:read/write, clients:read/write (contacts ride on clients — no contacts scope), sites:read/write, devices:read/write, users:read (no users:write), mentions:read/write, webhooks:read/write, reports:read, projects:read/write, crm_leads:read/write (label "CRM: Leads (intake)"), crm_prospects:read/write, kb:read/write, kb_secrets:read. No quotes scope.
- Error body is {"error":"..."}: 400 malformed JSON or schema ("Invalid request: field: message"); 401 missing/invalid/revoked/expired key; 403 missing scope (names it); 422 business rule; 429 + Retry-After on rate-limited CRM keys; 503 API kill switch off, or CRM module/intake/researcher API off on CRM routes.
- Phone: omit or "" = no number; JSON null = 400.
- POST /api/v1/clients (clients:write): customer-side only. Required name. Optional phone, website, relationship, industry, notes, address_line_1, address_line_2, city, county, postcode, country, main_site_name. Use county, not state (state on this route is dropped silently). Pre-customer relationship is 422. 201 includes main_site_id and qbo_provisioning (create still succeeds if QBO fails). GET /clients, /contacts, and /sites return customer-side rows unless ?include_pre_customer=true is sent with crm_prospects:read (otherwise 403).
- POST /api/v1/crm/leads (crm_leads:write): required practice_name (alias name). Optional contact_name, contact_email, contact_phone, website, address_line_1, address_line_2, city, state, postcode, org_npi, notes, source, source_detail, research_notes, confidence 0–1, external_id, idempotency_key. No country. 201, or 200 created:false on idempotency replay. dedupe_state: clean | customer_match | precustomer_match | fuzzy. status: pending | promoting | approved | merged | rejected.
- POST /api/v1/sites (sites:write): required client_id, name. Sites use state (clients use county). 201 does not echo address. Unknown client → 422 {"error":"Unknown client."} (not 404). Pre-customer parent without crm_prospects:write → 422 (not 403).
- POST /api/v1/contacts (clients:write): required client_id, name. Optional site_id, email, phone, mobile, job_title, role, is_primary. Same 422 traps, plus 422 if the site is not under the client.
- Quote create, lines, send, publish, and accept: UI only.
## RULES
- Search /crm/orgs and /clients for duplicates before creating or converting. On possible match: stop, ask human.
- Never convert a Needs cleanup org without explicit human approval.
- Show the human every create/convert/send action before executing; conversions are not reversible by you.
- In UI dialogs, nothing happens until the submit button; if only observing, press Cancel.
- Never output client names, contacts, PHI, or API keys. Use fictional examples (Example Dental, front-desk@example.com).
- Report partial results verbatim: converted / skipped / failed / "converted but QBO errored — fix from the client page".
- After accept, the company is still a pre-customer. Do not tell the user the quote acceptance created a client, a deal stage change, a ticket, or a project.
- Leave Convert to client to a human in the UI.
## UI_STEPS
1. Company must exist first (quote picker cannot create one): /crm/orgs "+ New lead" (Practice name* and any contact details) -> "Add lead". Or POST /api/v1/crm/leads. Do not use "+ Add client" Lead/MQL/Prospect for this.
2. "New quote" (/quotes header or Quotes left rail -> /quotes/new; or /clients/{id} Quotes section "New quote" -> /quotes/new?clientId={id}). Form: CLIENT* ("Search clients…"; badges "pre-customer" / "customer" — prospects allowed), Title* ("Quote title"), START FROM: "Blank" (default sections from Admin → Quotes) | "A template" ("Pick a template…"; copies sections+lines at today's catalog prices; template never changed). "Create quote" enabled when CLIENT+Title set.
3. Editor /quotes/{id}: default sections (/settings/quotes). "Add line" -> "Add line from catalog" ("Search the catalog…", "Select →") -> "Add line — {item}": Quantity*, Unit price* (catalog default, editable), Billing checkbox Monthly recurring, Description, Notes, option chips -> "Add line". Line "Edit" -> "Save line"; "Remove". Sections up/down, Delete, "Add section". "Valid until" shown to customer; blocks Accept after it passes.
4. "Send to customer" -> "Send quote" dialog (To, Cc, Subject, preview). Templates: /settings/quotes "Quote email". One permanent customer link. Sending requires human approval.
5. Post-send edits go live via "Publish changes". Sending never publishes; publishing never sends.
6. Acceptance: customer accepts on /quote/{token} -> "Customer accepted vN"; or staff "Record outcome" (Accepted/Declined). Same handler. Writes quote only (SENT→ACCEPTED, acceptedAt, frozen acceptedSnapshot, journal events). Accepted = frozen contract of record ("Duplicate it to quote something different."). Company relationship, isCustomer, linked deal, and pipeline stage unchanged.
7. Human converts: prospect record "CRM →" or /crm/orgs Pre-customer view -> "Convert to client" (or "Convert selected…"). UI only.
8. Accepted quote: "Create ticket from this quote" -> "Create as: Ticket / Project" -> "Create". Nothing is created until Create. This is not an accept side effect. The new ticket links back to the quote.
## API_STEPS
- Add the prospect with POST /api/v1/crm/leads (crm_leads:write) before anyone can quote them via the API of record — there is no quotes API, so the quote itself stays in the UI.
- No quotes scope. Do not invent quote create/send/accept endpoints.
- Do not PATCH the org to a customer relationship after accept. That returns 422. Convert is UI-only.
- After a human has converted, a follow-up ticket may use POST /api/v1/tickets (tickets:write; required summary and client_id). That is separate from "Create ticket from this quote", which remains the staff-confirmed UI handoff.