How Product Creation Defaults and Validation Works
Source: products_controller.rb:16-19, product.rb:25-43, product.rb:246-255, product.rb:300-304
- New products default to quantity_on_hand = 0.0 if no quantity is supplied at creation
- The server always overrides the product ID to nil on create -- clients cannot specify their own product IDs
- Flat rate values can only be set on labor-type products; setting flat_rate on a stock product raises an error
- Item codes are auto-uppercased on every save via a before_save callback -- "oil-filter" becomes "OIL-FILTER"
- Vendor ID is silently nullified if set to an empty string, which can look like the vendor "disappeared"
- Cost, cost_including_tax, and retail_price default to $0.00 if left blank (zero_out_fields callback)
- Field length limits: item_code max 100 chars, description max 255, brand max 40, location max 10, searchable_tags max 255
- All price and cost fields must be numeric; non-numeric values fail validation
- Product type must match a system-defined ProductType code -- custom product types are not supported
- price_lookup defaults to false on new products, so new products do not appear in price lookup searches unless explicitly enabled
Support scenarios
- "Why does my new product show zero stock?" → No quantity was supplied at creation, so it defaulted to 0.0
- "My product item code changed to uppercase" → The system auto-uppercases all item codes on every save; this is by design
- "Vendor disappeared from my product" → Vendor ID was saved as an empty string, which the system converts to null
- "Cost shows $0.00 but I left it blank" → Blank cost fields are automatically set to zero, not left empty