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
fix(production): count the units a job still owes when serials are drawn at production
Raule0bd2431f30e
diff --git a/apps/erp/app/modules/inventory/inventory.service.ts b/apps/erp/app/modules/inventory/inventory.service.tsindex 199fe68ff4..e32d49c456 100644--- a/apps/erp/app/modules/inventory/inventory.service.ts+++ b/apps/erp/app/modules/inventory/inventory.service.ts@@ -23320,10 +23320,15 @@ export async function issueMaterial(.execute();// No `Operation ...` completion stamp — the unit did NOT complete// this operation; status is the terminal marker.+ // One unit is scrapped. An unsplit seed (serialNumberTiming =+ // 'production', or an item with no serial sequence) holds every unit+ // of the job, so it keeps one; the rest are spawned one at a time,+ // as after a serial completion.await trx.updateTable("trackedEntity").set({status: "Scrapped",+ quantity: 1,attributes: {...(entity.attributes as TrackedEntityAttributes),"Scrap Reason": scrapReasonIddiff --git a/apps/erp/app/modules/production/AGENTS.md b/apps/erp/app/modules/production/AGENTS.mdindex 99b2fcd9e8..f354fba81d 100644--- a/apps/erp/app/modules/production/AGENTS.md+++ b/apps/erp/app/modules/production/AGENTS.md@@ -40,7 +40,7 @@ Work orders (jobs), scheduling, routings (operations), bill of materials, proced- It **refuses** a quantity ≤ 0 or below what was already received (stocked items), and a fractional quantity on a serial job. Those raises reach the `jobOperation` UPDATE when they happen under the trigger — `sync_finish_job_operation` therefore clamps with `GREATEST(computed, received)` before calling.- The serial branch receives the delta one numbered unit at a time — shop-floor-finished (`Available`) first, then by `readableId` — skipping `Consumed`/`Rejected`/`Scrapped` and any unit with a `Job Receipt` ledger row for this job, so re-completion never double-receives. An item with **no serial sequence** never reaches `assign-serial-numbers`, so its job keeps one whole-quantity seed entity and the delta is received against that seed instead.- **Make to Asset branch.** A job with `fixedAssetClassId` completes into one new `fixedAsset` per unit (status `Active`, or `Under Construction` when the class `isConstructionInProgress`; `acquisitionCost` = swept WIP ÷ units; one Posted `fixedAssetTransfer` per asset, `type 'Capitalization'`, `sourceType 'Job'`); a job with `fixedAssetId` sweeps its WIP onto that Construction in Progress asset as one `fixedAssetCipCost` row + one transfer. The units never enter stock: no `itemLedger`, `costLedger`, `pickMethod` or `itemCost` write, and the WIP discharge posts Dr class `assetAccountId` / Cr WIP as an `'Asset Transfer'` journal (both lines still `documentId = jobId`, so the per-job WIP balance nets to zero). Each serial unit goes `Consumed` with `attributes["Fixed Asset"]` and a `'Capitalize'` `trackedActivity`; every company writes the asset cost (the journal is Provisional before the accounting cutover). Guards raise before anything moves: `'A job linked to a sales order line cannot complete to a fixed asset'`; `'A job that completes to a fixed asset class needs a serialized item'` (any quantity — every asset a class job makes is a fleet unit followed by its serial); `'Make to Asset needs a serialized item or a quantity of one'` (a job attached to an asset under construction); a job attached to a non-CIP asset is also refused (`'… is not in a Construction in Progress class'`). The item rule is `makeToAssetItemError` (`production.models.ts`), applied by `x+/job+/new.tsx` on save (a field error on the item), by `updateJobDetails` (the details form), by `setJobItem` on a property-panel item change and by `resumeJob` when a paused job goes back to `Ready`, with the sales order line gate. Covered by `packages/database/supabase/tests/job-completion-to-asset.test.sql`. Full flow: `.claude/rules/fixed-asset-lifecycle.md`.-- **Serial number timing** (`companySettings.serialNumberTiming`, Settings → Production → Serial Numbers). `jobCreation` (default): `assignJobSerialNumbers` splits and numbers every unit when the job is created. `production`: it is skipped, the job keeps its unnumbered seed, and a unit draws its number at its first touch through `assignSerialNumberIfMissing` (`@carbon/database/sequence`): the MES start (`start.$operationId.tsx`, `x+/event.tsx`, via `services/serial-number.server.ts`), the `issue` posting's serial completion, batch output and operation scrap, and the completion that receives it. A unit the serial completion or a scrap spawns stays unnumbered under `production`. Both completion paths call the SQL `number_serial_units_for_completion` (`20261021103400_serial-number-timing-completion.sql`) before `complete_job_to_inventory`: `completeJob` (through `numberSerialUnitsForCompletion`) and the `sync_finish_job_operation` interceptor (an operation marked Done). It takes the units the RPC will take, in its receipt or Make to Asset order, splits what is missing off the seed and numbers every unit taken, so no unnumbered lump is received. Every serial is formatted by the SQL `get_next_serial_numbers`, which `getNextSerialNumbers` calls. The Complete dialog unlocks the quantity for such a job (`getSerialCompleteChoice`, mode `numberOnReceipt`) and says the serials are drawn at receipt; under `jobCreation` it stays locked to what the shop floor finished.+- **Serial number timing** (`companySettings.serialNumberTiming`, Settings → Production → Serial Numbers). `jobCreation` (default): `assignJobSerialNumbers` splits and numbers every unit when the job is created. `production`: it is skipped, the job keeps its unnumbered seed, and a unit draws its number at its first touch through `assignSerialNumberIfMissing` (`@carbon/database/sequence`): the MES start (`start.$operationId.tsx`, `x+/event.tsx`, via `services/serial-number.server.ts`), the `issue` posting's serial completion, batch output and operation scrap, and the completion that receives it. A unit the serial completion or a scrap spawns stays unnumbered under `production`. Both completion paths call the SQL `number_serial_units_for_completion` (`20261021103400_serial-number-timing-completion.sql`) before `complete_job_to_inventory`: `completeJob` (through `numberSerialUnitsForCompletion`) and the `sync_finish_job_operation` interceptor (an operation marked Done). It takes the units the RPC will take, in its receipt or Make to Asset order, splits what is missing off the seed and numbers every unit taken, so no unnumbered lump is received. The shop floor's first completion or scrap of the seed leaves it holding one unit (a serial scrap takes one unit, never the whole seed) and spawns the next units one at a time, so the rows can hold fewer units than the job quantity: the function creates the units no row holds yet, up to the job quantity less the units in rows (a scrapped unit does not count), and the Complete dialog counts them as receivable. Every serial is formatted by the SQL `get_next_serial_numbers`, which `getNextSerialNumbers` calls. The Complete dialog unlocks the quantity for such a job (`getSerialCompleteChoice`, mode `numberOnReceipt`) and says the serials are drawn at receipt; under `jobCreation` it stays locked to what the shop floor finished.- Dialog logic lives in `ui/Jobs/job-complete-logic.ts` (pure, no JSX/lingui, unit-tested by `apps/erp/test/job-complete-logic.test.ts`); the SQL is covered by `packages/database/supabase/tests/job-completion-received-quantity.test.sql`, hand-run like its siblings (nothing in CI runs `supabase/tests/`).### Loaded operation and unattributed machine timediff --git a/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx b/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsxindex 0d91754b32..8f026ba936 100644--- a/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx+++ b/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx@@ -1529,7 +1529,8 @@ function JobCompleteModal({? getSerialCompleteChoice({trackedEntities: trackedEntities.data,receivedEntityIds: receipts ? receivedEntityIds : null,- serialNumberTiming+ serialNumberTiming,+ jobQuantity: job?.quantity ?? 0}): ({ mode: "locked" } as const);diff --git a/apps/erp/app/modules/production/ui/Jobs/job-complete-logic.ts b/apps/erp/app/modules/production/ui/Jobs/job-complete-logic.tsindex 893eba1dc0..2ec919f934 100644--- a/apps/erp/app/modules/production/ui/Jobs/job-complete-logic.ts+++ b/apps/erp/app/modules/production/ui/Jobs/job-complete-logic.ts@@ -84,8 +84,9 @@ export function getReceivableSerialUnits(* - `serials`: every unit left to receive is a numbered single unit, so the* dialog lists the serials a completion takes (either timing).* - `numberOnReceipt`: the company numbers serials at production- * (`serialNumberTiming = 'production'`) and some units are unnumbered or- * still one unsplit seed. The completion numbers the units it receives+ * (`serialNumberTiming = 'production'`) and some units are unnumbered, still+ * one unsplit seed, or held by no row yet. The completion numbers the units+ * it receives and creates the missing ones* (`number_serial_units_for_completion`), so the quantity can be chosen up to* `receivableCount` even though the serials cannot be named yet.* - `locked`: the quantity stays what the shop floor finished — the default@@ -99,24 +100,44 @@ export type SerialCompleteChoice =export function getSerialCompleteChoice({trackedEntities,receivedEntityIds,- serialNumberTiming+ serialNumberTiming,+ jobQuantity}: {trackedEntities: JobSerialUnit[];/** Null when the job's receipts could not be read. */receivedEntityIds: ReadonlySet<string> | null;serialNumberTiming: "jobCreation" | "production";+ jobQuantity: number;}): SerialCompleteChoice {// Without the receipts the dialog could offer a unit the job already// received, whatever the timing.if (!receivedEntityIds) return { mode: "locked" };+ // The shop floor's first completion or scrap of an unsplit seed leaves it+ // holding one unit and spawns the rest one at a time, so the rows can hold+ // fewer units than the job quantity. Only a completion under the production+ // timing creates the missing units. A scrapped unit does not count: the job+ // still owes it.+ const unitsWithoutRow =+ serialNumberTiming === "production"+ ? Math.max(+ jobQuantity -+ trackedEntities+ .filter((entity) => entity.status !== "Scrapped")+ .reduce((total, entity) => total + Number(entity.quantity), 0),+ 0+ )+ : 0;+const serials = getReceivableSerialUnits(trackedEntities, receivedEntityIds);- if (serials) return { mode: "serials", serials };+ if (serials && unitsWithoutRow === 0) return { mode: "serials", serials };if (serialNumberTiming !== "production") return { mode: "locked" };- const receivableCount = trackedEntities- .filter((entity) => isUnreceived(entity, receivedEntityIds))- .reduce((total, entity) => total + Number(entity.quantity), 0);+ const receivableCount =+ trackedEntities+ .filter((entity) => isUnreceived(entity, receivedEntityIds))+ .reduce((total, entity) => total + Number(entity.quantity), 0) ++ unitsWithoutRow;return receivableCount > 0? { mode: "numberOnReceipt", receivableCount }: { mode: "locked" };diff --git a/apps/erp/test/database/serial-number-timing.test.ts b/apps/erp/test/database/serial-number-timing.test.tsindex 7ce4564cf8..45a08d9f70 100644--- a/apps/erp/test/database/serial-number-timing.test.ts+++ b/apps/erp/test/database/serial-number-timing.test.ts@@ -16,8 +16,10 @@ import {import { now } from "@internationalized/date";import { sql } from "kysely";import { describe, expect, it } from "vitest";+import { issueMaterial as issue } from "../../app/modules/inventory/inventory.service";import { completeJob } from "../../app/modules/production/production.server";import { numberSerialUnitsForCompletion } from "../../app/modules/production/production.service";+import { invokePosting } from "../../app/modules/shared/shared.service";import {alwaysPostFixture,type Fixture,@@ -25,8 +27,10 @@ import {seed,stockPart,TIME_ZONE,- USER+ USER,+ unwrap} from "./fixtures/always-post";+import { handlesOf } from "./fixtures/handles";import { hasLocalDatabase } from "./fixtures/local-database";import { localServiceRoleClient } from "./fixtures/local-supabase";@@ -269,6 +273,107 @@ describe.skipIf(!client)("serial number timing", () => {}});+ it("creates the units no row holds when a completion follows the shop floor", async () => {+ const f = await alwaysPostFixture();+ try {+ await stockPart(f, 20);+ await serialSetup(f, "production");+ const job = await untouchedSerialJob(f, "6", 3);+ const [seedUnit] = await units(f, job.makeMethodId);++ // The shop floor completes one unit: the seed keeps one unit and the+ // next is spawned, so the rows hold two of the job's three units.+ unwrap(+ await invokePosting(+ handlesOf(f.ctx),+ "issue",+ {+ type: "jobOperationSerialComplete",+ trackedEntityId: seedUnit!.id,+ quantity: 1,+ jobOperationId: job.operationId+ },+ issue+ )+ );+ expect(await units(f, job.makeMethodId)).toEqual([+ expect.objectContaining({ readableId: "SN-001", quantity: 1 }),+ expect.objectContaining({ readableId: null, quantity: 1 })+ ]);++ const result = await completeJob(contextFor(f), {+ jobId: job.jobId,+ quantityComplete: 3+ });+ expect(result.error).toBeNull();++ expect(await receivedUnits(f, job.jobId)).toEqual([+ { readableId: "SN-001", quantity: 1 },+ { readableId: "SN-002", quantity: 1 },+ { readableId: "SN-003", quantity: 1 }+ ]);+ expect(await units(f, job.makeMethodId)).toHaveLength(3);+ } finally {+ await f.cleanup();+ }+ });++ it("scraps one unit of an unsplit seed, and the job still owes it", async () => {+ const f = await alwaysPostFixture();+ try {+ await stockPart(f, 20);+ await serialSetup(f, "production");+ const job = await untouchedSerialJob(f, "7", 3);+ const [seedUnit] = await units(f, job.makeMethodId);+ const scrapReason = await f.db+ .insertInto("scrapReason")+ .values({ name: "Damaged", companyId: f.companyId, createdBy: USER })+ .returning("id")+ .executeTakeFirstOrThrow();++ unwrap(+ await invokePosting(+ handlesOf(f.ctx),+ "issue",+ {+ type: "jobOperationScrap",+ jobOperationId: job.operationId,+ quantity: 1,+ scrapReasonId: scrapReason.id,+ trackedEntityId: seedUnit!.id+ },+ issue+ )+ );+ expect(await units(f, job.makeMethodId)).toEqual([+ expect.objectContaining({+ readableId: "SN-001",+ quantity: 1,+ status: "Scrapped"+ }),+ expect.objectContaining({+ readableId: null,+ quantity: 1,+ status: "Reserved"+ })+ ]);++ const result = await completeJob(contextFor(f), {+ jobId: job.jobId,+ quantityComplete: 3+ });+ expect(result.error).toBeNull();++ expect(await receivedUnits(f, job.jobId)).toEqual([+ { readableId: "SN-002", quantity: 1 },+ { readableId: "SN-003", quantity: 1 },+ { readableId: "SN-004", quantity: 1 }+ ]);+ } finally {+ await f.cleanup();+ }+ });+it("numbers and receives untouched units when the last operation is marked Done", async () => {const f = await alwaysPostFixture();try {diff --git a/apps/erp/test/job-complete-logic.test.ts b/apps/erp/test/job-complete-logic.test.tsindex bb03f97b2d..e952515f97 100644--- a/apps/erp/test/job-complete-logic.test.ts+++ b/apps/erp/test/job-complete-logic.test.ts@@ -178,7 +178,8 @@ describe("getSerialCompleteChoice", () => {getSerialCompleteChoice({trackedEntities: units,receivedEntityIds: none,- serialNumberTiming+ serialNumberTiming,+ jobQuantity: 2})).toEqual({ mode: "serials", serials: ["SN-0001", "SN-0002"] });}@@ -189,7 +190,8 @@ describe("getSerialCompleteChoice", () => {getSerialCompleteChoice({trackedEntities: [seed],receivedEntityIds: none,- serialNumberTiming: "jobCreation"+ serialNumberTiming: "jobCreation",+ jobQuantity: 3})).toEqual({ mode: "locked" });});@@ -199,7 +201,8 @@ describe("getSerialCompleteChoice", () => {getSerialCompleteChoice({trackedEntities: [seed],receivedEntityIds: none,- serialNumberTiming: "production"+ serialNumberTiming: "production",+ jobQuantity: 3})).toEqual({ mode: "numberOnReceipt", receivableCount: 3 });});@@ -216,14 +219,16 @@ describe("getSerialCompleteChoice", () => {getSerialCompleteChoice({trackedEntities: units,receivedEntityIds: new Set(["received"]),- serialNumberTiming: "production"+ serialNumberTiming: "production",+ jobQuantity: 4})).toEqual({ mode: "numberOnReceipt", receivableCount: 2 });expect(getSerialCompleteChoice({trackedEntities: units,receivedEntityIds: new Set(["received"]),- serialNumberTiming: "jobCreation"+ serialNumberTiming: "jobCreation",+ jobQuantity: 4})).toEqual({ mode: "locked" });});@@ -233,7 +238,8 @@ describe("getSerialCompleteChoice", () => {getSerialCompleteChoice({trackedEntities: [seed],receivedEntityIds: null,- serialNumberTiming: "production"+ serialNumberTiming: "production",+ jobQuantity: 3})).toEqual({ mode: "locked" });});@@ -243,8 +249,71 @@ describe("getSerialCompleteChoice", () => {getSerialCompleteChoice({trackedEntities: [unit({ id: "received", status: "Available" })],receivedEntityIds: new Set(["received"]),- serialNumberTiming: "production"+ serialNumberTiming: "production",+ jobQuantity: 1})).toEqual({ mode: "locked" });});++ it("counts the units no row holds yet after the shop floor worked the seed", () => {+ // The first completion left the seed holding one unit and spawned one more.+ const units = [+ unit({ id: "done", status: "Available", readableId: "SN-0001" }),+ unit({ id: "spawned", status: "Reserved" })+ ];+ expect(+ getSerialCompleteChoice({+ trackedEntities: units,+ receivedEntityIds: none,+ serialNumberTiming: "production",+ jobQuantity: 3+ })+ ).toEqual({ mode: "numberOnReceipt", receivableCount: 3 });+ expect(+ getSerialCompleteChoice({+ trackedEntities: units,+ receivedEntityIds: none,+ serialNumberTiming: "jobCreation",+ jobQuantity: 3+ })+ ).toEqual({ mode: "locked" });+ });++ it("does not list the serials while units are still missing at production", () => {+ const units = [+ unit({ id: "done", status: "Available", readableId: "SN-0001" }),+ unit({ id: "started", status: "Reserved", readableId: "SN-0002" })+ ];+ expect(+ getSerialCompleteChoice({+ trackedEntities: units,+ receivedEntityIds: none,+ serialNumberTiming: "production",+ jobQuantity: 3+ })+ ).toEqual({ mode: "numberOnReceipt", receivableCount: 3 });+ expect(+ getSerialCompleteChoice({+ trackedEntities: units,+ receivedEntityIds: none,+ serialNumberTiming: "jobCreation",+ jobQuantity: 3+ })+ ).toEqual({ mode: "serials", serials: ["SN-0001", "SN-0002"] });+ });++ it("still owes a scrapped unit", () => {+ const units = [+ unit({ id: "scrapped", status: "Scrapped", readableId: "SN-0001" }),+ unit({ id: "replacement", status: "Reserved" })+ ];+ expect(+ getSerialCompleteChoice({+ trackedEntities: units,+ receivedEntityIds: none,+ serialNumberTiming: "production",+ jobQuantity: 3+ })+ ).toEqual({ mode: "numberOnReceipt", receivableCount: 3 });+ });});diff --git a/apps/mes/app/components/JobOperation/JobOperation.tsx b/apps/mes/app/components/JobOperation/JobOperation.tsxindex 2f29acf090..992c805029 100644--- a/apps/mes/app/components/JobOperation/JobOperation.tsx+++ b/apps/mes/app/components/JobOperation/JobOperation.tsx@@ -2131,9 +2131,16 @@ export const JobOperation = ({</span></>) : (- <span className="font-mono truncate">- {entity.id}- </span>+ <>+ <span className="font-medium text-muted-foreground truncate">+ <Trans>+ No serial number yet+ </Trans>+ </span>+ <span className="text-xs text-muted-foreground font-mono truncate">+ {entity.id}+ </span>+ </>)}</div>{entity.id === trackedEntityId && (diff --git a/packages/database/supabase/migrations/20261021103400_serial-number-timing-completion.sql b/packages/database/supabase/migrations/20261021103400_serial-number-timing-completion.sqlindex 02bb60aada..81047ef1ec 100644--- a/packages/database/supabase/migrations/20261021103400_serial-number-timing-completion.sql+++ b/packages/database/supabase/migrations/20261021103400_serial-number-timing-completion.sql@@ -116,6 +116,12 @@ $function$;-- is 'jobCreation', the item is not serial-tracked or has no sequence, or the-- job cannot cover the completion (the completion then refuses with its own-- message).+--+-- A unit can also have no row at all. The shop floor's first completion or+-- scrap of the seed leaves it holding one unit and adds the next units one at a+-- time, so after it the rows cover fewer units than the job quantity. Those+-- units are created here, up to the job quantity less the units already in+-- rows (a scrapped unit does not count: the job still owes it).CREATE OR REPLACE FUNCTION public.number_serial_units_for_completion(p_job_id text,p_quantity_complete numeric,@@ -135,8 +141,12 @@ DECLAREv_to_number text[];v_short integer;v_seed record;+ v_from_seed integer := 0;v_new_units integer := 0;v_seed_becomes_unit boolean := false;+ v_missing integer := 0;+ v_unstarted numeric;+ v_template record;v_count integer;v_serials text[];v_location record;@@ -150,7 +160,7 @@ BEGINRETURN 0;END IF;- SELECT j."itemId", j."quantityReceivedToInventory", j."fixedAssetClassId",+ SELECT j."itemId", j.quantity, j."quantityReceivedToInventory", j."fixedAssetClassId",j."fixedAssetId", j."locationId", i."itemTrackingType"INTO v_jobFROM "job" j@@ -267,17 +277,42 @@ BEGINAND te.quantity > 1ORDER BY te."createdAt"LIMIT 1;- IF NOT FOUND OR v_seed.quantity < v_short THEN- RETURN 0;+ IF FOUND THEN+ v_from_seed := LEAST(v_short, v_seed.quantity::integer);+ v_seed_becomes_unit := v_seed.quantity = v_from_seed;+ v_new_units := CASE WHEN v_seed_becomes_unit THEN v_from_seed - 1 ELSE v_from_seed END;+ IF v_seed_becomes_unit AND v_seed."readableId" IS NULL THEN+ v_to_number := v_to_number || v_seed."id";+ END IF;END IF;- v_seed_becomes_unit := v_seed.quantity = v_short;- v_new_units := CASE WHEN v_seed_becomes_unit THEN v_short - 1 ELSE v_short END;- IF v_seed_becomes_unit AND v_seed."readableId" IS NULL THEN- v_to_number := v_to_number || v_seed."id";++ -- Units no row holds yet.+ v_missing := v_short - v_from_seed;+ IF v_missing > 0 THEN+ SELECT v_job.quantity - COALESCE(SUM(te.quantity), 0)+ INTO v_unstarted+ FROM "trackedEntity" te+ WHERE te.attributes->>'Job Make Method' = v_make_method."id"+ AND te."companyId" = p_company_id+ AND te.status <> 'Scrapped';+ IF v_unstarted < v_missing THEN+ RETURN 0;+ END IF;++ SELECT *+ INTO v_template+ FROM "trackedEntity" te+ WHERE te.attributes->>'Job Make Method' = v_make_method."id"+ AND te."companyId" = p_company_id+ ORDER BY te."createdAt", te."id"+ LIMIT 1;+ IF NOT FOUND THEN+ RETURN 0;+ END IF;END IF;END IF;- v_count := COALESCE(array_length(v_to_number, 1), 0) + v_new_units;+ v_count := COALESCE(array_length(v_to_number, 1), 0) + v_new_units + v_missing;IF v_count = 0 THENRETURN 0;END IF;@@ -307,7 +342,7 @@ BEGINAND te."readableId" IS NULL;END IF;- IF v_short > 0 THEN+ IF v_from_seed > 0 THENUPDATE "trackedEntity"SET quantity = CASE WHEN v_seed_becomes_unit THEN 1 ELSE v_seed.quantity - v_new_units ENDWHERE "id" = v_seed."id"@@ -329,6 +364,23 @@ BEGINFROM generate_series(1, v_new_units) AS n;END IF;+ IF v_missing > 0 THEN+ INSERT INTO "trackedEntity" (+ "createdAt", "sourceDocument", "sourceDocumentId", "sourceDocumentReadableId",+ quantity, status, attributes, "itemId", "readableId",+ "companyId", "createdBy"+ )+ SELECT+ now() + (v_new_units + n) * interval '1 millisecond',+ v_template."sourceDocument", v_template."sourceDocumentId", v_template."sourceDocumentReadableId",+ 1, 'Reserved'::"trackedEntityStatus",+ jsonb_build_object('Job', p_job_id, 'Job Make Method', v_make_method."id"),+ v_job."itemId",+ v_serials[COALESCE(array_length(v_to_number, 1), 0) + v_new_units + n],+ p_company_id, v_template."createdBy"+ FROM generate_series(1, v_missing) AS n;+ END IF;+RETURN v_count;END;$function$;diff --git a/packages/locale/locales/de/mes.po b/packages/locale/locales/de/mes.poindex 7076762efa..81524c4042 100644--- a/packages/locale/locales/de/mes.po+++ b/packages/locale/locales/de/mes.po@@ -1238,6 +1238,9 @@ msgstr "Keine Proben erforderlich."msgid "No scheduled time"msgstr "Keine geplante Zeit"+msgid "No serial number yet"+msgstr "Noch keine Seriennummer"+msgid "No serial numbers"msgstr "Keine Seriennummern"diff --git a/packages/locale/locales/en/mes.po b/packages/locale/locales/en/mes.poindex d439670c66..8b291e1924 100644--- a/packages/locale/locales/en/mes.po+++ b/packages/locale/locales/en/mes.po@@ -1238,6 +1238,9 @@ msgstr "No samples required."msgid "No scheduled time"msgstr "No scheduled time"+msgid "No serial number yet"+msgstr "No serial number yet"+msgid "No serial numbers"msgstr "No serial numbers"diff --git a/packages/locale/locales/es/mes.po b/packages/locale/locales/es/mes.poindex 8ea773c95c..75dab2a30f 100644--- a/packages/locale/locales/es/mes.po+++ b/packages/locale/locales/es/mes.po@@ -1238,6 +1238,9 @@ msgstr "No se requieren muestras."msgid "No scheduled time"msgstr "Sin tiempo programado"+msgid "No serial number yet"+msgstr "Aún sin número de serie"+msgid "No serial numbers"msgstr "Sin números de serie"diff --git a/packages/locale/locales/fr/mes.po b/packages/locale/locales/fr/mes.poindex 4ac4df80f4..d6809fbe3c 100644--- a/packages/locale/locales/fr/mes.po+++ b/packages/locale/locales/fr/mes.po@@ -1238,6 +1238,9 @@ msgstr "Aucun échantillon requis."msgid "No scheduled time"msgstr "Aucun horaire planifié"+msgid "No serial number yet"+msgstr "Pas encore de numéro de série"+msgid "No serial numbers"msgstr "Aucun numéro de série"diff --git a/packages/locale/locales/hi/mes.po b/packages/locale/locales/hi/mes.poindex 3860d69d63..d78dbad02b 100644--- a/packages/locale/locales/hi/mes.po+++ b/packages/locale/locales/hi/mes.po@@ -1238,6 +1238,9 @@ msgstr "कोई नमूना आवश्यक नहीं है।"msgid "No scheduled time"msgstr "कोई निर्धारित समय नहीं"+msgid "No serial number yet"+msgstr "अभी तक कोई सीरियल नंबर नहीं"+msgid "No serial numbers"msgstr "कोई सीरियल नंबर नहीं"diff --git a/packages/locale/locales/it/mes.po b/packages/locale/locales/it/mes.poindex 635a065b6a..300aa967c2 100644--- a/packages/locale/locales/it/mes.po+++ b/packages/locale/locales/it/mes.po@@ -1238,6 +1238,9 @@ msgstr "Nessun campione richiesto."msgid "No scheduled time"msgstr "Nessun orario programmato"+msgid "No serial number yet"+msgstr "Ancora nessun numero di serie"+msgid "No serial numbers"msgstr "Nessun numero di serie"diff --git a/packages/locale/locales/ja/mes.po b/packages/locale/locales/ja/mes.poindex 5b5f92a271..f6395c8eab 100644--- a/packages/locale/locales/ja/mes.po+++ b/packages/locale/locales/ja/mes.po@@ -1238,6 +1238,9 @@ msgstr "サンプルは必要ありません。"msgid "No scheduled time"msgstr "予定時間なし"+msgid "No serial number yet"+msgstr "シリアル番号はまだありません"+msgid "No serial numbers"msgstr "シリアル番号なし"diff --git a/packages/locale/locales/ko/mes.po b/packages/locale/locales/ko/mes.poindex c9c1390477..1280829f9b 100644--- a/packages/locale/locales/ko/mes.po+++ b/packages/locale/locales/ko/mes.po@@ -1238,6 +1238,9 @@ msgstr "필요한 샘플이 없습니다."msgid "No scheduled time"msgstr "예정된 시간 없음"+msgid "No serial number yet"+msgstr "아직 일련번호 없음"+msgid "No serial numbers"msgstr "시리얼 번호 없음"diff --git a/packages/locale/locales/pl/mes.po b/packages/locale/locales/pl/mes.poindex 504a601db7..24da2f9a24 100644--- a/packages/locale/locales/pl/mes.po+++ b/packages/locale/locales/pl/mes.po@@ -1238,6 +1238,9 @@ msgstr "Nie wymagane żadne próbki."msgid "No scheduled time"msgstr "Brak zaplanowanego czasu"+msgid "No serial number yet"+msgstr "Jeszcze bez numeru seryjnego"+msgid "No serial numbers"msgstr "Brak numerów seryjnych"diff --git a/packages/locale/locales/pt/mes.po b/packages/locale/locales/pt/mes.poindex 353e8f9104..32405a98e3 100644--- a/packages/locale/locales/pt/mes.po+++ b/packages/locale/locales/pt/mes.po@@ -1238,6 +1238,9 @@ msgstr "Nenhuma amostra necessária."msgid "No scheduled time"msgstr "Nenhum horário programado"+msgid "No serial number yet"+msgstr "Ainda sem número de série"+msgid "No serial numbers"msgstr "Nenhum número de série"diff --git a/packages/locale/locales/ru/mes.po b/packages/locale/locales/ru/mes.poindex 669bfa7310..705554af61 100644--- a/packages/locale/locales/ru/mes.po+++ b/packages/locale/locales/ru/mes.po@@ -1238,6 +1238,9 @@ msgstr "Образцы не требуются."msgid "No scheduled time"msgstr "Нет запланированного времени"+msgid "No serial number yet"+msgstr "Серийный номер ещё не присвоен"+msgid "No serial numbers"msgstr "Нет серийных номеров"diff --git a/packages/locale/locales/tr/mes.po b/packages/locale/locales/tr/mes.poindex 8aba09424d..95dc06df39 100644--- a/packages/locale/locales/tr/mes.po+++ b/packages/locale/locales/tr/mes.po@@ -1238,6 +1238,9 @@ msgstr "Örnek gerekli değil."msgid "No scheduled time"msgstr "Planlanmış zaman yok"+msgid "No serial number yet"+msgstr "Henüz seri numarası yok"+msgid "No serial numbers"msgstr "Seri numarası yok"diff --git a/packages/locale/locales/zh/mes.po b/packages/locale/locales/zh/mes.poindex 8f4c7b0bf0..283aa435f9 100644--- a/packages/locale/locales/zh/mes.po+++ b/packages/locale/locales/zh/mes.po@@ -1238,6 +1238,9 @@ msgstr "不需要样本。"msgid "No scheduled time"msgstr "无排定时间"+msgid "No serial number yet"+msgstr "尚无序列号"+msgid "No serial numbers"msgstr "无序列号"