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.
Audit: accounting transactions for inspections & dispositions
Date: 2026-07-25 · Scope: inbound-inspection reject, NCR disposition close, batch split, and the receipt posting that feeds them. Read-only trace of three flows against the canonical inventory-adjustment posting path.
TL;DR
The inspection and disposition flows move inventory quantity (itemLedger) and tracked-entity status, but post no cost and no GL. Inventory value is booked once — at receipt — at full value even for requiresInspection items whose entities are On Hold, and is never relieved when that stock is rejected or scrapped. Result: the Inventory GL account overstates real inventory, cost layers (costLedger) never get consumed (FIFO/average drift), and there is no scrap/cost-of-quality expense.
How Carbon should post an inventory movement (reference)
Canonical path: edge fn packages/database/supabase/functions/post-inventory-adjustment/index.ts → shared core functions/shared/post-adjustment.ts::bookAdjustment. In one Kysely transaction per signed movement it writes:
itemLedger— signed quantity (always).costLedger— relieve layers viashared/calculate-cogs.ts::calculateCOGSon a decrease (honorscostingMethodStandard/Average/FIFO/LIFO,.forUpdate()locks layers, decrementsremainingQuantity); create a new layer at current carrying cost on an increase. Skipped forNon-Inventory/ qty 0.journal+journalLine(balanced Dr/Cr pair) +journalLineDimension(Item / ItemPostingGroup / Location tags) — only whencompanySettings.accountingEnabledand cost ≠ 0.
Account resolution (shared/get-posting-group.ts) is flat, one accountDefault row per company (posting-group matrix was dropped in 20260229000000_drop-posting-groups.sql):
- Inventory side by
replenishmentSystem:finishedGoodsAccount(Make / Buy and Make) elserawMaterialsAccount. - Offset:
inventoryAdjustmentVarianceAccount(seeded5310 "Inventory Adjustment", COGS/Expense). - No
valueLedger/generalLedgertables —costLedgeris the value ledger,journal/journalLineare the GL. UseaccountId(not the legacyaccountNumber).
When accounting is disabled, bookAdjustment still writes itemLedger + costLedger, but no journal — it fails closed (a failed companySettings read throws).
What the audited flows actually do
1. Inspection reject — apps/erp/app/modules/quality/quality.server.ts::dispositionInspection
- Flips lot tracked entities →
Rejected(Accept → un-sampledAvailable; Partial → none). No ledger. - Only ledger write (non-tracked
Inventory, receipt-sourced, not already Failed): oneitemLedgerNegative Adjmt.,documentType "Inbound Inspection",quantity: -lotSize,trackedEntityId: null. NocostLedger, nojournal. - Updates
inspectionstatus + writesinspectionHistory. - Tracked /
Non-Inventoryrejects post no ledger at all — only the status flip.
2. NCR disposition close — apps/erp/app/modules/quality/quality-disposition.server.ts::closeIssue
- Scrap / Return to Supplier (tracked): one
itemLedgerNegative Adjmt.per linked entity,documentType "Non-Conformance",quantity: -link.quantity; then flip entities →Rejected. No cost/GL. - Use As Is / Rework (tracked): flip entities →
Available. No ledger. - Non-tracked Use As Is / Rework restore (my recent change, inspection-originated
Inventoryonly): oneitemLedgerPositive Adjmt.+quantity. No cost/GL. - Sets
nonConformance.status = Closed.
3. Batch split — quality-disposition.server.ts::subdivideBatchEntity (via splitIssueItem)
- Three
itemLedgerBatch Splitrows that net to zero on-hand +trackedActivitygenealogy. Correctly no GL (no value change). Non-tracked quantity split writes noitemLedgerat all.
4. Receipt — packages/database/supabase/functions/post-receipt/index.ts
requiresInspectionhas exactly two effects: creates the inspection lot, and sets tracked entitiesOn Hold. Neither gates the posting. The main receipt loop books the normal full-valuejournal/journalLine+costLedgerlayers +itemLedgerfor every line regardless of inspection/On-Hold.- ⇒ At receipt, inspection stock's value is on the GL (
get_inventory_quantitieshides the quantity asquantityOnHold, but the value is booked). A later reject/scrap never reverses it.
5. itemLedger is quantity-only
No cost/value/amount column; its only triggers denormalize trackedEntityStatus. An itemLedger insert has no GL fan-out — cost/GL are always separate writes. Confirmed: zero journalLine / costLedger / post-inventory-adjustment / accountingEnabled references anywhere in the quality module or inspection/issue routes.
The gaps
| # | Gap | Consequence |
|---|---|---|
| G1 | Reject of non-tracked Inventory removes on-hand qty but not value/cost |
Inventory GL overstated by the lot's cost; cost layers not relieved |
| G2 | Reject of tracked stock changes status only — value stays in Inventory GL through the MRB hold and beyond | Rejected value commingled with good stock; relieved only if Scrap disposition eventually posts (it doesn't today) |
| G3 | Disposition Scrap / Return posts qty-only | No cost relief, no scrap/write-off expense — cost of quality invisible; GL overstated |
| G4 | Disposition Use As Is / Rework restore posts qty-only | If reject ever writes off value (post-fix), a kept lot's value isn't restored → understated |
| G5 | No accountingEnabled gate / accounting-period awareness in these flows |
Even correct-intent postings would ignore locked periods |
| G6 | NCR reopen (Closed→Registered) doesn't reverse anything | Once GL is added, reopen must reverse the journals or be blocked |
| G7 | Xero landmine — packages/ee/src/accounting/providers/xero/entities/inventory-adjustment.ts sweeps every itemLedger row with entryType ∈ {Positive/Negative Adjmt.} (ignores documentType) and recomputes value from itemCost.unitCost |
These NCR/inspection rows could push Xero ManualJournals with no matching local GL if adjustment sync is enqueued (currently disabled + push-only + backfill-only, so latent, not live) |
Account infrastructure (what exists to post against)
- Flat
accountDefault(PKcompanyId, one row/company). Relevant columns:rawMaterialsAccount,finishedGoodsAccount,workInProgressAccount,costOfGoodsSoldAccount,goodsReceivedNotInvoicedAccount,inventoryAdjustmentVarianceAccount,materialVarianceAccount, and the other variance/absorption accounts. Editable atapps/erp/app/modules/accounting/ui/AccountDefaults/AccountDefaultsForm.tsx; seeded infunctions/lib/seed.data.ts. - No dedicated scrap / write-off / adjustment-expense inventory account exists. Closest reusable =
inventoryAdjustmentVarianceAccount(5310, already the offset for physical-count adjustments). (customerWriteOffAccount=bad debt,supplierWriteOffAccount=vendor write-off income, fixed-assetwriteDownAccount— none fit inventory scrap.) - Production scrap has no scrap-specific GL today: scrapped-unit cost is absorbed into good-unit cost at
complete_job_to_inventory; residual WIP atclose-jobsweeps tomaterialVarianceAccount; scrapping a tracked material (functions/issue/index.ts::scrapTrackedEntity) posts DrworkInProgressAccount/ CrrawMaterials|finishedGoods(treated as consumption into WIP), not an expense.scrapReasonsare quantity labels with no account link.
Files
- Reference:
functions/post-inventory-adjustment/index.ts,functions/shared/post-adjustment.ts,functions/shared/calculate-cogs.ts,functions/shared/get-posting-group.ts. - Gap sites:
apps/erp/app/modules/quality/quality.server.ts(dispositionInspection),apps/erp/app/modules/quality/quality-disposition.server.ts(closeIssue,subdivideBatchEntity,splitIssueItem),apps/erp/app/routes/x+/inspection+/$id.reject.tsx,apps/erp/app/routes/x+/issue+/$id.close.tsx. - Receipt:
functions/post-receipt/index.ts. - Accounts:
packages/database/src/types.ts(accountDefault),apps/erp/app/modules/accounting/accounting.models.ts,functions/lib/seed.data.ts. - Xero:
packages/ee/src/accounting/providers/xero/entities/inventory-adjustment.ts.
→ Plan: .ai/plans/2026-07-25-inspection-disposition-gl-posting.md