Ledger-based stock
Current stock is the sum of StockMovement rows, each with a reason: goods received, dispatch, damaged, adjustment or opening balance. Product.quantity is only a cached total, and only one function, record_movement(), can change it.
Why: every change in stock can be traced back to a reason, and the cached total can always be checked against the ledger.
Reorder point with z-score safety stock
Safety stock comes from how much daily dispatches vary (their standard deviation), scaled by a z-score for the service level. Until a product has enough dispatch history, its manual threshold is used instead.
Why: products with unsteady demand get more buffer than steady ones, and it still works on day one.
Weighted quotation ranking
Each quotation is scored on price (50), delivery (25), payment terms (10) and supplier reliability (15). Reliability comes from past goods-receipt history, and the owner can pass different weights. Scores are calculated per request, not stored.
Why: the owner gets a clear suggested order but still makes the final choice.
Idempotent, server-verified orders
Accepting a quotation locks the RFQ row inside a database transaction. confirm_order() runs only after the server has verified the payment, using the advance amount stored in the database, and running it twice does no harm.
Why: a repeated webhook or a double click can't create a second order or confirm the wrong amount.