Workflow
Sales Workflow (Previous Style)
Previous detailed sales-only workflow, focused on lifecycle events and system side effects.
Audience: Sales team, store supervisors, and finance operators.
Related Collections
Execution Steps
Step 1
Sale is saved
When the user creates or edits a sale in admin, the system initializes context flags to identify create or update operation.
Step 2
Sale number is generated
On create, the system auto-generates a unique sale number in SALE-XXXX format (unique per tenant).
Step 3
Stock is updated immediately after save
Create: each sold variant stock is reduced by quantity. Update: stock uses delta logic between old and new line items. Result is clamped to zero to avoid negative stock.
Step 4
Customer balance ledger is posted
Create: invoice event is posted in customerBalance and customer.currentBalance increases by total sale amount.
Step 5
Adjustments are handled on edits
If sale total changes on update, an invoice_update entry is posted by the difference and customer.currentBalance is adjusted by the same delta.
When Quantity Updates
- Quantity affects stock right after sale save (afterChange hook).
- Stock deduction uses variant-level quantity from saleItems.
- On update, only the net quantity delta is applied.
Important Behavior
- Stock and balance effects happen automatically without manual confirmation.
- Delivery status does not gate stock deduction for sales.
- Editing historical sales can change inventory and customer balances.