HOCO B2B
Team tasksAnis

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.

FieldDetails
Task codeSRV-13
PhaseP1 — V1 build & integration
Product scopeV1
StatusDone (Sun 18 Oct 2026)
StartSun 18 Oct 2026
DueSun 18 Oct 2026
ResponsibleAnis — Full-stack developer
Co-responsible—
Effort1 person-day(s) planned · 5 from scratch · size S
Area · appServer · server
Depends onSRV-11
UnblocksSRV-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

#SubtaskOwner
1Warehouses with a default selling warehouse; admin.warehouses.crudAnis
2Stock service with row locks (SELECT … FOR UPDATE ordered by variant id) for reserve, release, deduct and re-enter; STOCK_INSUFFICIENT on shortageAnis
3Order hooks driven by stock.reserveOn / stock.deductOn settings, called by the orders state machine (SRV-16)Anis
4Authorised override for validation beyond available stock (stock.administer) with AuditLog OVERRIDE and reason (STK-08)Anis
5Receipts and adjustments with reasons (admin.stock.receipt, admin.stock.adjust) writing movementsAnis
6Return reception hook: RETURN movements for accepted quantities into a chosen warehouse (used by SRV-20)Anis
7Availability projection → product/variant IN_STOCK/OUT_OF_STOCK and catalog status eventsAnis
8Thresholds (admin.stock.thresholds) and stock.low / stock.out outbox events to stock managers and the back-office streamAnis
9Inventory sessions: create, count lines, validate → INVENTORY movements for differences with reasons (admin.inventory.crud, admin.inventory.validate)Anis
10admin.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

RequirementTitleRelease
STK-01Global stock or stock per warehouseV1
STK-02Physical, reserved and available stock (available = physical − reserved) with alert thresholdsV1
STK-03Reservation and deduction triggered by configurable order statuses; cancellations and returns put quantities back automaticallyV1
STK-04Every stock variation is journaled (movement ledger)V1
STK-05Low-stock and out-of-stock alertsV1
STK-06Inventory sessions and adjustments with reasonsV1
STK-07Resellers and guests only ever see availability (in stock / out of stock) — never quantitiesV1
STK-08No order validated beyond available stock unless an authorised override is recordedV1

Screens

ScreenNameApp
BO-33Stock overviewBO
BO-34Stock movements journalBO
BO-35Stock receipt / adjustmentBO
BO-36Inventory sessionsBO
BO-37WarehousesBO

API surface

Endpoint groupOperations
Stock8

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.

On this page