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 method id to url scheme for item master

Brad Barbinfdc24257c0b7
diff --git a/apps/erp/app/modules/items/items.service.ts b/apps/erp/app/modules/items/items.service.ts
index 8f7a5e6282..7d65a3fd19 100644
--- a/apps/erp/app/modules/items/items.service.ts
+++ b/apps/erp/app/modules/items/items.service.ts
@@ -717,8 +717,7 @@ export async function getMakeMethods(
.from("makeMethod")
.select("*")
.eq("itemId", itemId)
- .eq("companyId", companyId)
- .single();
+ .eq("companyId", companyId);
}
export async function getMakeMethodById(
diff --git a/apps/erp/app/modules/items/ui/Item/BoMExplorer.tsx b/apps/erp/app/modules/items/ui/Item/BoMExplorer.tsx
index 96372d7b89..c4f56adcc3 100644
--- a/apps/erp/app/modules/items/ui/Item/BoMExplorer.tsx
+++ b/apps/erp/app/modules/items/ui/Item/BoMExplorer.tsx
@@ -88,8 +88,9 @@ const BoMExplorer = ({
const navigate = useNavigate();
const location = useOptimisticLocation();
- const { itemId } = params;
+ const { itemId, methodId } = params;
if (!itemId) throw new Error("itemId not found");
+ if (!methodId) throw new Error("methodId not found");
const [selectedMaterialId, setSelectedMaterialId] = useBom();
useMount(() => {
@@ -149,8 +150,11 @@ const BoMExplorer = ({
selectNode(node.id);
setSelectedMaterialId(node.data.methodMaterialId);
if (node.data.isRoot) {
- if (location.pathname !== getRootLink(itemType, itemId)) {
- navigate(getRootLink(itemType, itemId));
+ if (
+ location.pathname !==
+ getRootLink(itemType, itemId, methodId)
+ ) {
+ navigate(getRootLink(itemType, itemId, methodId));
}
} else {
if (
@@ -158,6 +162,7 @@ const BoMExplorer = ({
getMaterialLink(
itemType,
itemId,
+ methodId,
node.data.methodType === "Make"
? node.data.materialMakeMethodId
: node.data.makeMethodId
@@ -167,6 +172,7 @@ const BoMExplorer = ({
getMaterialLink(
itemType,
itemId,
+ methodId,
node.data.methodType === "Make"
? node.data.materialMakeMethodId
: node.data.makeMethodId
@@ -372,12 +378,16 @@ function NodePreview({ node }: { node: FlatTreeItem<Method> }) {
);
}
-function getRootLink(itemType: MethodItemType, itemId: string) {
+function getRootLink(
+ itemType: MethodItemType,
+ itemId: string,
+ methodId: string
+) {
switch (itemType) {
case "Part":
- return path.to.partMakeMethod(itemId);
+ return path.to.partMakeMethod(itemId, methodId);
case "Tool":
- return path.to.toolMakeMethod(itemId);
+ return path.to.toolMakeMethod(itemId, methodId);
default:
throw new Error(`Unimplemented BoMExplorer itemType: ${itemType}`);
}
@@ -386,13 +396,14 @@ function getRootLink(itemType: MethodItemType, itemId: string) {
function getMaterialLink(
itemType: MethodItemType,
itemId: string,
+ methodId: string,
makeMethodId: string
) {
switch (itemType) {
case "Part":
- return path.to.partManufacturingMaterial(itemId, makeMethodId);
+ return path.to.partManufacturingMaterial(itemId, methodId, makeMethodId);
case "Tool":
- return path.to.toolManufacturingMaterial(itemId, makeMethodId);
+ return path.to.toolManufacturingMaterial(itemId, methodId, makeMethodId);
default:
throw new Error(`Unimplemented BoMExplorer itemType: ${itemType}`);
}
diff --git a/apps/erp/app/modules/items/ui/Methods/MethodMaterialsTable.tsx b/apps/erp/app/modules/items/ui/Methods/MethodMaterialsTable.tsx
index 44d08838e0..c15cfe3f5e 100644
--- a/apps/erp/app/modules/items/ui/Methods/MethodMaterialsTable.tsx
+++ b/apps/erp/app/modules/items/ui/Methods/MethodMaterialsTable.tsx
@@ -31,7 +31,9 @@ const MethodMaterialsTable = memo(
// @ts-ignore
row.original.makeMethod?.item?.type,
// @ts-ignore
- row.original.makeMethod?.item?.id
+ row.original.makeMethod?.item?.id,
+ // @ts-ignore
+ row.original.makeMethod?.id
)}
className="max-w-[260px] truncate"
>
diff --git a/apps/erp/app/modules/items/ui/Methods/MethodOperationsTable.tsx b/apps/erp/app/modules/items/ui/Methods/MethodOperationsTable.tsx
index aca87fcaa3..44be1bb4ff 100644
--- a/apps/erp/app/modules/items/ui/Methods/MethodOperationsTable.tsx
+++ b/apps/erp/app/modules/items/ui/Methods/MethodOperationsTable.tsx
@@ -30,7 +30,9 @@ const MethodOperationsTable = memo(
// @ts-ignore
row.original.makeMethod?.item?.type,
// @ts-ignore
- row.original.makeMethod?.item?.id
+ row.original.makeMethod?.item?.id,
+ // @ts-ignore
+ row.original.makeMethod?.id
)}
className="max-w-[260px] truncate"
>
diff --git a/apps/erp/app/modules/items/ui/Methods/utils.ts b/apps/erp/app/modules/items/ui/Methods/utils.ts
index 6c30792651..1d1266df9c 100644
--- a/apps/erp/app/modules/items/ui/Methods/utils.ts
+++ b/apps/erp/app/modules/items/ui/Methods/utils.ts
@@ -1,11 +1,15 @@
import { path } from "~/utils/path";
-export function getPathToMakeMethod(type: string, id: string) {
+export function getPathToMakeMethod(
+ type: string,
+ id: string,
+ methodId: string
+) {
switch (type) {
case "Part":
- return path.to.partMakeMethod(id);
+ return path.to.partMakeMethod(id, methodId);
case "Tool":
- return path.to.toolMakeMethod(id);
+ return path.to.toolMakeMethod(id, methodId);
default:
return "#";
}
diff --git a/apps/erp/app/modules/items/ui/Parts/PartManufacturingForm.tsx b/apps/erp/app/modules/items/ui/Parts/PartManufacturingForm.tsx
index c442d69683..88191c9855 100644
--- a/apps/erp/app/modules/items/ui/Parts/PartManufacturingForm.tsx
+++ b/apps/erp/app/modules/items/ui/Parts/PartManufacturingForm.tsx
@@ -17,7 +17,7 @@ import {
} from "~/components/Form";
import { usePermissions } from "~/hooks";
-import type { action } from "~/routes/x+/part+/$itemId.manufacturing.method";
+import type { action } from "~/routes/x+/part+/$itemId.manufacturing.$methodId.method";
import { partManufacturingValidator } from "../../items.models";
type PartManufacturingFormProps = {
diff --git a/apps/erp/app/modules/items/ui/Parts/PartProperties.tsx b/apps/erp/app/modules/items/ui/Parts/PartProperties.tsx
index 91190870c2..176041856f 100644
--- a/apps/erp/app/modules/items/ui/Parts/PartProperties.tsx
+++ b/apps/erp/app/modules/items/ui/Parts/PartProperties.tsx
@@ -17,6 +17,7 @@ import {
toast,
} from "@carbon/react";
import { Await, Link, useFetcher, useParams } from "@remix-run/react";
+import type { PostgrestResponse } from "@supabase/supabase-js";
import { Suspense, useCallback, useEffect } from "react";
import {
LuCopy,
@@ -44,6 +45,7 @@ import {
} from "../../items.models";
import type {
ItemFile,
+ MakeMethod,
PartSummary,
PickMethod,
SupplierPart,
@@ -62,6 +64,7 @@ const PartProperties = () => {
files: Promise<ItemFile[]>;
supplierParts: SupplierPart[];
pickMethods: PickMethod[];
+ makeMethods: Promise<PostgrestResponse<MakeMethod>>;
tags: { name: string }[];
}>(path.to.part(itemId));
@@ -374,11 +377,20 @@ const PartProperties = () => {
<h3 className="text-xs text-muted-foreground">Methods</h3>
</HStack>
{routeData?.partSummary?.replenishmentSystem?.includes("Make") && (
- <MethodBadge
- type="Make"
- text={routeData?.partSummary?.readableIdWithRevision ?? ""}
- to={path.to.partManufacturing(itemId)}
- />
+ <Suspense fallback={null}>
+ <Await resolve={routeData?.makeMethods}>
+ {(makeMethods) =>
+ makeMethods.data?.map((method) => (
+ <MethodBadge
+ key={method.id}
+ type="Make"
+ text={`Version ${method.version}`}
+ to={path.to.partMakeMethod(itemId, method.id)}
+ />
+ ))
+ }
+ </Await>
+ </Suspense>
)}
{routeData?.partSummary?.replenishmentSystem?.includes("Buy") &&
supplierParts.map((method) => (
diff --git a/apps/erp/app/modules/items/ui/Tools/ToolProperties.tsx b/apps/erp/app/modules/items/ui/Tools/ToolProperties.tsx
index 3061fb5105..d398a00999 100644
--- a/apps/erp/app/modules/items/ui/Tools/ToolProperties.tsx
+++ b/apps/erp/app/modules/items/ui/Tools/ToolProperties.tsx
@@ -17,6 +17,7 @@ import {
toast,
} from "@carbon/react";
import { Await, useFetcher, useParams } from "@remix-run/react";
+import type { PostgrestResponse } from "@supabase/supabase-js";
import { Suspense, useCallback, useEffect } from "react";
import { LuCopy, LuKeySquare, LuLink } from "react-icons/lu";
import { z } from "zod";
@@ -37,7 +38,13 @@ import {
itemReplenishmentSystems,
itemTrackingTypes,
} from "../../items.models";
-import type { ItemFile, PickMethod, SupplierPart, Tool } from "../../types";
+import type {
+ ItemFile,
+ MakeMethod,
+ PickMethod,
+ SupplierPart,
+ Tool,
+} from "../../types";
import { FileBadge } from "../Item";
const ToolProperties = () => {
@@ -52,6 +59,7 @@ const ToolProperties = () => {
files: Promise<ItemFile[]>;
supplierParts: SupplierPart[];
pickMethods: PickMethod[];
+ makeMethods: Promise<PostgrestResponse<MakeMethod>>;
tags: { name: string }[];
}>(path.to.tool(itemId));
@@ -335,7 +343,22 @@ const ToolProperties = () => {
<HStack className="w-full justify-between">
<h3 className="text-xs text-muted-foreground">Methods</h3>
</HStack>
-
+ {routeData?.toolSummary?.replenishmentSystem?.includes("Make") && (
+ <Suspense fallback={null}>
+ <Await resolve={routeData?.makeMethods}>
+ {(makeMethods) =>
+ makeMethods.data?.map((method) => (
+ <MethodBadge
+ key={method.id}
+ type="Make"
+ text={`Revision ${method.revision}`}
+ to={path.to.partMakeMethod(itemId, method.id)}
+ />
+ ))
+ }
+ </Await>
+ </Suspense>
+ )}
{routeData?.toolSummary?.replenishmentSystem?.includes("Buy") &&
supplierParts.map((method) => (
<MethodBadge
diff --git a/apps/erp/app/routes/x+/part+/$itemId.manufacturing.$makeMethodId.tsx b/apps/erp/app/routes/x+/part+/$itemId.manufacturing.$methodId.$makeMethodId.tsx
similarity index 100%
rename from apps/erp/app/routes/x+/part+/$itemId.manufacturing.$makeMethodId.tsx
rename to apps/erp/app/routes/x+/part+/$itemId.manufacturing.$methodId.$makeMethodId.tsx
diff --git a/apps/erp/app/routes/x+/part+/$itemId.manufacturing.method.tsx b/apps/erp/app/routes/x+/part+/$itemId.manufacturing.$methodId.method.tsx
similarity index 92%
rename from apps/erp/app/routes/x+/part+/$itemId.manufacturing.method.tsx
rename to apps/erp/app/routes/x+/part+/$itemId.manufacturing.$methodId.method.tsx
index 0e7b35ec33..681c2459b6 100644
--- a/apps/erp/app/routes/x+/part+/$itemId.manufacturing.method.tsx
+++ b/apps/erp/app/routes/x+/part+/$itemId.manufacturing.$methodId.method.tsx
@@ -4,6 +4,7 @@ import { flash } from "@carbon/auth/session.server";
import { validationError, validator } from "@carbon/form";
import { VStack } from "@carbon/react";
import { useLoaderData, useParams } from "@remix-run/react";
+import type { PostgrestResponse } from "@supabase/supabase-js";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
import { json, redirect } from "@vercel/remix";
import type { z } from "zod";
@@ -47,16 +48,15 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
return json({ tags: tags.data ?? [] });
}
-// action
-
export async function action({ request, params }: ActionFunctionArgs) {
assertIsPost(request);
const { client, userId } = await requirePermissions(request, {
update: "parts",
});
- const { itemId } = params;
+ const { itemId, methodId } = params;
if (!itemId) throw new Error("Could not find itemId");
+ if (!methodId) throw new Error("Could not find methodId");
const formData = await request.formData();
const validation = await validator(partManufacturingValidator).validate(
@@ -87,20 +87,22 @@ export async function action({ request, params }: ActionFunctionArgs) {
}
throw redirect(
- path.to.partManufacturing(itemId),
+ path.to.partMakeMethod(itemId, methodId),
await flash(request, success("Updated part manufacturing"))
);
}
export default function MakeMethodRoute() {
const permissions = usePermissions();
- const { itemId } = useParams();
+ const { itemId, methodId } = useParams();
if (!itemId) throw new Error("Could not find itemId");
+ if (!methodId) throw new Error("Could not find methodId");
const { tags } = useLoaderData<typeof loader>();
const itemRouteData = useRouteData<{
partSummary: PartSummary;
+ makeMethods: Promise<PostgrestResponse<MakeMethod>>;
}>(path.to.part(itemId));
const manufacturingRouteData = useRouteData<{
@@ -115,7 +117,7 @@ export default function MakeMethodRoute() {
makeMethod: MakeMethod;
methodMaterials: Material[];
methodOperations: MethodOperation[];
- }>(path.to.partManufacturing(itemId));
+ }>(path.to.partMethod(itemId, methodId));
if (!manufacturingRouteData) throw new Error("Could not find route data");
@@ -130,7 +132,7 @@ export default function MakeMethodRoute() {
return (
<VStack spacing={2} className="p-2">
- <MakeMethodTools itemId={itemId} type="Part" />
+ <MakeMethodTools itemId={itemId} type="Part" revisions={[]} />
<PartManufacturingForm
key={itemId}
// @ts-ignore
diff --git a/apps/erp/app/routes/x+/part+/$itemId.manufacturing.tsx b/apps/erp/app/routes/x+/part+/$itemId.manufacturing.$methodId.tsx
similarity index 91%
rename from apps/erp/app/routes/x+/part+/$itemId.manufacturing.tsx
rename to apps/erp/app/routes/x+/part+/$itemId.manufacturing.$methodId.tsx
index e7682631df..e546d7adf0 100644
--- a/apps/erp/app/routes/x+/part+/$itemId.manufacturing.tsx
+++ b/apps/erp/app/routes/x+/part+/$itemId.manufacturing.$methodId.tsx
@@ -25,7 +25,7 @@ import {
getConfigurationParameters,
getConfigurationRules,
getItemManufacturing,
- getMakeMethods,
+ getMakeMethodById,
getMethodMaterialsByMakeMethod,
getMethodOperationsByMakeMethodId,
getMethodTree,
@@ -40,17 +40,18 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
bypassRls: true,
});
- const { itemId } = params;
+ const { itemId, methodId } = params;
if (!itemId) throw new Error("Could not find itemId");
+ if (!methodId) throw new Error("Could not find methodId");
- const makeMethods = await getMakeMethods(client, itemId, companyId);
+ const makeMethod = await getMakeMethodById(client, methodId, companyId);
- if (makeMethods.error) {
+ if (makeMethod.error) {
throw redirect(
path.to.partDetails(itemId),
await flash(
request,
- error(makeMethods.error, "Failed to load make methods")
+ error(makeMethod.error, "Failed to load make methods")
)
);
}
@@ -62,6 +63,13 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
);
}
+ if (companyId !== makeMethod.data.companyId) {
+ throw redirect(
+ path.to.authenticatedRoot,
+ await flash(request, error("Access denied"))
+ );
+ }
+
const [methodTree, methodMaterials, methodOperations, partManufacturing] =
await Promise.all([
getMethodTree(client, makeMethod.data.id),
diff --git a/apps/erp/app/routes/x+/part+/$itemId.manufacturing._index.tsx b/apps/erp/app/routes/x+/part+/$itemId.manufacturing._index.tsx
index a35209b37d..f7550952ae 100644
--- a/apps/erp/app/routes/x+/part+/$itemId.manufacturing._index.tsx
+++ b/apps/erp/app/routes/x+/part+/$itemId.manufacturing._index.tsx
@@ -1,10 +1,21 @@
+import { requirePermissions } from "@carbon/auth/auth.server";
import type { LoaderFunctionArgs } from "@vercel/remix";
import { redirect } from "@vercel/remix";
+import { getMakeMethods } from "~/modules/items";
import { path } from "~/utils/path";
-export async function loader({ params }: LoaderFunctionArgs) {
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { client, companyId } = await requirePermissions(request, {
+ view: "parts",
+ });
const { itemId } = params;
if (!itemId) throw new Error("Could not find itemId");
- throw redirect(path.to.partMakeMethod(itemId));
+ const makeMethods = await getMakeMethods(client, itemId, companyId);
+ const makeMethod =
+ makeMethods.data?.find((m) => m.status === "Active") ??
+ makeMethods.data?.[0];
+ if (!makeMethod) throw new Error("Could not find make method");
+
+ throw redirect(path.to.partMakeMethod(itemId, makeMethod.id));
}
diff --git a/apps/erp/app/routes/x+/part+/$itemId.tsx b/apps/erp/app/routes/x+/part+/$itemId.tsx
index 2bf0f985de..a12b225753 100644
--- a/apps/erp/app/routes/x+/part+/$itemId.tsx
+++ b/apps/erp/app/routes/x+/part+/$itemId.tsx
@@ -6,6 +6,7 @@ import type { LoaderFunctionArgs } from "@vercel/remix";
import { defer, redirect } from "@vercel/remix";
import {
getItemFiles,
+ getMakeMethods,
getPart,
getPickMethods,
getSupplierParts,
@@ -52,6 +53,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
files: getItemFiles(serviceRole, itemId, companyId),
supplierParts: supplierParts.data ?? [],
pickMethods: pickMethods.data ?? [],
+ makeMethods: getMakeMethods(serviceRole, itemId, companyId),
tags: tags.data ?? [],
});
}
diff --git a/apps/erp/app/routes/x+/tool+/$itemId.manufacturing.$makeMethodId.tsx b/apps/erp/app/routes/x+/tool+/$itemId.manufacturing.$methodId.$makeMethodId.tsx
similarity index 100%
rename from apps/erp/app/routes/x+/tool+/$itemId.manufacturing.$makeMethodId.tsx
rename to apps/erp/app/routes/x+/tool+/$itemId.manufacturing.$methodId.$makeMethodId.tsx
diff --git a/apps/erp/app/routes/x+/tool+/$itemId.manufacturing.method.tsx b/apps/erp/app/routes/x+/tool+/$itemId.manufacturing.$methodId.method.tsx
similarity index 89%
rename from apps/erp/app/routes/x+/tool+/$itemId.manufacturing.method.tsx
rename to apps/erp/app/routes/x+/tool+/$itemId.manufacturing.$methodId.method.tsx
index 6f5b6a6189..1ad2ded5c5 100644
--- a/apps/erp/app/routes/x+/tool+/$itemId.manufacturing.method.tsx
+++ b/apps/erp/app/routes/x+/tool+/$itemId.manufacturing.$methodId.method.tsx
@@ -1,6 +1,7 @@
import { requirePermissions } from "@carbon/auth/auth.server";
import { VStack } from "@carbon/react";
import { useLoaderData, useParams } from "@remix-run/react";
+import type { PostgrestResponse } from "@supabase/supabase-js";
import type { LoaderFunctionArgs } from "@vercel/remix";
import { json } from "@vercel/remix";
import CadModel from "~/components/CadModel";
@@ -19,8 +20,6 @@ import {
import { getTagsList } from "~/modules/shared";
import { path } from "~/utils/path";
-// loader
-
export async function loader({ request, params }: LoaderFunctionArgs) {
const { client, companyId } = await requirePermissions(request, {
view: "parts",
@@ -33,20 +32,22 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
export default function MakeMethodRoute() {
const permissions = usePermissions();
- const { itemId } = useParams();
+ const { itemId, methodId } = useParams();
if (!itemId) throw new Error("Could not find itemId");
+ if (!methodId) throw new Error("Could not find methodId");
const { tags } = useLoaderData<typeof loader>();
const itemRouteData = useRouteData<{
toolSummary: ToolSummary;
- }>(path.to.part(itemId));
+ makeMethods: Promise<PostgrestResponse<MakeMethod>>;
+ }>(path.to.tool(itemId));
const manufacturingRouteData = useRouteData<{
makeMethod: MakeMethod;
methodMaterials: Material[];
methodOperations: MethodOperation[];
- }>(path.to.toolManufacturing(itemId));
+ }>(path.to.toolMethod(itemId, methodId));
if (!manufacturingRouteData) throw new Error("Could not find route data");
@@ -55,7 +56,7 @@ export default function MakeMethodRoute() {
return (
<VStack spacing={2} className="p-2">
- <MakeMethodTools itemId={itemId} type="Part" />
+ <MakeMethodTools itemId={itemId} type="Tool" revisions={[]} />
<BillOfProcess
key={`bop:${itemId}`}
diff --git a/apps/erp/app/routes/x+/tool+/$itemId.manufacturing.tsx b/apps/erp/app/routes/x+/tool+/$itemId.manufacturing.$methodId.tsx
similarity index 95%
rename from apps/erp/app/routes/x+/tool+/$itemId.manufacturing.tsx
rename to apps/erp/app/routes/x+/tool+/$itemId.manufacturing.$methodId.tsx
index c1641cc4f2..c18eddb32d 100644
--- a/apps/erp/app/routes/x+/tool+/$itemId.manufacturing.tsx
+++ b/apps/erp/app/routes/x+/tool+/$itemId.manufacturing.$methodId.tsx
@@ -22,7 +22,7 @@ import type { FlatTreeItem } from "~/components/TreeView";
import { flattenTree } from "~/components/TreeView";
import type { Method } from "~/modules/items";
import {
- getMakeMethods,
+ getMakeMethodById,
getMethodMaterialsByMakeMethod,
getMethodOperationsByMakeMethodId,
getMethodTree,
@@ -37,14 +37,15 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
bypassRls: true,
});
- const { itemId } = params;
+ const { itemId, methodId } = params;
if (!itemId) throw new Error("Could not find itemId");
+ if (!methodId) throw new Error("Could not find methodId");
- const makeMethods = await getMakeMethods(client, itemId, companyId);
+ const makeMethod = await getMakeMethodById(client, methodId, companyId);
if (makeMethod.error) {
throw redirect(
- path.to.partDetails(itemId),
+ path.to.toolDetails(itemId),
await flash(
request,
error(makeMethod.error, "Failed to load make method")
diff --git a/apps/erp/app/routes/x+/tool+/$itemId.manufacturing._index.tsx b/apps/erp/app/routes/x+/tool+/$itemId.manufacturing._index.tsx
index e5b8ac19cb..2026245456 100644
--- a/apps/erp/app/routes/x+/tool+/$itemId.manufacturing._index.tsx
+++ b/apps/erp/app/routes/x+/tool+/$itemId.manufacturing._index.tsx
@@ -1,10 +1,21 @@
+import { requirePermissions } from "@carbon/auth/auth.server";
import type { LoaderFunctionArgs } from "@vercel/remix";
import { redirect } from "@vercel/remix";
+import { getMakeMethods } from "~/modules/items";
import { path } from "~/utils/path";
-export async function loader({ params }: LoaderFunctionArgs) {
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { client, companyId } = await requirePermissions(request, {
+ view: "parts",
+ });
const { itemId } = params;
if (!itemId) throw new Error("Could not find itemId");
- throw redirect(path.to.toolMakeMethod(itemId));
+ const makeMethods = await getMakeMethods(client, itemId, companyId);
+ const makeMethod =
+ makeMethods.data?.find((m) => m.status === "Active") ??
+ makeMethods.data?.[0];
+ if (!makeMethod) throw new Error("Could not find make method");
+
+ throw redirect(path.to.toolMakeMethod(itemId, makeMethod.id));
}
diff --git a/apps/erp/app/routes/x+/tool+/$itemId.tsx b/apps/erp/app/routes/x+/tool+/$itemId.tsx
index 832487c350..e6a0e6cf76 100644
--- a/apps/erp/app/routes/x+/tool+/$itemId.tsx
+++ b/apps/erp/app/routes/x+/tool+/$itemId.tsx
@@ -6,6 +6,7 @@ import type { LoaderFunctionArgs } from "@vercel/remix";
import { defer, redirect } from "@vercel/remix";
import {
getItemFiles,
+ getMakeMethods,
getPickMethods,
getSupplierParts,
getTool,
@@ -52,6 +53,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
files: getItemFiles(serviceRole, itemId, companyId),
supplierParts: supplierParts.data ?? [],
pickMethods: pickMethods.data ?? [],
+ makeMethods: getMakeMethods(serviceRole, itemId, companyId),
tags: tags.data ?? [],
});
}
diff --git a/apps/erp/app/utils/path.ts b/apps/erp/app/utils/path.ts
index 9ad5421e74..ddc476b4df 100644
--- a/apps/erp/app/utils/path.ts
+++ b/apps/erp/app/utils/path.ts
@@ -883,12 +883,20 @@ export const path = {
partInventory: (id: string) => generatePath(`${x}/part/${id}/inventory`),
partInventoryLocation: (id: string, locationId: string) =>
generatePath(`${x}/part/${id}/inventory?location=${locationId}`),
- partMakeMethod: (id: string) =>
- generatePath(`${x}/part/${id}/manufacturing/method`),
+ partMethod: (id: string, methodId: string) =>
+ generatePath(`${x}/part/${id}/manufacturing/${methodId}`),
+ partMakeMethod: (id: string, methodId: string) =>
+ generatePath(`${x}/part/${id}/manufacturing/${methodId}/method`),
partManufacturing: (id: string) =>
generatePath(`${x}/part/${id}/manufacturing`),
- partManufacturingMaterial: (itemId: string, makeMethodId: string) =>
- generatePath(`${x}/part/${itemId}/manufacturing/${makeMethodId}`),
+ partManufacturingMaterial: (
+ itemId: string,
+ methodId: string,
+ makeMethodId: string
+ ) =>
+ generatePath(
+ `${x}/part/${itemId}/manufacturing/${methodId}/${makeMethodId}`
+ ),
partPlanning: (id: string) => generatePath(`${x}/part/${id}/planning`),
partPlanningLocation: (id: string, locationId: string) =>
generatePath(`${x}/part/${id}/planning?location=${locationId}`),
@@ -1177,12 +1185,20 @@ export const path = {
toolInventory: (id: string) => generatePath(`${x}/tool/${id}/inventory`),
toolInventoryLocation: (id: string, locationId: string) =>
generatePath(`${x}/tool/${id}/inventory?location=${locationId}`),
- toolMakeMethod: (id: string) =>
- generatePath(`${x}/tool/${id}/manufacturing/method`),
+ toolMethod: (id: string, methodId: string) =>
+ generatePath(`${x}/tool/${id}/manufacturing/${methodId}`),
+ toolMakeMethod: (id: string, methodId: string) =>
+ generatePath(`${x}/tool/${id}/manufacturing/${methodId}/method`),
toolManufacturing: (id: string) =>
generatePath(`${x}/tool/${id}/manufacturing`),
- toolManufacturingMaterial: (itemId: string, makeMethodId: string) =>
- generatePath(`${x}/tool/${itemId}/manufacturing/${makeMethodId}`),
+ toolManufacturingMaterial: (
+ itemId: string,
+ methodId: string,
+ makeMethodId: string
+ ) =>
+ generatePath(
+ `${x}/tool/${itemId}/manufacturing/${methodId}/${makeMethodId}`
+ ),
toolPlanning: (id: string) => generatePath(`${x}/tool/${id}/planning`),
toolPlanningLocation: (id: string, locationId: string) =>
generatePath(`${x}/tool/${id}/planning?location=${locationId}`),
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 60b47bea53..3671ea7a13 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -11054,9 +11054,11 @@ export type Database = {
customFields: Json | null
id: string
itemId: string
+ status: Database["public"]["Enums"]["makeMethodStatus"]
tags: string[] | null
updatedAt: string | null
updatedBy: string | null
+ version: number
}
Insert: {
companyId: string
@@ -11065,9 +11067,11 @@ export type Database = {
customFields?: Json | null
id?: string
itemId: string
+ status?: Database["public"]["Enums"]["makeMethodStatus"]
tags?: string[] | null
updatedAt?: string | null
updatedBy?: string | null
+ version?: number
}
Update: {
companyId?: string
@@ -11076,9 +11080,11 @@ export type Database = {
customFields?: Json | null
id?: string
itemId?: string
+ status?: Database["public"]["Enums"]["makeMethodStatus"]
tags?: string[] | null
updatedAt?: string | null
updatedBy?: string | null
+ version?: number
}
Relationships: [
{
@@ -36579,14 +36585,14 @@ export type Database = {
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["supplierLocationId"]
+ columns: ["id"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["id"]
+ columns: ["supplierLocationId"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
@@ -40137,14 +40143,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["invoiceCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["invoiceCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
@@ -44070,6 +44076,7 @@ export type Database = {
| "Credit Memo"
| "Blanket Order"
| "Return Order"
+ makeMethodStatus: "Draft" | "Active" | "Archived"
methodOperationOrder: "After Previous" | "With Previous"
methodType: "Buy" | "Make" | "Pick"
module:
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 60b47bea53..3671ea7a13 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -11054,9 +11054,11 @@ export type Database = {
customFields: Json | null
id: string
itemId: string
+ status: Database["public"]["Enums"]["makeMethodStatus"]
tags: string[] | null
updatedAt: string | null
updatedBy: string | null
+ version: number
}
Insert: {
companyId: string
@@ -11065,9 +11067,11 @@ export type Database = {
customFields?: Json | null
id?: string
itemId: string
+ status?: Database["public"]["Enums"]["makeMethodStatus"]
tags?: string[] | null
updatedAt?: string | null
updatedBy?: string | null
+ version?: number
}
Update: {
companyId?: string
@@ -11076,9 +11080,11 @@ export type Database = {
customFields?: Json | null
id?: string
itemId?: string
+ status?: Database["public"]["Enums"]["makeMethodStatus"]
tags?: string[] | null
updatedAt?: string | null
updatedBy?: string | null
+ version?: number
}
Relationships: [
{
@@ -36579,14 +36585,14 @@ export type Database = {
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["supplierLocationId"]
+ columns: ["id"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["id"]
+ columns: ["supplierLocationId"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
@@ -40137,14 +40143,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["invoiceCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["invoiceCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
@@ -44070,6 +44076,7 @@ export type Database = {
| "Credit Memo"
| "Blanket Order"
| "Return Order"
+ makeMethodStatus: "Draft" | "Active" | "Archived"
methodOperationOrder: "After Previous" | "With Previous"
methodType: "Buy" | "Make" | "Pick"
module: