Skip to content

OUT-3512: add customerType to support dual QBO customers per company#213

Merged
SandipBajracharya merged 1 commit intomasterfrom
OUT-3512
Apr 6, 2026
Merged

OUT-3512: add customerType to support dual QBO customers per company#213
SandipBajracharya merged 1 commit intomasterfrom
OUT-3512

Conversation

@SandipBajracharya
Copy link
Copy Markdown
Collaborator

@SandipBajracharya SandipBajracharya commented Apr 6, 2026

Summary

  • Adds customer_type column ('client' | 'company', default 'client') to qb_customers with a composite unique index on (portal_id, client_company_id, customer_type) to allow both client-detail and company-detail QBO customers to coexist for the same company
  • Threads customerType through the customer lookup/create chain (getByClientCompanyId, getExistingCustomer, ensureCustomerExistsAndSyncToken, findOrCreateCustomer) so the correct record is matched based on the current useCompanyNameFlag setting
  • Adds a CompanyName guard when searching QBO by email/display name to prevent cross-company customer reuse when the same client exists in multiple companies

Test plan

  • Create invoice billed to company with useCompanyNameFlag = false → verify QBO customer created with client details (customerType = 'client')
  • Toggle useCompanyNameFlag = true, create invoice to same company → verify a new QBO customer created with company details (customerType = 'company')
  • Toggle flag back to false, create another invoice → verify it reuses the existing 'client' customer, not the 'company' one
  • Create invoice billed to a client directly → verify existing QBO customer is reused (no duplicate)
  • Same client in two companies (flag=false): bill company A then company B → verify separate QBO customers created
  • Invoice paid webhook still works correctly (uses FK, unaffected)
  • Run migration on staging and verify existing records default to 'client'

Testing criteria

https://www.loom.com/share/734c58fdf6a849e5b91089758f60e74e

🤖 Generated with Claude Code

…per company

When useCompanyNameFlag is toggled, the system now creates separate QBO
customers for client-detail and company-detail invoices instead of reusing
a single record. Also adds a CompanyName guard to prevent cross-company
customer reuse when the same client exists in multiple companies.

Changes:
- Add customer_type column (varchar, notNull, default 'client') to qb_customers
- Update unique index to composite (portalId, clientCompanyId, customerType)
- Thread customerType param through getByClientCompanyId, getExistingCustomer,
  ensureCustomerExistsAndSyncToken, and findOrCreateCustomer
- Add CompanyName to QBO customer queries and validate on match

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@linear
Copy link
Copy Markdown

linear bot commented Apr 6, 2026

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
quickbooks-sync Ready Ready Preview, Comment Apr 6, 2026 10:14am

Request Review

@SandipBajracharya SandipBajracharya changed the title fix(OUT-3512): add customerType to support dual QBO customers per company OUT-3512: add customerType to support dual QBO customers per company Apr 6, 2026
Copy link
Copy Markdown
Collaborator

@priosshrsth priosshrsth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@SandipBajracharya SandipBajracharya merged commit 6bbb83f into master Apr 6, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants