Skip to content

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.

feat: support custom barcodes for completing

Brad Barbincea50078eae5
diff --git a/apps/erp/app/modules/settings/ui/Integrations/IntegrationsList.tsx b/apps/erp/app/modules/settings/ui/Integrations/IntegrationsList.tsx
index afca988853..014177cfc7 100644
--- a/apps/erp/app/modules/settings/ui/Integrations/IntegrationsList.tsx
+++ b/apps/erp/app/modules/settings/ui/Integrations/IntegrationsList.tsx
@@ -86,10 +86,14 @@ function IntegrationCard({
<integration.logo className="h-10 w-auto" />
{integration.active ? (
installed ? (
- <Badge variant="green">Installed</Badge>
+ <Badge variant="green" className="flex-shrink-0">
+ Installed
+ </Badge>
) : null
) : (
- <Badge variant="secondary">Coming soon</Badge>
+ <Badge variant="secondary" className="flex-shrink-0">
+ Coming soon
+ </Badge>
)}
</div>
<CardHeader className="pb-0">
diff --git a/apps/mes/app/components/JobOperation.tsx b/apps/mes/app/components/JobOperation.tsx
index 94e52699ab..9191832359 100644
--- a/apps/mes/app/components/JobOperation.tsx
+++ b/apps/mes/app/components/JobOperation.tsx
@@ -105,6 +105,7 @@ import type {
JobMaterial,
JobOperationAttribute,
JobOperationParameter,
+ Kanban,
OperationWithDetails,
ProductionEvent,
ProductionQuantity,
@@ -114,6 +115,7 @@ import type {
} from "~/services/types";
import { path } from "~/utils/path";
+import type { Result } from "@carbon/auth";
import { useCarbon } from "@carbon/auth";
import {
Combobox,
@@ -202,6 +204,7 @@ import ScrapReason from "./ScrapReason";
type JobOperationProps = {
events: ProductionEvent[];
files: Promise<StorageItem[]>;
+ kanban: Kanban | null;
materials: Promise<{
materials: JobMaterial[];
trackedInputs: TrackedInput[];
@@ -222,6 +225,7 @@ export const JobOperation = ({
events,
files,
job,
+ kanban,
materials,
method,
operation: originalOperation,
@@ -370,12 +374,20 @@ export const JobOperation = ({
}
};
- const completeFetcher = useFetcher<{}>();
+ const completeFetcher = useFetcher<Result>();
useKeyboardWedge({
- test: (input) => input === "x",
+ test: (input) => {
+ if (kanban?.completedBarcodeOverride) {
+ return input === kanban.completedBarcodeOverride;
+ } else if (kanban?.id) {
+ return input === path.to.kanbanComplete(kanban.id);
+ }
+ return false;
+ },
callback: () => {
completeFetcher.load(path.to.endOperation(operation.id));
},
+ active: !!kanban?.id,
});
return (
diff --git a/apps/mes/app/routes/_index.tsx b/apps/mes/app/routes/_index.tsx
index b6351f7e23..66e42780e6 100644
--- a/apps/mes/app/routes/_index.tsx
+++ b/apps/mes/app/routes/_index.tsx
@@ -4,6 +4,7 @@ import { path } from "~/utils/path";
export async function loader({ request }: LoaderFunctionArgs) {
await requireAuthSession(request);
+
throw redirect(path.to.authenticatedRoot);
}
diff --git a/apps/mes/app/routes/x+/complete.tsx b/apps/mes/app/routes/x+/complete.tsx
index 5860c05e8f..84a8962bdc 100644
--- a/apps/mes/app/routes/x+/complete.tsx
+++ b/apps/mes/app/routes/x+/complete.tsx
@@ -93,7 +93,7 @@ export async function action({ request }: ActionFunctionArgs) {
);
}
- throw redirect(
+ return redirect(
path.to.operations,
await flash(request, {
...success("Operation finished successfully"),
@@ -103,14 +103,14 @@ export async function action({ request }: ActionFunctionArgs) {
}
if (trackedEntityId) {
- throw redirect(
+ return redirect(
`${path.to.operation(
validation.data.jobOperationId
)}?trackedEntityId=${trackedEntityId}`
);
}
- throw redirect(`${path.to.operation(validation.data.jobOperationId)}`);
+ return redirect(`${path.to.operation(validation.data.jobOperationId)}`);
} else if (validation.data.trackingType === "Batch") {
const serviceRole = await getCarbonServiceRole();
const response = await serviceRole.functions.invoke("issue", {
@@ -149,7 +149,7 @@ export async function action({ request }: ActionFunctionArgs) {
);
}
- throw redirect(
+ return redirect(
path.to.operations,
await flash(request, {
...success("Operation finished successfully"),
@@ -158,7 +158,7 @@ export async function action({ request }: ActionFunctionArgs) {
);
}
- throw redirect(`${path.to.operation(validation.data.jobOperationId)}`);
+ return redirect(`${path.to.operation(validation.data.jobOperationId)}`);
} else {
const { trackedEntityId, trackingType, ...data } = validation.data;
const insertProduction = await insertProductionQuantity(client, {
@@ -217,7 +217,7 @@ export async function action({ request }: ActionFunctionArgs) {
);
}
- throw redirect(
+ return redirect(
path.to.operations,
await flash(request, {
...success("Operation finished successfully"),
@@ -229,7 +229,7 @@ export async function action({ request }: ActionFunctionArgs) {
return json(
insertProduction.data,
await flash(request, {
- ...success("Production quantity recorded successfully"),
+ ...success("Successfully completed part"),
flash: "success",
})
);
diff --git a/apps/mes/app/routes/x+/end.$operationId.tsx b/apps/mes/app/routes/x+/end.$operationId.tsx
index f46bd23808..c7e145aadd 100644
--- a/apps/mes/app/routes/x+/end.$operationId.tsx
+++ b/apps/mes/app/routes/x+/end.$operationId.tsx
@@ -2,7 +2,7 @@ import { error, getCarbonServiceRole, success } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { FunctionRegion } from "@supabase/supabase-js";
-import { json, redirect, type LoaderFunctionArgs } from "@vercel/remix";
+import { redirect, type LoaderFunctionArgs } from "@vercel/remix";
import {
finishJobOperation,
getTrackedEntitiesByMakeMethodId,
@@ -18,7 +18,6 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
const url = new URL(request.url);
let trackedEntityId = url.searchParams.get("trackedEntityId");
-
const serviceRole = await getCarbonServiceRole();
const [jobOperation, productionQuantities] = await Promise.all([
@@ -39,7 +38,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
!jobOperation.data ||
!jobOperation.data.jobMakeMethodId
) {
- throw redirect(
+ return redirect(
path.to.operations,
await flash(request, {
...error(jobOperation.error, "Failed to fetch job operation"),
@@ -49,7 +48,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
}
if (jobOperation.data?.companyId !== companyId) {
- throw redirect(
+ return redirect(
path.to.operations,
await flash(request, {
...error(
@@ -71,7 +70,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
]);
if (jobMakeMethod.error || !jobMakeMethod.data) {
- throw redirect(
+ return redirect(
path.to.operations,
await flash(
request,
@@ -128,7 +127,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
const newTrackedEntityId = response.data?.newTrackedEntityId;
if (newTrackedEntityId) {
- throw redirect(
+ return redirect(
`${path.to.operation(
operationId
)}?trackedEntityId=${newTrackedEntityId}`
@@ -142,8 +141,8 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
});
if (finishOperation.error) {
- return json(
- {},
+ return redirect(
+ path.to.operation(operationId),
await flash(
request,
error(finishOperation.error, "Failed to finish operation")
@@ -151,7 +150,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
);
}
- throw redirect(
+ return redirect(
path.to.operations,
await flash(request, {
...success("Operation finished successfully"),
@@ -175,7 +174,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
});
if (response.error) {
- throw redirect(
+ return redirect(
path.to.operation(operationId),
await flash(request, {
...error(response.error, "Failed to complete job operation"),
@@ -194,7 +193,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
});
if (insertProduction.error) {
- throw redirect(
+ return redirect(
path.to.operation(operationId),
await flash(request, {
...error(
@@ -218,7 +217,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
});
if (issue.error) {
- throw redirect(
+ return redirect(
path.to.operation(operationId),
await flash(request, {
...error(issue.error, "Failed to issue materials"),
@@ -236,7 +235,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
});
if (finishOperation.error) {
- throw redirect(
+ return redirect(
path.to.operation(operationId),
await flash(request, {
...error(finishOperation.error, "Failed to finish operation"),
@@ -245,7 +244,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
);
}
- throw redirect(
+ return redirect(
path.to.operations,
await flash(request, {
...success("Operation finished successfully"),
@@ -254,7 +253,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
);
}
- throw redirect(
+ return redirect(
path.to.operation(operationId),
await flash(request, {
...success("Successfully completed part"),
diff --git a/apps/mes/app/routes/x+/finish.tsx b/apps/mes/app/routes/x+/finish.tsx
index 36b08e81c0..b38fcdb8ca 100644
--- a/apps/mes/app/routes/x+/finish.tsx
+++ b/apps/mes/app/routes/x+/finish.tsx
@@ -30,8 +30,6 @@ export async function action({ request }: ActionFunctionArgs) {
userId,
});
- console.log({ finishOperation });
-
if (finishOperation.error) {
return json(
{},
diff --git a/apps/mes/app/routes/x+/operation.$operationId.tsx b/apps/mes/app/routes/x+/operation.$operationId.tsx
index db0118c9b6..f36dbc5248 100644
--- a/apps/mes/app/routes/x+/operation.$operationId.tsx
+++ b/apps/mes/app/routes/x+/operation.$operationId.tsx
@@ -14,6 +14,7 @@ import {
getJobMaterialsByOperationId,
getJobOperationById,
getJobOperationProcedure,
+ getKanbanByJobId,
getProductionEventsForJobOperation,
getProductionQuantitiesForJobOperation,
getThumbnailPathByItemId,
@@ -23,6 +24,7 @@ import {
import type { OperationWithDetails } from "~/services/types";
import { makeDurations } from "~/utils/durations";
import { path } from "~/utils/path";
+
export async function loader({ request, params }: LoaderFunctionArgs) {
const { userId, companyId } = await requirePermissions(request, {});
@@ -65,14 +67,16 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
);
}
- const [thumbnailPath, trackedEntities, jobMakeMethod] = await Promise.all([
- getThumbnailPathByItemId(serviceRole, operation.data?.[0].itemId),
- getTrackedEntitiesByMakeMethodId(
- serviceRole,
- operation.data?.[0].jobMakeMethodId
- ),
- getJobMakeMethod(serviceRole, operation.data?.[0].jobMakeMethodId),
- ]);
+ const [thumbnailPath, trackedEntities, jobMakeMethod, kanban] =
+ await Promise.all([
+ getThumbnailPathByItemId(serviceRole, operation.data?.[0].itemId),
+ getTrackedEntitiesByMakeMethodId(
+ serviceRole,
+ operation.data?.[0].jobMakeMethodId
+ ),
+ getJobMakeMethod(serviceRole, operation.data?.[0].jobMakeMethodId),
+ getKanbanByJobId(serviceRole, job.data.id),
+ ]);
// If no trackedEntityId is provided in the URL but trackedEntities exist,
// redirect to the same URL with the last trackedEntityId as a search param
@@ -110,6 +114,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
),
job: job.data,
jobMakeMethod: jobMakeMethod.data,
+ kanban: kanban.data,
files: getJobFiles(
serviceRole,
companyId,
@@ -139,6 +144,7 @@ export default function OperationRoute() {
files,
job,
jobMakeMethod,
+ kanban,
materials,
operation,
procedure,
@@ -152,6 +158,7 @@ export default function OperationRoute() {
key={`job-operation-${operationId}`}
events={events}
files={files}
+ kanban={kanban}
materials={materials}
method={jobMakeMethod}
trackedEntities={trackedEntities}
diff --git a/apps/mes/app/routes/x+/operations.tsx b/apps/mes/app/routes/x+/operations.tsx
index f533f315c6..6ebcea4ffd 100644
--- a/apps/mes/app/routes/x+/operations.tsx
+++ b/apps/mes/app/routes/x+/operations.tsx
@@ -17,16 +17,16 @@ import {
useMount,
VStack,
} from "@carbon/react";
-import { json, redirect, useLoaderData } from "@remix-run/react";
-import type { RealtimeChannel } from "@supabase/supabase-js";
-import type { LoaderFunctionArgs } from "@vercel/remix";
-import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import {
getLocalTimeZone,
now,
parseAbsolute,
toZoned,
} from "@internationalized/date";
+import { json, redirect, useLoaderData } from "@remix-run/react";
+import type { RealtimeChannel } from "@supabase/supabase-js";
+import type { LoaderFunctionArgs } from "@vercel/remix";
+import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { LuSettings2, LuTriangleAlert } from "react-icons/lu";
import type { ColumnFilter } from "~/components/Filter";
diff --git a/apps/mes/app/services/operations.service.ts b/apps/mes/app/services/operations.service.ts
index a79eb4eaf5..babdbe7b48 100644
--- a/apps/mes/app/services/operations.service.ts
+++ b/apps/mes/app/services/operations.service.ts
@@ -355,6 +355,14 @@ export async function getJobParametersByOperationId(
.eq("operationId", operationId);
}
+export async function getKanbanByJobId(
+ client: SupabaseClient<Database>,
+ jobId: string | null
+) {
+ if (!jobId) return { data: null, error: null };
+ return client.from("kanban").select("*").eq("jobId", jobId).maybeSingle();
+}
+
export async function getLocationsByCompany(
client: SupabaseClient<Database>,
companyId: string
diff --git a/apps/mes/app/services/types.ts b/apps/mes/app/services/types.ts
index b96355e716..8aa8b59baa 100644
--- a/apps/mes/app/services/types.ts
+++ b/apps/mes/app/services/types.ts
@@ -6,6 +6,7 @@ import type {
getJobOperationById,
getJobOperationProcedure,
getJobOperationsByWorkCenter,
+ getKanbanByJobId,
getLocationsByCompany,
getProductionEventsForJobOperation,
getProductionQuantitiesForJobOperation,
@@ -44,9 +45,7 @@ export type JobMaterial = NonNullable<
kitParentId?: string;
};
-export type TrackedInput = NonNullable<
- Awaited<ReturnType<typeof getTrackedInputs>>["data"]
->[number];
+export type Kanban = Awaited<ReturnType<typeof getKanbanByJobId>>["data"];
export type JobMakeMethod = NonNullable<
Awaited<ReturnType<typeof getJobMakeMethod>>["data"]
@@ -90,6 +89,10 @@ export type TrackedEntity = NonNullable<
Awaited<ReturnType<typeof getTrackedEntitiesByMakeMethodId>>["data"]
>[number];
+export type TrackedInput = NonNullable<
+ Awaited<ReturnType<typeof getTrackedInputs>>["data"]
+>[number];
+
export type WorkCenter = NonNullable<
Awaited<ReturnType<typeof getJobOperationsByWorkCenter>>["data"]
>[number];
diff --git a/apps/mes/app/utils/path.ts b/apps/mes/app/utils/path.ts
index d2348c3236..83c34609b0 100644
--- a/apps/mes/app/utils/path.ts
+++ b/apps/mes/app/utils/path.ts
@@ -71,8 +71,8 @@ export const path = {
endOperation: (id: string) => generatePath(`${x}/end/${id}`),
feedback: `${x}/feedback`,
finish: `${x}/finish`,
-
health: "/health",
+ kanbanComplete: (id: string) => `${ERP_URL}/api/kanban/complete/${id}`,
inventoryAdjustment: `${x}/adjustment`,
issue: `${x}/issue`,
issueTrackedEntity: `${x}/issue-tracked-entity`,