How Vendor (Supplier) Invoices Work
Source: vendor_invoice.rb, vendor_invoices_controller.rb, vendor_invoice_items_controller.rb
- New vendor invoices start as Open status; total = subtotal + gst + freight + rounding (calculated only while open)
- Cannot create vendor invoices for biller vendors -- error directs users to create a non-biller version of the supplier
- Cannot edit processed/closed vendor invoices; cannot create/update/delete items on processed vendor invoices
- Duplicate vendor invoice numbers are blocked when Xero is connected (case-insensitive check using ILIKE)
- Deletion requires: open status, no Xero ID, and no serial numbers attached
- Cannot process without a vendor invoice number; serial numbers must match item quantities
- Average cost calculation on processing: if product cost type is "A" (average) and stock exists, weighted average is calculated; otherwise cost is simply replaced
- Quantity_on_hand increases for invoices, decreases for credits on processing
- Dealership acquisition vehicles are set to for_sale on processing; vendor credits with acquisition products soft-delete the corresponding vehicles
- Price_includes_tax toggle triggers a re-save of all line items to recalculate GST
- GST calculation depends on calculate_tax_on_subtotal setting: if enabled (or MYOB connected), GST is calculated from subtotals; otherwise summed from individual items
- Process and save are wrapped in a single database transaction -- both succeed or both fail
- The update_product flag on a vendor invoice item copies description and cost to the master Product record
Support scenarios
- "Why can't I create a supplier invoice for this vendor?" -> the vendor is flagged as a biller; create a non-biller version
- "Duplicate invoice number error" -> Xero requires unique invoice numbers per vendor; the check is case-insensitive (INV-001 and inv-001 are treated as duplicates)
- "My product cost changed after receiving a supplier invoice" -> if cost type is average, a weighted average is recalculated from existing stock + new line; otherwise the cost is replaced
- "Supplier invoice GST doesn't match line items" -> the calculate_tax_on_subtotal setting or MYOB connection changes how GST is computed (from subtotal vs from items)