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 shelf to job

Brad Barbin4d0ec8693616
diff --git a/apps/erp/app/modules/inventory/ui/Kanbans/KanbansTable.tsx b/apps/erp/app/modules/inventory/ui/Kanbans/KanbansTable.tsx
index d06c675627..9a7cb4869b 100644
--- a/apps/erp/app/modules/inventory/ui/Kanbans/KanbansTable.tsx
+++ b/apps/erp/app/modules/inventory/ui/Kanbans/KanbansTable.tsx
@@ -91,15 +91,11 @@ const KanbansTable = memo(
header: "Item",
cell: ({ row }) => (
<HStack className="py-1">
- <div className="relative">
- <ItemThumbnail
- size="sm"
- thumbnailPath={row.original.thumbnailPath}
- />
- {row.original.jobReadableId && (
- <PulsingDot className="absolute top-0 right-0" />
- )}
- </div>
+ <ItemThumbnail
+ size="sm"
+ thumbnailPath={row.original.thumbnailPath}
+ />
+
<Hyperlink to={`${path.to.kanban(row.original.id!)}?${params}`}>
<VStack spacing={0}>
<div className="flex gap-1 items-center">
@@ -123,6 +119,24 @@ const KanbansTable = memo(
icon: <LuPackage />,
},
},
+ {
+ id: "job",
+ header: "",
+ cell: ({ row }) => {
+ if (!row.original.jobReadableId || !row.original.jobId) return null;
+ return (
+ <Badge variant="outline">
+ <Link
+ to={path.to.job(row.original.jobId)}
+ className="flex flex-row items-center gap-1"
+ >
+ {row.original.jobReadableId}
+ <PulsingDot />
+ </Link>
+ </Badge>
+ );
+ },
+ },
{
id: "links",
header: "",
diff --git a/apps/mes/app/components/JobOperation.tsx b/apps/mes/app/components/JobOperation.tsx
index 7728276f1d..42bb69b470 100644
--- a/apps/mes/app/components/JobOperation.tsx
+++ b/apps/mes/app/components/JobOperation.tsx
@@ -389,10 +389,10 @@ export const JobOperation = ({
<Button
variant="ghost"
leftIcon={<LuChevronLeft />}
- onClick={() => navigate(path.to.assigned)}
+ onClick={() => navigate(path.to.operations)}
className="pl-2"
>
- Assignments
+ Schedule
</Button>
</div>
<div className="hidden md:flex flex-shrink-0 items-center justify-end gap-2">
@@ -2502,7 +2502,7 @@ function useOperation({
}));
} else if (payload.eventType === "DELETE") {
toast.error("This operation has been deleted");
- window.location.href = path.to.assigned;
+ window.location.href = path.to.operations;
}
}
)
diff --git a/apps/mes/app/routes/x+/_index.tsx b/apps/mes/app/routes/x+/_index.tsx
index b71df4cad3..959e525c1d 100644
--- a/apps/mes/app/routes/x+/_index.tsx
+++ b/apps/mes/app/routes/x+/_index.tsx
@@ -3,5 +3,5 @@ import { redirect } from "@vercel/remix";
import { path } from "~/utils/path";
export const loader: LoaderFunction = async ({ request }) => {
- return redirect(path.to.assigned);
+ return redirect(path.to.operations);
};
diff --git a/apps/mes/app/routes/x+/finish.tsx b/apps/mes/app/routes/x+/finish.tsx
index 76ae3597dc..36b08e81c0 100644
--- a/apps/mes/app/routes/x+/finish.tsx
+++ b/apps/mes/app/routes/x+/finish.tsx
@@ -43,7 +43,7 @@ export async function action({ request }: ActionFunctionArgs) {
}
throw redirect(
- path.to.assigned,
+ path.to.operations,
await flash(request, success("Operation finished successfully"))
);
}
diff --git a/packages/database/supabase/migrations/20251001133427_remove-production-event-trigger.sql b/packages/database/supabase/migrations/20251001133427_remove-production-event-trigger.sql
index 82e5e7c6d2..a6b35f79fb 100644
--- a/packages/database/supabase/migrations/20251001133427_remove-production-event-trigger.sql
+++ b/packages/database/supabase/migrations/20251001133427_remove-production-event-trigger.sql
@@ -52,7 +52,7 @@ BEGIN
job_shelf_id TEXT;
BEGIN
- UPDATE "kanban" SET "jobId" = NULL WHERE "jobId" = NEW."jobId";
+
SELECT "locationId"
INTO job_location_id
@@ -155,3 +155,23 @@ BEGIN
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;
+
+
+-- Trigger to clear kanban jobId when job is completed or canceled
+CREATE OR REPLACE FUNCTION job_complete_or_canceled()
+RETURNS TRIGGER AS $$
+BEGIN
+ -- Check if status changed to 'Completed' or 'Canceled'
+ IF (OLD."status" != NEW."status" AND (NEW."status" = 'Completed' OR NEW."status" = 'Cancelled')) THEN
+ UPDATE "kanban"
+ SET "jobId" = NULL
+ WHERE "jobId" = NEW."id";
+ END IF;
+
+ RETURN NEW;
+END;
+$$ LANGUAGE plpgsql SECURITY DEFINER;
+
+CREATE OR REPLACE TRIGGER "job_completed_or_canceled_trigger"
+AFTER UPDATE ON "job"
+FOR EACH ROW EXECUTE FUNCTION job_complete_or_canceled();
diff --git a/packages/database/supabase/migrations/20251002020841_add-shelf-to-job.sql b/packages/database/supabase/migrations/20251002020841_add-shelf-to-job.sql
new file mode 100644
index 0000000000..1478d11a7d
--- /dev/null
+++ b/packages/database/supabase/migrations/20251002020841_add-shelf-to-job.sql
@@ -0,0 +1,42 @@
+ALTER TABLE "job" ADD COLUMN "shelfId" TEXT;
+
+ALTER TABLE "job" ADD CONSTRAINT "job_shelfId_fkey" FOREIGN KEY ("shelfId") REFERENCES "shelf" ("id") ON DELETE SET NULL ON UPDATE CASCADE;
+
+DROP VIEW IF EXISTS "jobs";
+CREATE OR REPLACE VIEW "jobs" WITH(SECURITY_INVOKER=true) AS
+WITH job_model AS (
+ SELECT
+ j.id AS job_id,
+ j."companyId",
+ COALESCE(j."modelUploadId", i."modelUploadId") AS model_upload_id
+ FROM "job" j
+ INNER JOIN "item" i ON j."itemId" = i."id" AND j."companyId" = i."companyId"
+)
+SELECT
+ j.*,
+ jmm."id" as "jobMakeMethodId",
+ i.name,
+ i."readableIdWithRevision" as "itemReadableIdWithRevision",
+ i.type as "itemType",
+ i.name as "description",
+ i."itemTrackingType",
+ i.active,
+ i."replenishmentSystem",
+ mu.id as "modelId",
+ mu."autodeskUrn",
+ mu."modelPath",
+ CASE
+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"
+ ELSE i."thumbnailPath"
+ END as "thumbnailPath",
+ mu."name" as "modelName",
+ mu."size" as "modelSize",
+ so."salesOrderId" as "salesOrderReadableId",
+ qo."quoteId" as "quoteReadableId"
+FROM "job" j
+LEFT JOIN "jobMakeMethod" jmm ON jmm."jobId" = j.id AND jmm."parentMaterialId" IS NULL
+INNER JOIN "item" i ON j."itemId" = i."id" AND j."companyId" = i."companyId"
+LEFT JOIN job_model jm ON j.id = jm.job_id AND j."companyId" = jm."companyId"
+LEFT JOIN "modelUpload" mu ON mu.id = jm.model_upload_id
+LEFT JOIN "salesOrder" so on j."salesOrderId" = so.id AND j."companyId" = so."companyId"
+LEFT JOIN "quote" qo ON j."quoteId" = qo.id AND j."companyId" = qo."companyId";
\ No newline at end of file