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: make it so make methods are not 1:1 for items

Brad Barbin1dc0df1fc3de
diff --git a/apps/erp/app/modules/items/items.service.ts b/apps/erp/app/modules/items/items.service.ts
index 6324f54f1b..8f7a5e6282 100644
--- a/apps/erp/app/modules/items/items.service.ts
+++ b/apps/erp/app/modules/items/items.service.ts
@@ -708,7 +708,7 @@ export async function getPartUsedIn(
};
}
-export async function getMakeMethod(
+export async function getMakeMethods(
client: SupabaseClient<Database>,
itemId: string,
companyId: string
@@ -1977,6 +1977,7 @@ export async function upsertMethodMaterial(
let materialMakeMethodId: string | null = null;
if (methodMaterial.methodType === "Make") {
const makeMethod = await client
+ // TODO: get we need to pass the make method since there can be multiple
.from("makeMethod")
.select("id")
.eq("itemId", methodMaterial.itemId!)
diff --git a/apps/erp/app/modules/items/ui/Item/MakeMethodTools.tsx b/apps/erp/app/modules/items/ui/Item/MakeMethodTools.tsx
index 0839206bc0..a3fd61932e 100644
--- a/apps/erp/app/modules/items/ui/Item/MakeMethodTools.tsx
+++ b/apps/erp/app/modules/items/ui/Item/MakeMethodTools.tsx
@@ -4,6 +4,13 @@ import {
AlertTitle,
Button,
Checkbox,
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuIcon,
+ DropdownMenuItem,
+ DropdownMenuLabel,
+ DropdownMenuSeparator,
+ DropdownMenuTrigger,
HStack,
Menubar,
MenubarItem,
@@ -21,9 +28,12 @@ import {
import { Link, useFetcher } from "@remix-run/react";
import { useEffect, useState } from "react";
import {
+ LuChevronDown,
+ LuCirclePlus,
LuGitBranch,
LuGitFork,
LuGitMerge,
+ LuGitPullRequestArrow,
LuTriangleAlert,
} from "react-icons/lu";
import { Hidden, Item } from "~/components/Form";
@@ -36,9 +46,13 @@ import { getLinkToItemDetails } from "./ItemForm";
type MakeMethodToolsProps = {
itemId: string;
type: MethodItemType;
+ revisions: {
+ id: string;
+ name: string;
+ }[];
};
-const MakeMethodTools = ({ itemId, type }: MakeMethodToolsProps) => {
+const MakeMethodTools = ({ itemId, revisions, type }: MakeMethodToolsProps) => {
const permissions = usePermissions();
const fetcher = useFetcher<{ error: string | null }>();
@@ -57,13 +71,13 @@ const MakeMethodTools = ({ itemId, type }: MakeMethodToolsProps) => {
const getMethodModal = useDisclosure();
const saveMethodModal = useDisclosure();
-
+ const newVersionDisclosure = useDisclosure();
const itemLink = type && itemId ? getLinkToItemDetails(type, itemId) : null;
return (
<>
<Menubar>
- <HStack className="w-full justify-start">
+ <HStack className="w-full justify-between">
<HStack spacing={0}>
<MenubarItem
isLoading={isGetMethodLoading}
@@ -93,6 +107,41 @@ const MakeMethodTools = ({ itemId, type }: MakeMethodToolsProps) => {
</MenubarItem>
)}
</HStack>
+
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button
+ variant="ghost"
+ leftIcon={<LuGitPullRequestArrow />}
+ rightIcon={<LuChevronDown />}
+ >
+ Versions
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ {permissions.can("create", "production") && (
+ <DropdownMenuItem onClick={newVersionDisclosure.onOpen}>
+ <DropdownMenuIcon icon={<LuCirclePlus />} />
+ New Version
+ </DropdownMenuItem>
+ )}
+ {revisions && revisions.length > 0 && (
+ <>
+ <DropdownMenuLabel>Version History</DropdownMenuLabel>
+ <DropdownMenuSeparator />
+ {revisions.map((revision) => (
+ <Link
+ key={revision.id}
+ to={path.to.procedure(revision.id)}
+ className="relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors hover:bg-accent hover:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50"
+ >
+ {revision.name}
+ </Link>
+ ))}
+ </>
+ )}
+ </DropdownMenuContent>
+ </DropdownMenu>
</HStack>
</Menubar>
diff --git a/apps/erp/app/routes/x+/part+/$itemId.manufacturing.tsx b/apps/erp/app/routes/x+/part+/$itemId.manufacturing.tsx
index b52c7f5a2f..e7682631df 100644
--- a/apps/erp/app/routes/x+/part+/$itemId.manufacturing.tsx
+++ b/apps/erp/app/routes/x+/part+/$itemId.manufacturing.tsx
@@ -25,7 +25,7 @@ import {
getConfigurationParameters,
getConfigurationRules,
getItemManufacturing,
- getMakeMethod,
+ getMakeMethods,
getMethodMaterialsByMakeMethod,
getMethodOperationsByMakeMethodId,
getMethodTree,
@@ -43,14 +43,14 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
const { itemId } = params;
if (!itemId) throw new Error("Could not find itemId");
- const makeMethod = await getMakeMethod(client, itemId, companyId);
+ const makeMethods = await getMakeMethods(client, itemId, companyId);
- if (makeMethod.error) {
+ if (makeMethods.error) {
throw redirect(
path.to.partDetails(itemId),
await flash(
request,
- error(makeMethod.error, "Failed to load make method")
+ error(makeMethods.error, "Failed to load make methods")
)
);
}
diff --git a/apps/erp/app/routes/x+/tool+/$itemId.manufacturing.tsx b/apps/erp/app/routes/x+/tool+/$itemId.manufacturing.tsx
index 387817aca0..c1641cc4f2 100644
--- a/apps/erp/app/routes/x+/tool+/$itemId.manufacturing.tsx
+++ b/apps/erp/app/routes/x+/tool+/$itemId.manufacturing.tsx
@@ -22,7 +22,7 @@ import type { FlatTreeItem } from "~/components/TreeView";
import { flattenTree } from "~/components/TreeView";
import type { Method } from "~/modules/items";
import {
- getMakeMethod,
+ getMakeMethods,
getMethodMaterialsByMakeMethod,
getMethodOperationsByMakeMethodId,
getMethodTree,
@@ -40,7 +40,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
const { itemId } = params;
if (!itemId) throw new Error("Could not find itemId");
- const makeMethod = await getMakeMethod(client, itemId, companyId);
+ const makeMethods = await getMakeMethods(client, itemId, companyId);
if (makeMethod.error) {
throw redirect(
diff --git a/packages/database/supabase/migrations/20250516124051_revisions.sql b/packages/database/supabase/migrations/20250516124051_revisions.sql
new file mode 100644
index 0000000000..591dfa2a8a
--- /dev/null
+++ b/packages/database/supabase/migrations/20250516124051_revisions.sql
@@ -0,0 +1,4 @@
+
+ALTER TABLE "makeMethod" DROP CONSTRAINT "makeMethod_unique_itemId";
+ALTER TABLE "makeMethod" ADD CONSTRAINT "makeMethod_unique_itemId_revision" UNIQUE ("itemId", "revision");
+ALTER TABLE "makeMethod" ADD COLUMN "revision" TEXT NOT NULL DEFAULT '0';