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/jobs-date-range-filter-v1
naveenkashf96e4faf9757
diff --cc .ai/lessons.mdindex 1643c4f2f6,f3ad30e058..7b9aae7c28--- a/.ai/lessons.md+++ b/.ai/lessons.md@@@ -3003,12 -3027,23 +3029,34 @@@ And a delete whose failure the caller i**Applies to:** `packages/react/src/PrefetchLink.tsx`; `packages/utils/src/prefetch.ts`; any `<Link prefetch>` or `PrefetchPageLinks`; a revalidation started while a navigation to the same URL is loading.+ ## A revalidation during the navigation after a save loses the save++ **Context:** 186 layouts export `shouldRevalidate` and skip a GET navigation that leaves their params unchanged. Realtime calls `revalidate()` 300 ms after a broadcast.++ **Problem:** A save's own broadcast arrives while its redirect is still loading. `revalidate()` during a loading navigation restarts it with `overrideNavigation: state.navigation`, and for a fetcher submission that carries no `formMethod`. The restarted navigation looks like a plain one, so each layout returned `false` and kept its data from before the save: a new quote line was missing from the quote's explorer until a reload (2026-10-05). In single fetch `defaultShouldRevalidate` is `true` for every route on every navigation, so a predicate cannot tell a forced reload from a plain one. A first fix assumed React Router's default was `false` after a redirect with no cookie; logging the predicate's arguments in the browser showed the default was `true` and the first pass did include the layout.++ **Rule:** Never call React Router's `revalidate()` directly. Import `useRevalidator` from `@carbon/query`: it holds a call made while a navigation is in flight or a fetcher is submitting and runs it when the router is idle. The `no-raw-revalidator` check (`@carbon/checks`) fails an import of React Router's. Before explaining a skipped loader, log what `shouldRevalidate` received: wrap the route's `shouldRevalidate` on `window.__reactRouterDataRouter.routes` and read `formMethod`, `defaultShouldRevalidate` and both URLs for each call.++ **Applies to:** `packages/query/src/useRevalidator.ts`; every `revalidate()` call (realtime, polling timers, upload callbacks); every route that exports `shouldRevalidate`.+++ ## A drag re-rendered every card on the board++ **Context:** The schedule boards (operations, dates, batches) render one sortable card per operation or job, each with a form, avatars, tooltips and a menu.++ **Problem:** A drag stuttered: with 82 cards, six frames of a 90-frame sweep took over 100 ms. Two causes. dnd-kit re-renders every `useSortable` consumer when the drop target changes, and the hook sat inside the card, so every card's whole body rendered each time. And `useSensor(KeyboardSensor, { coordinateGetter })` passed a new options object on every render: dnd-kit memoizes the sensor on it, so every draggable got new `listeners`, which defeats `memo` on anything that takes them.++ **Rule:** A sortable card is a thin shell that calls `useSortable` and a `memo`ized body that takes plain props (`sortableCardProps` in `Schedule/Kanban/cardShell.ts`). `useSensor` options are a module constant (`no-inline-sensor-options` check). A context every card reads must have a stable value. To find what re-renders, count renders per component during a scripted drag; do not guess.++ **Applies to:** `apps/erp/app/modules/production/ui/Schedule/Kanban/**`; any dnd-kit board or list with more than a few dozen items.+++++## Lingui: `plural()` inside a `memo(…)` component calls the global i18n++**Context:** The jobs table's bulk-release toast needed "Released 1 job" / "Released N jobs". The table is `memo((props) => { … })`, and the toast text was written as `` t`${plural(count, { one: "Released # job", other: "Released # jobs" })}` `` with `t` from `useLingui()` and `plural` from `@lingui/core/macro`.++**Problem:** Lingui 6.9.0's macro transform folds a nested `plural()` into the surrounding `t` only when the component or hook is a function declaration or a plain `const X = () => …`. When the function is an inline ARGUMENT of a call (`memo((props) => …)`), the `plural()` is expanded on its own into `i18n._(…)` on the global `@lingui/core` instance, and the outer `t` becomes `{0}` with that call as its value. The global instance is never activated here (see `.claude/rules/i18n-lingui-system.md`), so the string throws "Attempted to call a translation function without setting a locale" the first time it is built. Typecheck, Biome and `lingui:extract` all pass: the catalog shows a normal ICU plural msgid. Only the compiled output shows it.++**Rule:** Do not call `plural()` (or `select()`) from `@lingui/core/macro` inside a component passed inline to `memo(…)` or any other call. Use `<Plural>` in JSX. For a string (a toast), either build it in a function-declaration hook (`function useX() { const { t } = useLingui(); return (n: number) => t`${plural(n, …)}`; }`), or choose between two whole `t` phrases (``n === 1 ? t`Released 1 job` : t`Released ${n} jobs` ``) — both phrases are extracted and translated, but a locale with more plural forms gets only two. When in doubt, read the compiled module (Vite `transformRequest` on the file) and check for an import of `i18n` from `@lingui/core`.++**Applies to:** every `memo(…)` component in `apps/{erp,mes}/app` and `packages/{react,form}/src` (most ERP tables); any new use of `plural` / `select` from `@lingui/core/macro`.diff --cc apps/erp/test/release-jobs.test.tsindex 4a82a18003,0000000000..73e5ee1fa4mode 100644,000000..100644--- a/apps/erp/test/release-jobs.test.ts+++ b/apps/erp/test/release-jobs.test.ts@@@ -1,102 -1,0 +1,109 @@@+// SPDX-License-Identifier: AGPL-3.0-only+// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,+// including ports, remain AGPLv3; serving them over a network requires releasing their source.++import { beforeEach, describe, expect, it, vi } from "vitest";+++// The service's imports now reach the glossary, whose `msg` macro only runs compiled.++vi.mock("@lingui/core/macro", () => ({++ msg: (strings: TemplateStringsArray) => ({ id: strings.join("") })++}));+vi.mock("@carbon/auth/client.server", () => ({+ getCarbonServiceRole: vi.fn(() => ({}))+}));- vi.mock("@carbon/env", () => ({ ASSEMBLER_SERVICE_URL: "" }));++vi.mock("@carbon/env", async (importOriginal) => ({++ ...(await importOriginal<typeof import("@carbon/env")>()),++ ASSEMBLER_SERVICE_URL: ""++}));+vi.mock("@carbon/logger", () => ({+ getLogger: () => ({ error: vi.fn() })+}));+vi.mock("@carbon/server-functions", () => ({+ serverFns: {+ system: () => ({+ invoke: vi.fn(async () => ({+ data: { purchaseOrderIdsBySupplierId: {} },+ error: null+ }))+ })+ }+}));+vi.mock("../app/modules/production/production.service", () => ({+ getJobReleaseReadiness: vi.fn(),+ recalculateJobRequirements: vi.fn(async () => ({ data: null, error: null })),+ runMRP: vi.fn(async () => ({ data: null, error: null })),+ updateJobStatus: vi.fn(async () => ({ error: null, updated: true }))+}));++import {+ runMRP,+ updateJobStatus+} from "../app/modules/production/production.service";+import { releaseJobs } from "../app/modules/production/production.server";++// The release-date write: a chainable, thenable stand-in for the user client.+function clientWith(stamp: { error: null | { message: string } }) {+ const chain: Record<string, any> = {};+ for (const method of ["update", "eq"]) chain[method] = () => chain;+ chain.then = (resolve: (value: unknown) => unknown) =>+ Promise.resolve({ data: null, ...stamp }).then(resolve);+ return { from: () => chain } as any;+}++const release = (client: any, jobIds = ["job-1"]) =>+ releaseJobs({+ client,+ db: {} as any,+ jobIds,+ companyId: "company-1",+ userId: "user-1",+ purchaseOrdersBySupplierId: {}+ });++beforeEach(() => vi.clearAllMocks());++describe("releaseJobs", () => {+ it("releases past a failed MRP run", async () => {+ vi.mocked(runMRP).mockResolvedValueOnce({+ data: null,+ error: new Error("planning blew up")+ });+ const result = await release(clientWith({ error: null }));+ expect(result).toEqual({+ error: null,+ purchaseOrdersBySupplierId: {},+ releasedJobIds: ["job-1"]+ });+ });++ it("flips only a job still Draft or Planned, and stops when it is not", async () => {+ vi.mocked(updateJobStatus).mockResolvedValueOnce({+ error: null,+ updated: false+ } as any);+ const result = await release(clientWith({ error: null }), [+ "job-1",+ "job-2"+ ]);+ expect(vi.mocked(updateJobStatus).mock.calls[0]?.[1]).toMatchObject({+ status: "Ready",+ fromStatuses: ["Draft", "Planned"]+ });+ expect(result).toEqual({+ error: "The job is no longer Draft or Planned",+ purchaseOrdersBySupplierId: {},+ releasedJobIds: []+ });+ });++ it("reports a failed release-date write on a job that is released", async () => {+ const result = await release(+ clientWith({ error: { message: "connection reset" } })+ );+ expect(result).toEqual({+ error: "The job is released, but its release date could not be saved",+ purchaseOrdersBySupplierId: {},+ releasedJobIds: ["job-1"]+ });+ });+});