How Invoice Creation Validation Works
Source: invoice.rb:954-993, invoices_controller.rb:2699-2746
- Invoice must have a valid, non-archived customer -- error "a valid customer must be selected for all invoices" if customer is missing, deleted, or archived
- Invoice cannot reference an archived vehicle -- error "Cannot create invoice for an archived vehicle"
- Cannot create invoices for biller-type customers -- billers are payment aggregators, not invoiceable entities
- If a discount value > 0 is set, a discount_type (percentage, currency, or invoice_line_items) must also be specified or save fails
- Tax group ID and tax group name must be provided as a matching pair -- one without the other triggers a validation error
- Tax group fields are silently cleared if the company does not have use_multi_tax enabled
- Cannot use line-item discount with multiple tax rates when discount_includes_tax is true -- error "Cannot calculate discount when line items have multiple tax rates"
- Products on each line item are validated: must exist, not be deleted, and not be inactive
Support scenarios
- "I can't save the invoice, it says I need a valid customer" -> customer was archived or deleted; un-archive them first
- "It won't let me set a discount" -> discount_type field is empty; select percentage or currency first
- "I get an error about multiple tax rates" -> discount_includes_tax is on and line items have mixed tax rates; switch to per-line-item discounting or use a single tax rate
- "The tax group keeps disappearing from my invoice" -> company does not have multi-tax enabled in settings