Purchasing and suppliers¶
warehouse-service lets an admin buy stock from suppliers. Receiving goods
raises stock in warehouse-service's own stock ledger (it owns stock since 1.6.0);
the backend's copy catches up a few seconds later. UI page:
/admin/purchasing. All endpoints require ROLE_ADMIN.
Endpoints¶
| Method and path | Result |
|---|---|
GET / POST /api/v1/admin/suppliers |
List / create suppliers (name, email, lead time in days) |
GET /api/v1/admin/purchase-orders, GET .../{id} |
List / read |
POST /api/v1/admin/purchase-orders |
Create a DRAFT with lines (product snapshots) |
PUT /api/v1/admin/purchase-orders/{id} |
Replace lines; DRAFT only |
POST /api/v1/admin/purchase-orders/{id}/submit |
Needs at least one line; sets expectedAt = submittedAt + supplier lead time |
POST /api/v1/admin/purchase-orders/{id}/cancel |
DRAFT or SUBMITTED only |
POST /api/v1/admin/purchase-orders/{id}/receipts |
{requestId, lines:[{productId, quantity}]} |
GET /api/v1/admin/inventory/reorder-suggestions?lowStockThreshold=5 |
Products to reorder |
Purchase order lifecycle¶
stateDiagram-v2
[*] --> DRAFT
DRAFT --> SUBMITTED: submit
SUBMITTED --> PARTIALLY_RECEIVED: receive some
PARTIALLY_RECEIVED --> RECEIVED: receive rest
SUBMITTED --> RECEIVED: receive all
DRAFT --> CANCELLED: cancel
SUBMITTED --> CANCELLED: cancel
Receipts¶
- Only
SUBMITTEDandPARTIALLY_RECEIVEDorders accept receipts. - Receiving more than is outstanding for a line is
409. - A repeated
requestIdwith the same lines replays the previous result; the samerequestIdwith different lines is409. - Stock rises in warehouse-service's ledger with
PURCHASE_RECEIVEDmovements, in the same transaction as the receipt. The new level reaches the backend's stock copy through the stock-level outbox (POST /internal/v1/inventory/levels); a 0 → n change there triggers back-in-stock emails for wishlists.
sequenceDiagram
actor A as Admin
participant W as warehouse-service
participant B as Backend
A->>W: Receipt (requestId)
Note over W: Check quantities, add stock to the ledger
W-->>A: Updated order
W->>B: Push stock level (outbox, retried)
Reorder suggestions¶
For every product, projected = stock + incoming, where incoming is the
outstanding quantity on SUBMITTED and PARTIALLY_RECEIVED purchase orders.
A product is suggested when projected ≤ lowStockThreshold, with
sorted by projected quantity, then product id. lowStockThreshold defaults to
5 and must be at least 1.
Example
Threshold 5, stock 1, 2 units incoming → projected 3 ≤ 5 → suggest 4 × 5 − 3 = 17 units.
Demo suppliers (lightweight and full): Nordic Electronics ([email protected], 7 days) and Baltic Gadgets ([email protected], 14 days).