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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
Merge remote-tracking branch 'origin/main' into naveenkash/strict-backflush
naveenkash92fc7ffd6ae4
diff --cc .ai/lessons.mdindex 01e61735cb,57e35837a0..d8a19f222f--- a/.ai/lessons.md+++ b/.ai/lessons.md@@@ -3703,56 -3703,36 +3703,86 @@@ The write was then removed (nothing rea**Applies to:** `membership` and its interceptors in `packages/database/src/event-system/handlers/`, and any unique key with a nullable column.+## A pick moves a job material's storage unit to lineside, so the line no longer names its Pull From++**Context:** Strict backflush (2026-10-16) consumed what no pick covered from `jobMaterial.storageUnitId`.++**Problem:** Posting a pick calls `pointJobMaterialAtLineside`, which overwrites `jobMaterial.storageUnitId` with the lineside bin. After a partial pick, the remainder was checked against lineside (already drawn) instead of the warehouse bin the BoM named. With negative stock prevented it refused a completion the shelf could cover. With it allowed, it drove lineside negative. The TypeScript and SQL paths had the same bug, and no test picked anything.++**Rule:** Never read `jobMaterial.storageUnitId` as "the Pull From" once picking may have run. The pick line keeps the source (`pickingListLine.storageUnitId`). Use the oldest pick line into the line's current bin (`pullFromStorageUnit`, `@carbon/database/strict-backflush`). A later list is sourced from the fullest bin, so do not use the newest one. Any test of a bin rule needs a case with a partial pick.++**Applies to:** strict backflush, and any rule keyed on a job material's bin (picking, returns, lineside credit, consumption).++## A module the browser bundles must not reach the Kysely runtime, even through a helper++**Context:** Strict backflush (2026-10-16). `@carbon/database/strict-backflush` is imported by BoM UI components and by `settings.service.ts`, which the module barrel bundles for the browser.++**Problem:** Using `inOrder` from `@carbon/database/rows` there would have imported `kysely` at runtime into the client bundle; typecheck does not see it. Separately, `settings.server.ts` gained an import of `~/utils/query`, which imports the `@carbon/auth` barrel. That barrel runs a Lingui `msg` macro, which plain vitest cannot compile, so 2 unrelated test files stopped loading.++**Rule:** In a client-bundled module, import only types from `kysely` and `./client`. Run two awaits instead of `inOrder`. Raw `sql` belongs in a server-only file. Before adding an import to a file that tests import, check what that import's barrel pulls in, then run the module's tests.++**Applies to:** `@carbon/database` subpaths read by UI, `{module}.service.ts`, `{module}.server.ts` imported by vitest files.++## A Lingui placeholder is named after its expression, so a refactor can silently drop translations++**Context:** Strict backflush (2026-10-16) changed `<Plural value={methodsMissingPullFrom} …>` to `<Plural value={gaps.methods} …>`.++**Problem:** A member expression has no name, so the message id changed from `{methodsMissingPullFrom, plural, …}` to `{0, plural, …}`. `lingui:extract --clean` then deleted the old id and its 12 translations, and the new id came back untranslated.++**Rule:** Pass a plain, named variable to `Plural`, `t` and `Trans` placeholders, and keep the name when refactoring. If extract drops translations by mistake, restore the catalogs from git (`git checkout HEAD -- packages/locale/locales`), fix the name, and extract again.++**Applies to:** every `Plural` / `t\`…${x}\`` / `<Trans>` with an interpolation.++## Guard a state by listing everything that writes it, not by who calls the check++**Context:** Strict backflush (2026-10-17). Release had to refuse a job with a line that had no storage unit. The check was added where the release check already ran: the Release dialog, bulk release, batch release.++**Problem:** Two more paths set a job to Ready without any check. The kanban scan with auto-release wrote `status: "Ready"` straight to the job with the service role. The MCP / API tool `production_updateJobStatus` wrote any status. A search for callers of the release function cannot find a direct write. A self-review on a fixed file list did not look outside it, and the docs then claimed "every release path".++**Rule:** To guard a state change, first list every writer of that state: grep for the value being written (`status: "Ready"`, `SET status = 'Ready'` in SQL) and for every caller of the write function, including MCP tools. Put the check where all writers meet, or give each writer the check. Keep the unchecked write out of the API (no `@mcp` tag). Do not claim "every path" without that list.++**Applies to:** release, completion, posting, cancellation — any status a check must gate.++## A flash returned with `data()` from a page loader never shows++**Context:** The kanban scan (2026-10-19) returned `data(result, await flash(request, error(…)))` from its loader, and its page then navigated to the job with `window.location`.++**Problem:** The message never appeared. The root's `flashMiddleware` reads and clears the flash on every request. It ran on the scan's own document request and cleared the cookie the loader had just set. Typecheck and unit tests cannot see this; only the browser did.++**Rule:** To carry a message to another page, throw `redirect(path, await flash(request, …))` from the loader or action, as every other route does. Do not return a flash with `data()` from a page loader and expect a later page to show it.++**Applies to:** any loader or action that sets a flash for the page it sends the user to.++ ## A flash on a fetcher's redirect back to the same page is never shown++ **Context:** Refusing a receipt post that still misses serial numbers (2026-10-16). The Post dialog submits through `useRuleViolations`, a fetcher.++ **Problem:** The action threw `redirect(path.to.receipt(id), await flash(...))`. The redirect lands on the pathname already on screen, so the root's `shouldRevalidate` (`isSearchParamOnlyNavigation`) skips the root loader, and the root is what reads the flash and shows the toast. The post was refused correctly, but the user saw nothing happen. The route's older flash errors ("Failed to post receipt") have the same gap.++ **Rule:** An action submitted through a fetcher returns its error as data (`{ error: { message } }`, which `useRuleViolations` toasts), not as a flash on a redirect to the current page. A flash is for a redirect that navigates somewhere else.++ **Applies to:** Post / void / approve actions behind a modal or `useRuleViolations` (`receipt+/$receiptId.post.tsx` and its siblings).++ ## What a document posts must be what its form shows++ **Context:** Receipt serial entry (2026-10-16). Each serial box saved on blur, keyed on the serial number.++ **Problem:** A box emptied, refused (a duplicate) or pushed out of range by a lower received quantity kept its saved serial. The post check reads what is saved, so the receipt posted a serial the user could no longer see.++ **Rule:** Key a per-field save on the field's position (here the box: receipt line + index), not on its value. An empty value, a refused value and a removed field each clear what is saved for it. And a removal never deletes a record with stock history: a sales return re-tags real shipped units, so those only lose their receipt link (`planReceiptSerialRelease`).++ **Applies to:** `setReceiptLineSerial` / `saveReceiptSerialBox`, `updateReceiptLines`, `ReceiptLines` `SerialForm`, the receipt line split (`receiptLineSplit` in `shared.service.ts`), and any autosaved list of tracked values (shipment serials, batch numbers).++ ## A void reverses only what is still where the posting put it++ **Context:** Voiding a posted purchase receipt with serials and batches (2026-10-16).++ **Problem:** The void set every tracked entity back to Available at its received quantity, so a lot that was never received stayed pickable. It also reversed each ledger row at the receipt's bin with only a cost-layer check. A serial moved to another bin, picked to lineside or shipped (Standard and Average cost never draw a layer down) passed that check, so the receipt bin went negative while the unit stayed counted where it went. And the receipt's inspection lot stayed open: Accept made the voided batch Available again, and Reject wrote the reversed stock off a second time.++ **Rule:** A reversal checks, inside its transaction, that the stock it removes is still at the position the posting wrote: per serial or batch for tracked rows. It closes every record that hangs off the document (here the inspection lot) or refuses while one has acted. It drains the document's tracked entities to quantity 0. To keep `Rejected` at zero, write the status directly: `settleQuantity` only preserves `Scrapped` and turns `Rejected` into `Consumed`.++ **Applies to:** the `postReceipt` void (`lockPostedReceipt`, `assertReceivedStockOnHand`, `assertNoRejectedUntrackedLot` in `inventory.service.ts`), and any other void that reverses item ledger rows (shipments, stock transfers, adjustments).+## A text replace on a function name also renames its prefix siblings**Context:** The service-function migration (2026-10-16) renamed thousands of call sites with scripts.diff --cc apps/erp/app/modules/shared/shared.service.tsindex e30ed12e02,1770723dfb..65a10ba9a6--- a/apps/erp/app/modules/shared/shared.service.ts+++ b/apps/erp/app/modules/shared/shared.service.ts@@@ -183,7 -185,7 +185,8 @@@ importsetGenericQueryFilters} from "~/utils/query";import type { CustomFieldsTableType } from "../settings/types";+ import type { assignableTables } from "./shared.models";+import { assertMethodHasPullFrom, isStrictBackflush } from "./strict-backflush";import type { ItemModelUpload } from "./types";const logger = getLogger("erp", "shared");diff --cc apps/erp/app/routes/api+/mcp+/lib/tool-manifest.digest.jsonindex ab4974ff6f,0b414935c6..5d2fb873a8--- a/apps/erp/app/routes/api+/mcp+/lib/tool-manifest.digest.json+++ b/apps/erp/app/routes/api+/mcp+/lib/tool-manifest.digest.json@@@ -741,11 -742,11 +742,11 @@@{"name":"production_getJobExpediteForecast","classification":"READ","schema":"ca49bc65b712","response":"d377dc3a1fd5","permission":"production:view","paginates":false},{"name":"production_getJobMakeMethodById","classification":"READ","schema":"7679db37b5f9","response":"ec2dc329264c","permission":"production:view","paginates":false},{"name":"production_getJobMaterialItemIds","classification":"READ","schema":"ca49bc65b712","response":"32068a500dfe","permission":"production:view","paginates":false},- {"name":"production_getJobMaterialsByMethodId","classification":"READ","schema":"7679db37b5f9","response":"f2854a3bd7f8","permission":"production:view","paginates":false},+ {"name":"production_getJobMaterialsByMethodId","classification":"READ","schema":"7679db37b5f9","response":"08d673090a5e","permission":"production:view","paginates":false},- {"name":"production_getJobMaterialsWithQuantityOnHand","classification":"READ","schema":"7f300608525e","response":"839ec8fc28ff","permission":"production:view","paginates":false},+ {"name":"production_getJobMaterialsWithQuantityOnHand","classification":"READ","schema":"f0c0b4958cf1","response":"839ec8fc28ff","permission":"production:view","paginates":false},{"name":"production_getJobMethodTree","classification":"READ","schema":"ca49bc65b712","response":"b65b4600c0ec","permission":"production:view","paginates":false},{"name":"production_getJobOperationAttachments","classification":"READ","schema":"cf62af6a7d5a","response":"9a8b9c571a6b","permission":"production:view","paginates":false},- {"name":"production_getJobOperationBatches","classification":"READ","schema":"e2389bb135b5","response":"505156d91e5d","permission":"production:view","paginates":true},+ {"name":"production_getJobOperationBatches","classification":"READ","schema":"cd40ae40fad5","response":"505156d91e5d","permission":"production:view","paginates":true},{"name":"production_getJobOperationBatchEvents","classification":"READ","schema":"1a62d6c430a5","response":"031cdafdafbd","permission":"production:view","paginates":false},{"name":"production_getJobOperationBatchMembers","classification":"READ","schema":"d429e4a46057","response":"66bcdc105c00","permission":"production:view","paginates":false},{"name":"production_getJobOperationBatchMemberStats","classification":"READ","schema":"d429e4a46057","response":"03aaee65a70b","permission":"production:view","paginates":false},@@@ -758,8 -759,8 +759,8 @@@{"name":"production_getJobOrderStatusMap","classification":"READ","schema":"cc93d4900988","response":"5a380f81ad00","permission":"production:view","paginates":false},{"name":"production_getJobPurchaseOrderLines","classification":"READ","schema":"ca49bc65b712","response":"f0dff75b384d","permission":"production:view","paginates":false},{"name":"production_getJobReceiptSnapshot","classification":"READ","schema":"ca49bc65b712","response":"60e9609498b0","permission":"production:view","paginates":false},- {"name":"production_getJobReleaseReadiness","classification":"READ","schema":"bd58e48cf49b","response":"2a2deafa81ab","permission":"production:view","paginates":false},+ {"name":"production_getJobReleaseReadiness","classification":"READ","schema":"bd58e48cf49b","response":"f5f114b3f417","permission":"production:view","paginates":false},- {"name":"production_getJobs","classification":"READ","schema":"e2389bb135b5","response":"418c2732d3b9","permission":"production:view","paginates":true},+ {"name":"production_getJobs","classification":"READ","schema":"cd40ae40fad5","response":"418c2732d3b9","permission":"production:view","paginates":true},{"name":"production_getJobsByDateRange","classification":"READ","schema":"c4a3c6cdab79","response":"94688560d7de","permission":"production:view","paginates":false},{"name":"production_getJobsBySalesOrderLine","classification":"READ","schema":"fbe78064dbd7","response":"70526fffc19e","permission":"production:view","paginates":false},{"name":"production_getJobsList","classification":"READ","schema":"c47cc3e0c427","response":"232ee7305e73","permission":"production:view","paginates":false},@@@ -1514,10 -1517,10 +1517,10 @@@{"name":"settings_enableCompanyAuditLog","classification":"WRITE","schema":"31b84d65b2ac","response":"a369dbcd055c","permission":"settings:update","paginates":false},{"name":"settings_getAccountsPayableBillingAddress","classification":"READ","schema":"31b84d65b2ac","response":"7c0b9dc6d441","permission":"settings:view","paginates":false},{"name":"settings_getAccountsReceivableBillingAddress","classification":"READ","schema":"31b84d65b2ac","response":"7c0b9dc6d441","permission":"settings:view","paginates":false},- {"name":"settings_getApiKeys","classification":"WRITE","schema":"e2389bb135b5","response":"14fbafc2ddf8","permission":"users:update","paginates":true},+ {"name":"settings_getApiKeys","classification":"WRITE","schema":"cd40ae40fad5","response":"14fbafc2ddf8","permission":"users:update","paginates":true},{"name":"settings_getCompanies","classification":"READ","schema":"31b84d65b2ac","response":"5783a32e0f4a","permission":"settings:view","paginates":false},{"name":"settings_getCompany","classification":"READ","schema":"31b84d65b2ac","response":"81a93f0029ec","permission":"settings:view","paginates":false},- {"name":"settings_getCompanySettings","classification":"READ","schema":"31b84d65b2ac","response":"689a7e333d99","permission":"settings:view","paginates":false},+ {"name":"settings_getCompanySettings","classification":"READ","schema":"31b84d65b2ac","response":"62d80c17f737","permission":"settings:view","paginates":false},{"name":"settings_getConfig","classification":"READ","schema":"31b84d65b2ac","response":"aa1021ff34cf","permission":"settings:view","paginates":false},{"name":"settings_getCurrentSequence","classification":"READ","schema":"31018ffa701d","response":"00404e686415","permission":"settings:view","paginates":false},{"name":"settings_getCustomField","classification":"READ","schema":"7f8214d1083f","response":"a533a796c094","permission":"settings:view","paginates":false},@@@ -1555,8 -1558,8 +1558,8 @@@{"name":"settings_updateDimensionSync","classification":"WRITE","schema":"42c99362fccd","response":"f95fa90d0071","permission":"settings:update","paginates":false},{"name":"settings_updateInventorySettings","classification":"WRITE","schema":"0e19706cf388","response":"8197b1c61474","permission":"settings:update","paginates":false},{"name":"settings_updateInvoicingSettings","classification":"WRITE","schema":"48fd9aba9ea8","response":"a32ee5ad2099","permission":"settings:update","paginates":false},- {"name":"settings_updateItemSerialSequence","classification":"WRITE","schema":"5544b362f82e","response":"3797626bd17e","permission":"settings:update","paginates":false},+ {"name":"settings_updateItemSerialSequence","classification":"WRITE","schema":"8e65da365dcb","response":"3797626bd17e","permission":"settings:update","paginates":false},- {"name":"settings_updateItemsSettings","classification":"WRITE","schema":"e8ef8b2a7abb","response":"da26374a450b","permission":"settings:update","paginates":false},+ {"name":"settings_updateItemsSettings","classification":"WRITE","schema":"b4f7e7addad9","response":"03604adb2677","permission":"settings:update","paginates":false},{"name":"settings_updatePlanningSettings","classification":"WRITE","schema":"0c543ed217a3","response":"0b9572e63423","permission":"settings:update","paginates":false},{"name":"settings_updatePostingSync","classification":"WRITE","schema":"a545e3ef8da3","response":"f95fa90d0071","permission":"settings:update","paginates":false},{"name":"settings_updateProductionSettings","classification":"WRITE","schema":"aab377266e08","response":"be6b8045779d","permission":"settings:update","paginates":false},diff --cc packages/jobs/manifests/schema.jsonindex 4933c23d55,06f09732a4..2e7f55444e--- a/packages/jobs/manifests/schema.json+++ b/packages/jobs/manifests/schema.json@@@ -1,11 -1,11 +1,11 @@@{"kind": "carbon-company-backup","version": 1,-- "schemaVersion": "20261017070014",++ "schemaVersion": "20261019104431","sourceCompanyId": "schema-baseline","sourceCompanyGroupId": null,"sourceCompanyName": null,- "exportedAt": "2026-10-18T20:30:56.842Z",- "exportedAt": "2026-10-17T07:08:05.778Z",++ "exportedAt": "2026-10-19T13:03:48.932Z","exportedBy": "schema-baseline","label": "schema baseline","includeStorage": "none",