Skip to content
English
  • There are no suggestions because the search field is empty.

How Customer Soft-Delete and Archiving Works

Source: `customers_controller.rb`, `customer.rb`

  • The default scope on Customer excludes both deleted (soft-deleted) and archived records from all queries, so normal searches never return them
  • The include_archived scope adds archived customers back into results but still hides deleted ones
  • Deleting a customer is a soft-delete: it sets deleted=true on the record rather than destroying it; reactivation reverses this flag using an unscoped query to find the record
  • Deletion is blocked if the customer has any associated vehicles, invoices, payments, inspections, events, or loan car bookings -- the user must remove or reassign these first
  • The internal (dealership) customer cannot be deleted under any circumstances; this is the system customer used for acquisitions and internal jobs
  • Archiving a customer cascades to ALL of that customer's vehicles, marking them archived too; however, unarchiving the customer does NOT automatically unarchive the vehicles -- each vehicle must be unarchived individually
  • Archiving is blocked if the customer has open invoices, outstanding payments, active inspections, upcoming events, or loan car bookings
  • There is no bulk unarchive for vehicles after a customer is unarchived; support must communicate this to the customer

Support scenarios

  • "I deleted a customer but they still show up in some reports" → The customer was likely archived, not deleted. Archived customers appear in queries using the include_archived scope. Check whether the customer is archived vs deleted.
  • "I can't delete this customer, it says they have records" → Deletion is blocked by linked vehicles, invoices, payments, inspections, events, or loan cars. The user must reassign or remove all linked records before the customer can be deleted.
  • "I archived a customer and now all their vehicles are gone" → Archiving cascades to all vehicles. The vehicles are archived, not deleted. They can be individually unarchived, but the customer must be unarchived first.
  • "I unarchived a customer but their vehicles are still missing" → Unarchiving a customer does not automatically unarchive their vehicles. Each vehicle must be unarchived separately.