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
feat: disable release of job if no operations exist for a given asssmebly
Brad Barbin3f1ce5d88189
diff --git a/apps/carbon/app/modules/production/ui/Jobs/JobHeader.tsx b/apps/carbon/app/modules/production/ui/Jobs/JobHeader.tsxindex 9ccfc3d4e7..aeda8e23f4 100644--- a/apps/carbon/app/modules/production/ui/Jobs/JobHeader.tsx+++ b/apps/carbon/app/modules/production/ui/Jobs/JobHeader.tsx@@ -1,4 +1,7 @@import {+ Alert,+ AlertDescription,+ AlertTitle,Button,DropdownMenu,DropdownMenuContent,@@ -17,12 +20,18 @@ import {ModalFooter,ModalHeader,ModalTitle,+ Spinner,useDisclosure,+ useMount,} from "@carbon/react";+import { useCarbon } from "@carbon/auth";import type { FetcherWithComponents } from "@remix-run/react";import { Link, useFetcher, useNavigate, useParams } from "@remix-run/react";+import { useState } from "react";+import { flushSync } from "react-dom";import {+ LuAlertTriangle,LuChevronDown,LuClock,LuHardHat,@@ -343,6 +352,55 @@ function JobStartModal({fetcher: FetcherWithComponents<{}>;onClose: () => void;}) {+ const { carbon } = useCarbon();+ const [loading, setLoading] = useState(true);+ const [eachAssemblyHasAnOperation, setEachAssemblyHasAnOperation] =+ useState(false);++ const validate = async () => {+ if (!carbon || !job) return;+ const [makeMethod, materials, operations] = await Promise.all([+ carbon+ .from("jobMakeMethod")+ .select("*")+ .eq("jobId", job.id!)+ .is("parentMaterialId", null)+ .single(),+ carbon+ .from("jobMaterialWithMakeMethodId")+ .select("*")+ .eq("jobId", job.id!),+ carbon.from("jobOperation").select("*").eq("jobId", job.id!),+ ]);++ // make methods for materials+ const uniqueMakeMethodIds = new Set(+ materials.data+ ?.filter((m) => m.jobMaterialMakeMethodId && m.methodType === "Make")+ .map((m) => m.jobMaterialMakeMethodId) ?? []+ );++ // top-level make method+ uniqueMakeMethodIds.add(makeMethod.data?.id!);++ flushSync(() => {+ setEachAssemblyHasAnOperation(+ Array.from(uniqueMakeMethodIds).every(+ (makeMethodId) =>+ operations.data?.some(+ (op) => op.jobMakeMethodId === makeMethodId+ ) ?? false+ )+ );+ });++ setLoading(false);+ };++ useMount(() => {+ validate();+ });+if (!job) return null;return (@@ -358,29 +416,56 @@ function JobStartModal({<ModalHeader><ModalTitle>Start {job?.jobId}</ModalTitle></ModalHeader>- <ModalBody>- Are you sure you want to start this job? It will become available to- the shop floor.- </ModalBody>- <ModalFooter>- <Button variant="secondary" onClick={onClose}>- Cancel- </Button>- <fetcher.Form- onSubmit={onClose}- method="post"- action={`${path.to.jobStatus(job.id!)}?schedule=1`}- >- <input type="hidden" name="status" value="Ready" />- <Button- isLoading={fetcher.state !== "idle"}- isDisabled={fetcher.state !== "idle"}- type="submit"- >- Release Job- </Button>- </fetcher.Form>- </ModalFooter>+ {loading ? (+ <ModalBody>+ <div className="flex flex-col h-[118px] w-full items-center justify-center gap-2">+ <Spinner className="size-8" />+ <p className="text-sm">Validating job...</p>+ </div>+ </ModalBody>+ ) : (+ <>+ <ModalBody>+ {eachAssemblyHasAnOperation ? (+ <p>+ Are you sure you want to start this job? It will become+ available to the shop floor.+ </p>+ ) : (+ <Alert variant="warning">+ <LuAlertTriangle />+ <AlertTitle>Missing Operations</AlertTitle>+ <AlertDescription>+ There are Bills of Processes associated with this job that+ have no operations. Please assign an operation to each make+ method before releasing it.+ </AlertDescription>+ </Alert>+ )}+ </ModalBody>+ <ModalFooter>+ <Button variant="secondary" onClick={onClose}>+ Cancel+ </Button>+ <fetcher.Form+ onSubmit={onClose}+ method="post"+ action={`${path.to.jobStatus(job.id!)}?schedule=1`}+ >+ <input type="hidden" name="status" value="Ready" />+ <Button+ isLoading={fetcher.state !== "idle"}+ isDisabled={+ fetcher.state !== "idle" || !eachAssemblyHasAnOperation+ }+ type="submit"+ >+ Release Job+ </Button>+ </fetcher.Form>+ </ModalFooter>+ </>+ )}</ModalContent></Modal>);diff --git a/packages/database/supabase/functions/lib/scheduling/material-manager.ts b/packages/database/supabase/functions/lib/scheduling/material-manager.tsindex 5d5800b3e3..69ea20954c 100644--- a/packages/database/supabase/functions/lib/scheduling/material-manager.ts+++ b/packages/database/supabase/functions/lib/scheduling/material-manager.ts@@ -16,15 +16,22 @@ class MaterialManager {throw new Error("Database connection is not initialized");}- const materialToAssign = await this.db- .selectFrom("jobMaterial")- .selectAll()- .where("jobId", "=", jobId)- .where("jobOperationId", "is", null)- .where("companyId", "=", this.companyId)- .execute();+ const [materialToAssign, jobOperations] = await Promise.all([+ this.db+ .selectFrom("jobMaterial")+ .selectAll()+ .where("jobId", "=", jobId)+ .where("jobOperationId", "is", null)+ .where("companyId", "=", this.companyId)+ .execute(),+ this.db+ .selectFrom("jobOperation")+ .selectAll()+ .where("jobId", "=", jobId)+ .execute(),+ ]);- console.log({ materialToAssign });+ console.log({ materialToAssign, jobOperations });}}diff --git a/packages/database/supabase/functions/scheduler/index.ts b/packages/database/supabase/functions/scheduler/index.tsindex db675e3bfc..4f197d490d 100644--- a/packages/database/supabase/functions/scheduler/index.ts+++ b/packages/database/supabase/functions/scheduler/index.ts@@ -4,7 +4,6 @@ import { z } from "https://deno.land/x/[email protected]/mod.ts";import { DB, getConnectionPool, getDatabaseClient } from "../lib/database.ts";import { corsHeaders } from "../lib/headers.ts";import { SchedulingEngine } from "../lib/scheduling/engine.ts";-import { SchedulingStrategy } from "../lib/scheduling/types.ts";import { getSupabaseServiceRoleFromAuthorizationHeader } from "../lib/supabase.ts";const pool = getConnectionPool(1);@@ -40,7 +39,7 @@ serve(async (req: Request) => {const engine = new SchedulingEngine({ client, db, jobId, companyId });await engine.initialize();- await engine.prioritize(SchedulingStrategy.LeastTime);+ // await engine.prioritize(SchedulingStrategy.LeastTime);return new Response(JSON.stringify({