Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

946 B
Raw Blame
-- Specific identification for serialized units. A cost layer booked for ONE
-- serial unit (a fixed asset returned to stock at its net book value, a
-- sales-type lease residual returned at its closing net investment, an
-- unscrap, a positive adjustment of a serial) records that unit, and
-- calculateCOGS relieves the unit leaving from its own layer instead of the
-- oldest one. NULL for every layer that covers many units (receipts, job
-- output), which keep FIFO / LIFO order.
ALTER TABLE "costLedger" ADD COLUMN IF NOT EXISTS "trackedEntityId" TEXT;

DO $$ BEGIN
  ALTER TABLE "costLedger" ADD CONSTRAINT "costLedger_trackedEntityId_fkey"
    FOREIGN KEY ("trackedEntityId") REFERENCES "trackedEntity"("id")
    ON DELETE SET NULL ON UPDATE CASCADE;
EXCEPTION WHEN duplicate_object THEN NULL; END $$;

CREATE INDEX IF NOT EXISTS "costLedger_trackedEntityId_idx" ON "costLedger" ("trackedEntityId")
  WHERE "trackedEntityId" IS NOT NULL;