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: add link to job traveler in mes

Brad Barbind7860fee9895
diff --git a/apps/erp/app/modules/production/production.service.ts b/apps/erp/app/modules/production/production.service.ts
index 09d1b9ad1a..3efe3e9a2e 100644
--- a/apps/erp/app/modules/production/production.service.ts
+++ b/apps/erp/app/modules/production/production.service.ts
@@ -320,12 +320,14 @@ export async function getJobsList(
export async function getJobMakeMethodById(
client: SupabaseClient<Database>,
- jobMakeMethodId: string
+ jobMakeMethodId: string,
+ companyId: string
) {
return client
.from("jobMakeMethod")
.select("*, ...item(itemType:type)")
.eq("id", jobMakeMethodId)
+ .eq("companyId", companyId)
.single();
}
diff --git a/apps/erp/app/routes/file+/traveler+/$id[.]pdf.tsx b/apps/erp/app/routes/file+/traveler+/$id[.]pdf.tsx
index 39e05f948e..9b90e41446 100644
--- a/apps/erp/app/routes/file+/traveler+/$id[.]pdf.tsx
+++ b/apps/erp/app/routes/file+/traveler+/$id[.]pdf.tsx
@@ -1,3 +1,4 @@
+import { getCarbonServiceRole } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { JobTravelerPDF } from "@carbon/documents/pdf";
import type { JSONContent } from "@carbon/react";
@@ -16,22 +17,24 @@ import { getLocale } from "~/utils/request";
export const config = { runtime: "nodejs" };
export async function loader({ request, params }: LoaderFunctionArgs) {
- const { client } = await requirePermissions(request, {
- view: "production",
- });
+ const { companyId } = await requirePermissions(request, {});
const { id } = params;
if (!id) throw new Error("Could not find job make method id");
- const jobMakeMethod = await getJobMakeMethodById(client, id);
+ const serviceRole = await getCarbonServiceRole();
+
+ // we add the companyId to make sure we belong to the company
+ // while allowing guys on the shop floor with no permissions to download the traveler
+ const jobMakeMethod = await getJobMakeMethodById(serviceRole, id, companyId);
if (jobMakeMethod.error) {
console.error(jobMakeMethod.error);
throw new Error("Failed to load job make method");
}
const [company, job] = await Promise.all([
- getCompany(client, jobMakeMethod.data?.companyId ?? ""),
- getJob(client, jobMakeMethod.data?.jobId ?? ""),
+ getCompany(serviceRole, jobMakeMethod.data?.companyId ?? ""),
+ getJob(serviceRole, jobMakeMethod.data?.jobId ?? ""),
]);
if (company.error) {
@@ -45,13 +48,13 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
}
const [jobOperations, customer, item] = await Promise.all([
- getJobOperationsByMethodId(client, id),
- client
+ getJobOperationsByMethodId(serviceRole, id),
+ serviceRole
.from("customer")
.select("*")
.eq("id", job.data.customerId ?? "")
.maybeSingle(),
- client
+ serviceRole
.from("item")
.select("*, modelUpload(thumbnailPath)")
.eq("id", jobMakeMethod.data.itemId ?? "")
@@ -70,7 +73,10 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
let batchNumber: string | undefined;
if (["Batch", "Serial"].includes(item.data.itemTrackingType)) {
- const trackedEntity = await getTrackedEntityByJobId(client, job.data.id!);
+ const trackedEntity = await getTrackedEntityByJobId(
+ serviceRole,
+ job.data.id!
+ );
if (trackedEntity.error) {
console.error(trackedEntity.error);
throw new Error("Failed to load tracked entity");
@@ -86,7 +92,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
let thumbnail: string | null = null;
if (item.data.thumbnailPath || item.data.modelUpload?.thumbnailPath) {
thumbnail = await getBase64ImageFromSupabase(
- client,
+ serviceRole,
item.data.thumbnailPath ?? item.data.modelUpload?.thumbnailPath ?? ""
);
}
diff --git a/apps/erp/app/routes/x+/job+/$jobId.method.$methodId.tsx b/apps/erp/app/routes/x+/job+/$jobId.method.$methodId.tsx
index 1a10bafdbc..88ab945b03 100644
--- a/apps/erp/app/routes/x+/job+/$jobId.method.$methodId.tsx
+++ b/apps/erp/app/routes/x+/job+/$jobId.method.$methodId.tsx
@@ -46,7 +46,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
getJobMaterialsByMethodId(client, methodId),
getJobOperationsByMethodId(client, methodId),
getTagsList(client, companyId, "operation"),
- getJobMakeMethodById(client, methodId),
+ getJobMakeMethodById(client, methodId, companyId),
]);
if (materials.error) {
diff --git a/apps/mes/app/components/JobOperation.tsx b/apps/mes/app/components/JobOperation.tsx
index 59fadbf760..33f1f95ae9 100644
--- a/apps/mes/app/components/JobOperation.tsx
+++ b/apps/mes/app/components/JobOperation.tsx
@@ -427,7 +427,23 @@ export const JobOperation = ({
</header>
<div className="hidden md:flex items-center justify-between px-4 lg:pl-6 py-2 h-[var(--header-height)] bg-background gap-4 max-w-[100vw] overflow-x-hidden scrollbar-thin scrollbar-track-transparent scrollbar-thumb-accent">
- <Heading size="h4">{operation.jobReadableId}</Heading>
+ <HStack>
+ <Heading size="h4">{operation.jobReadableId}</Heading>
+ <Button
+ variant="secondary"
+ size="sm"
+ leftIcon={<LuQrCode />}
+ asChild
+ >
+ <a
+ href={path.to.file.jobTraveler(operation.jobMakeMethodId)}
+ target="_blank"
+ rel="noreferrer"
+ >
+ Traveler
+ </a>
+ </Button>
+ </HStack>
<HStack className="justify-end items-center gap-2">
{job.customer?.name && (
diff --git a/apps/mes/app/utils/path.ts b/apps/mes/app/utils/path.ts
index 3c871c31f5..31f529a62a 100644
--- a/apps/mes/app/utils/path.ts
+++ b/apps/mes/app/utils/path.ts
@@ -16,6 +16,7 @@ export const path = {
generatePath(`${api}/serial-numbers?itemId=${itemId}`),
},
file: {
+ jobTraveler: (id: string) => `${getAppUrl()}${file}/traveler/${id}.pdf`,
operationLabelsPdf: (
id: string,
{