Skip to main content
Version: v1.0.0(int)

org.finished_goods_inventory_ledger

Append-only event log for finished-goods movement. Same shape as the materials ledger, anchored on sku_id instead of material_id. Summary views are derived.

ER diagram

Columns

Identical shape to materials_inventory_ledger, anchored on sku_id instead of material_id. event_type uses the finished_goods_inventory_event_type ENUM (same values as materials, plus PRODUCE and REVERSE_PRODUCE which only apply to FG).

ColumnTypeNotes
idUUID PK
org_idUUID FKplatform.organizations(id).
codeTEXTNOT NULL. Row's own human-readable ID (e.g. FIL-001). Auto-generated when not supplied. UNIQUE per (org_id, code). Distinct from ref.
sku_idUUID FKNOT NULL. → org.skus(id) ON DELETE RESTRICT.
location_idUUID FKorg.locations(id) ON DELETE RESTRICT.
event_typefinished_goods_inventory_event_typeNOT NULL. ENUM. See Event types below.
quantityNUMERIC(18,6)NOT NULL. CHECK > 0. Direction encoded in event_type.
unit_costNUMERIC(18,6)Cost basis. Set at write time. NULL when not applicable.
refTEXTExternal reference (PO/WO/SO number, TFR-FG-###). Multiple rows can share the same ref.
to_location_idUUID FKorg.locations(id) ON DELETE RESTRICT. Set only for TRANSFER events.
notesTEXT
event_dateTIMESTAMPTZNOT NULL. Default NOW(). Real-world event time.
source_typeorg.ledger_source_kindENUM. po_receipt (FG-target POs), wo_receipt, so_item, manual.
source_idUUIDOriginating row id. (source_type, source_id) is the idempotency key. No DB-level FK — application-enforced.
created_atTIMESTAMPTZNOT NULL. Default NOW().

Constraints: same as the materials ledger — ((source_type IS NULL AND source_id IS NULL) OR both set).

Event types

finished_goods_inventory_event_type ENUM:

ValueMeaning
ORDERA PO targeting FG was placed — committed inflow not yet received.
RECEIVEFG physically received (from a PO or completing a transfer).
PRODUCEFG produced by a WO completion. Distinct from RECEIVE so reporting can separate purchased FG from in-house production.
DEMANDAn SO was placed — committed outflow.
ALLOCATESoft reservation against a specific SO before fulfillment.
CONSUMEActual outflow when the SO ships.
TRANSFERFG leaves location_id for to_location_id. Paired with a later RECEIVE sharing the same ref.
ADJUSTManual correction (positive quantity). Reductions use DISPOSE.
DISPOSEManual removal — write-off, damage, loss.
REVERSE_ORDERCancels an ORDER (e.g. FG-target PO transitioned to Cancelled).
REVERSE_RECEIVECancels a RECEIVE (e.g. PO receipt deleted, or transfer reversed).
REVERSE_PRODUCECancels a PRODUCE (e.g. WO receipt deleted).
REVERSE_DEMANDCancels a DEMAND (e.g. SO transitioned to Rejected).
REVERSE_ALLOCATEReleases a previously written ALLOCATE (was RELEASE in earlier drafts; renamed for consistency).
REVERSE_CONSUMECancels a CONSUME (e.g. SO deleted after shipment).
REVERSE_TRANSFERCancels a TRANSFER (e.g. an in-transit transfer is voided).

REVERSE_* rows store positive quantities — the schema's quantity > 0 invariant holds. Direction is encoded entirely in event_type; the summary query interprets reverse rows as netting their original counterpart. Each reverse row carries source_type and source_id matching the original entry so audit pairs are easy to find.

Event sources

  • RECEIVE from a PO receipt when the PO's target_type = 'finished_goods'.
  • RECEIVE from a WO receipt — the canonical source of new FG inventory.
  • DEMAND / ALLOCATE / CONSUME from SO progression.
  • TRANSFER paired with a later RECEIVE (sharing the same TFR-FG-xxx ref) — the manual transfer flow.
  • ADJUST / DISPOSE from the manual flow on the Finished Goods Inventory page.

ref conventions

Event typeref value
RECEIVE (from PO)PO number
RECEIVE (from WO)WO number
DEMAND / ALLOCATE / CONSUME (from SO)SO number
TRANSFERTFR-FG-xxx (auto-generated)
RECEIVE (completing transfer)Same TFR-FG-xxx as the paired TRANSFER
ADJUST / DISPOSENULL