SRV-13 — Inventory module
Warehouses, stock levels, reservations and deductions by order status, automatic restock on cancellation and on return reception, movement ledger, thresholds and alerts, inventory sessions. Resellers only ever see availability.
| Field | Details |
|---|---|
| Task code | SRV-13 |
| Phase | P1 — V1 build & integration |
| Product scope | V1 |
| Status | Done (Sun 18 Oct 2026) |
| Start | Sun 18 Oct 2026 |
| Due | Sun 18 Oct 2026 |
| Responsible | Anis — Full-stack developer |
| Co-responsible | — |
| Effort | 1 person-day(s) planned · 5 from scratch · size S |
| Area · app | Server · server |
| Depends on | SRV-11 |
| Unblocks | SRV-15, DSH-05, SRV-40 |
| Milestones | — |
Summary
Warehouses, stock levels, reservations and deductions by order status, automatic restock on cancellation and on return reception, movement ledger, thresholds and alerts, inventory sessions. Resellers only ever see availability.
Description
Stock must be exact in the back-office and never exposed as a number to resellers or guests (STK-01…STK-08, cahier §4.3, §8, §12; 17 Oct decisions 1 and 10). This task implements warehouses (global or per warehouse), StockLevel with physical, reserved and available (= physical − reserved) quantities and alert thresholds, and the StockMovement ledger for every change (RECEIPT, ADJUSTMENT, INVENTORY, RESERVATION, RESERVATION_RELEASE, SHIPMENT, RETURN, transfers). Order hooks reserve at stock.reserveOn (default VALIDATED) and deduct at stock.deductOn (default SHIPPED); cancellation and refusal release reservations automatically, cancellation after deduction re-enters quantities, and return reception posts RETURN movements automatically (consumed by SRV-20). No order is validated beyond available stock unless an authorised override is recorded (STK-08). It projects availability (IN_STOCK/OUT_OF_STOCK) to the catalog, raises low/out-of-stock alerts, and runs inventory sessions. Out of scope: stock UI (DSH-05) and V2 stock-system sync (SRV-37).
Subtasks
| # | Subtask | Owner |
|---|---|---|
| 1 | Warehouses with a default selling warehouse; admin.warehouses.crud | Anis |
| 2 | Stock service with row locks (SELECT … FOR UPDATE ordered by variant id) for reserve, release, deduct and re-enter; STOCK_INSUFFICIENT on shortage | Anis |
| 3 | Order hooks driven by stock.reserveOn / stock.deductOn settings, called by the orders state machine (SRV-16) | Anis |
| 4 | Authorised override for validation beyond available stock (stock.administer) with AuditLog OVERRIDE and reason (STK-08) | Anis |
| 5 | Receipts and adjustments with reasons (admin.stock.receipt, admin.stock.adjust) writing movements | Anis |
| 6 | Return reception hook: RETURN movements for accepted quantities into a chosen warehouse (used by SRV-20) | Anis |
| 7 | Availability projection → product/variant IN_STOCK/OUT_OF_STOCK and catalog status events | Anis |
| 8 | Thresholds (admin.stock.thresholds) and stock.low / stock.out outbox events to stock managers and the back-office stream | Anis |
| 9 | Inventory sessions: create, count lines, validate → INVENTORY movements for differences with reasons (admin.inventory.crud, admin.inventory.validate) | Anis |
| 10 | admin.stock.levels and admin.stock.movements with filters (warehouse, variant, type, date, reference) | Anis |
Deliverables
- apps/server/src/modules/inventory/{stock.service.ts,order-hooks.ts,availability.ts,inventory-sessions.service.ts,router.ts,events.ts}
- packages/contracts/src/admin/stock.ts
- Stock rules table in /docs/srs/lifecycles-and-statuses confirmed against the implementation
Acceptance criteria
- With reserveOn = VALIDATED, validating an order reserves each line; refusing or cancelling it writes RESERVATION_RELEASE and restores available (STK-03)
- Reaching SHIPPED writes SHIPMENT (physical −qty, reserved −qty); cancelling after that re-enters the quantities with a movement
- Validation beyond available stock fails with 422 STOCK_INSUFFICIENT unless the caller has the override permission and gives a reason (STK-08)
- Every change of physical or reserved has exactly one StockMovement with its reference (order, return, inventory session) (STK-04)
- When available reaches 0 the variant becomes OUT_OF_STOCK in the catalog and a stock.out alert is emitted (STK-05, CAT-04)
- No reseller or delegate endpoint returns a quantity (STK-07)
Requirements covered
| Requirement | Title | Release |
|---|---|---|
| STK-01 | Global stock or stock per warehouse | V1 |
| STK-02 | Physical, reserved and available stock (available = physical − reserved) with alert thresholds | V1 |
| STK-03 | Reservation and deduction triggered by configurable order statuses; cancellations and returns put quantities back automatically | V1 |
| STK-04 | Every stock variation is journaled (movement ledger) | V1 |
| STK-05 | Low-stock and out-of-stock alerts | V1 |
| STK-06 | Inventory sessions and adjustments with reasons | V1 |
| STK-07 | Resellers and guests only ever see availability (in stock / out of stock) — never quantities | V1 |
| STK-08 | No order validated beyond available stock unless an authorised override is recorded | V1 |
Screens
| Screen | Name | App |
|---|---|---|
| BO-33 | Stock overview | BO |
| BO-34 | Stock movements journal | BO |
| BO-35 | Stock receipt / adjustment | BO |
| BO-36 | Inventory sessions | BO |
| BO-37 | Warehouses | BO |
API surface
| Endpoint group | Operations |
|---|---|
| Stock | 8 |
Test measures
- DB concurrency test: 50 parallel validations competing for the last 10 units never oversell
- Ledger invariant test: physical = sum of movements per variant/warehouse after a random sequence of operations
- Unit tests for the reserveOn/deductOn hook matrix (SUBMITTED vs VALIDATED reservation)
Risks
- Deadlocks between concurrent multi-line orders — lock rows in a deterministic order and keep transactions short
- Physical stock in HOCO's existing system diverges from the platform — initial import in LCH-01 and inventory sessions; API sync is V2 (STK-09)
KPI
- Delivered by Sun 18 Oct 2026 within 1 person-day(s).
- Every acceptance criterion above demonstrated before hand-off; linked requirements' acceptance criteria pass.
- Zero open critical defects, permission gaps or data-integrity regressions at sign-off.
Generated from content/plan/tasks.json by scripts/generate-team-tasks.mjs. Dates are computed by the scheduler (Sunday–Thursday weeks, holidays excluded) — change the plan, not this page.
SRV-12 — Pricing engine
Three selling prices per variant (super-gros, demi-gros, détail) chosen by the reseller's customer type, VAT, price history; prices withheld from guests; promotions applied on top by the cart engine.
SRV-19 — Promotions & banners module
Promotions (percent, amount, fixed price) on products/categories/brands, targeting, schedule, stock cap, stacking rules, daily offers and banners, applied by the cart engine.