Functional contract
Inventory
On-hand stock is per Location and shipped at /app/inventory (inventory.read; adjustments and status moves need inventory.manage at that Location). Purchasing identity is per Legal Entity. Catalog identity is per Organization. A unit at Location A never decrements Location B.
Stock control
Each catalog item has a master stock_control (not a Location override):
| Mode | Behavior |
|---|---|
No control (none) | No stock rows. Absent from Inventory. Default for services. Always for bundles |
Control without batch (quantity) | One on-hand integer per Location. Default for products |
Control with batch (batch) | On-hand is the sum of lots (lot number, optional expiry, quantity). Adjustments must name a lot. batch_strategy: fifo (default, oldest created), lifo (newest), fefo (earliest expiry; every lot needs expires_on) |
- Changing mode is rejected while on-hand or lot rows remain. Switching to FEFO is rejected while any lot lacks expiry.
- Manual adjustments cannot go negative. Invoicing may leave on-hand negative when overselling.
- Enabled identity comes from Catalog and pricing. Exclusive items are only stocked where granted.
Stock quantities
| Quantity | Meaning |
|---|---|
| On hand | Physical quantity at the Location (location_stocks or sum of lots) |
| Allocated | Rounded quantities on open sales-order lines for the item at this Location |
| Held | Units set aside in location_stock_holds: Reserved (optionally for a client or an open sales order here), On hold, or Quarantine |
| Available | on hand − allocated − held (may be negative) |
- Adding an inventoried item to an open order allocates it. Removing the line, voiding, or invoicing releases allocation.
- Batch lines store a preferred lot (suggested by strategy, editable). Issuing an invoice consumes on-hand: preferred lot first, then strategy order; a shortfall may create an
__oversold__lot. - Screens show on hand, allocated, held, and available, and warn when available is negative.
Holds and status moves
- Move stock (
POST /app/inventory/:id/status_moves,inventory.manage) moves units between Available, Reserved, On hold, and Quarantine without changing on hand. Batch items move per lot. - A move cannot exceed what the source status holds (or available).
- Each move writes a read-only
InventoryStatusMovement(from, to, quantity, staff, optional source and note). - Quarantined units may be written off instead of returned (reason
adjustmentorexpiry), lowering on hand via an adjustment. - The item page lists held rows with Release back to Available.
- Sales-order reservations are released on invoice or void, and retargeted to the surviving order on merge.
- Held units are not sellable: suggested lots skip fully held lots; adjustments cannot drop on hand below held.
Bundles
- Bundles (category kind
bundle) never hold stock;stock_controlis alwaysnone. - Availability is derived from stocked components (flattened through nested bundles):
min(floor(component available / units per bundle)). Short as soon as any stocked component is. - Open bundle lines allocate components; invoicing consumes components (strategy order for batch); restocking a credit-noted bundle line returns components.
- Bundles with no stocked components are not stock-checked.
Adjustments and kardex
- Manual adjustments write an
InventoryAdjustment(who, where, delta, optional lot and note). Enter a change (delta) or a target balance. - For batch items the same form updates lot
expires_on, including expiry-only edits. - Each row has a reason:
adjustment,sale,expiry, orreturn, and an optional polymorphic source (SalesOrderfor invoice consumption,CreditNotefor restock). - The item page kardex lists every movement at the selected Location: type, reference (linked), lot, before/change/after, staff, note. Status moves appear as “Status move” rows (from → to).
Transfers between Locations
Not built Sites in the same Organization move stock with a documented transfer. Traceability: who sent, who received, what, how many, when.
| Step | Behavior |
|---|---|
| Create | Source Location (or an Organization admin) starts a transfer to another Location in the same Organization |
| In transit | Left the source; not yet available at the destination |
| Receive | Destination confirms; quantity becomes on hand there |
| Cancel / reject | Stock returns to the source; no silent disappear |
No client invoice. Same Legal Entity: internal transfer. Different Legal Entities: still a transfer; intercompany cost out of scope. Never to another Organization.
Purchase orders
Not built Issued in the name of a Legal Entity.
- Vendor sees the Legal Entity's legal name and tax ID.
- One PO may supply several Locations of that Legal Entity. Receiving is per Location.
- A Location cannot receive a PO for a Legal Entity it does not belong to.
Visibility
| Actor | Sees |
|---|---|
| Organization admin | On-hand at every Location; later all transfers and POs |
| Location manager / staff | On-hand (later transfers and receipts) for granted Locations only |
| Other Locations | Not each other's quantities, except on a shared transfer |
Acceptance
- Adjusting one unit at A changes A and leaves B unchanged.
- Items with no stock control are absent from Inventory. Batch adjustments without a lot are rejected.
- Staff granted only A cannot read B's counts.
- Open order lines allocate; available = on hand − allocated − held.
- Status moves leave on hand unchanged; an order reservation is released on invoice or void.
- Invoicing consumes on-hand (preferred lot, then strategy) and drops allocation; voiding releases without consuming.
- Overselling is allowed with a warning.
- The kardex lists all movements; sale rows link to the sales order.
- FEFO items reject adjustments without expiry.
- Transfers need a receive at B; POs for Legal Entity 1 cannot be received at a Location of Legal Entity 2 (not built).
Out of scope: reorder points, lot recalls, controlled-substance registers, vendor EDI, intercompany invoices for cross-EIN transfers.