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.

fix: get/save method with new navigation

Brad Barbin94569205706e
diff --git a/apps/erp/app/modules/production/production.service.ts b/apps/erp/app/modules/production/production.service.ts
index 0b6f3bc589..c6dc6ef106 100644
--- a/apps/erp/app/modules/production/production.service.ts
+++ b/apps/erp/app/modules/production/production.service.ts
@@ -1179,20 +1179,11 @@ export async function upsertJobMaterialMakeMethod(
userId: string;
}
) {
- const makeMethod = await client
- .from("jobMakeMethod")
- .select("id")
- .eq("parentMaterialId", jobMaterial.targetId)
- .single();
- if (makeMethod.error) {
- return makeMethod;
- }
-
const { error } = await client.functions.invoke("get-method", {
body: {
type: "itemToJobMakeMethod",
sourceId: jobMaterial.sourceId,
- targetId: makeMethod.data.id,
+ targetId: jobMaterial.targetId,
companyId: jobMaterial.companyId,
userId: jobMaterial.userId,
},
@@ -1237,19 +1228,10 @@ export async function upsertMakeMethodFromJobMethod(
userId: string;
}
) {
- const makeMethod = await client
- .from("jobMakeMethod")
- .select("id")
- .eq("parentMaterialId", jobMethod.sourceId)
- .single();
- if (makeMethod.error) {
- return makeMethod;
- }
-
const { error } = await client.functions.invoke("get-method", {
body: {
type: "jobMakeMethodToItem",
- sourceId: makeMethod.data.id,
+ sourceId: jobMethod.sourceId,
targetId: jobMethod.targetId,
companyId: jobMethod.companyId,
userId: jobMethod.userId,
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobMakeMethodTools.tsx b/apps/erp/app/modules/production/ui/Jobs/JobMakeMethodTools.tsx
index 7e311ce346..0725c96a9e 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobMakeMethodTools.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobMakeMethodTools.tsx
@@ -32,7 +32,6 @@ import {
useFetcher,
useLocation,
useParams,
- useSearchParams,
} from "@remix-run/react";
import { Suspense, useEffect, useState } from "react";
import {
@@ -64,8 +63,6 @@ const JobMakeMethodTools = ({ makeMethod }: { makeMethod?: JobMakeMethod }) => {
const permissions = usePermissions();
const { jobId, methodId } = useParams();
if (!jobId) throw new Error("jobId not found");
- const [searchParams] = useSearchParams();
- const materialId = searchParams.get("materialId");
const fetcher = useFetcher<{ error: string | null }>();
const routeData = useRouteData<{
@@ -79,7 +76,7 @@ const JobMakeMethodTools = ({ makeMethod }: { makeMethod?: JobMakeMethod }) => {
const materialRouteData = useRouteData<{
makeMethod: JobMakeMethod;
- }>(path.to.jobMakeMethod(jobId, methodId!, materialId!));
+ }>(path.to.jobMakeMethod(jobId, methodId!, methodId!));
const itemId =
materialRouteData?.makeMethod?.itemId ?? routeData?.job?.itemId;
@@ -185,8 +182,6 @@ const JobMakeMethodTools = ({ makeMethod }: { makeMethod?: JobMakeMethod }) => {
}
};
- console.log({ makeMethod });
-
return (
<>
{permissions.can("update", "production") &&
@@ -316,7 +311,7 @@ const JobMakeMethodTools = ({ makeMethod }: { makeMethod?: JobMakeMethod }) => {
) : (
<>
<Hidden name="type" value="method" />
- <Hidden name="targetId" value={materialId!} />
+ <Hidden name="targetId" value={methodId!} />
</>
)}
@@ -408,7 +403,7 @@ const JobMakeMethodTools = ({ makeMethod }: { makeMethod?: JobMakeMethod }) => {
) : (
<>
<Hidden name="type" value="method" />
- <Hidden name="sourceId" value={materialId!} />
+ <Hidden name="sourceId" value={methodId!} />
</>
)}
diff --git a/apps/erp/app/modules/sales/sales.service.ts b/apps/erp/app/modules/sales/sales.service.ts
index 7ae33aeef4..b738fa7902 100644
--- a/apps/erp/app/modules/sales/sales.service.ts
+++ b/apps/erp/app/modules/sales/sales.service.ts
@@ -1860,29 +1860,20 @@ export async function upsertMakeMethodFromQuoteLine(
export async function upsertMakeMethodFromQuoteMethod(
client: SupabaseClient<Database>,
- quoteMaterial: {
- quoteMaterialId: string;
- itemId: string;
+ quoteMethod: {
+ sourceId: string;
+ targetId: string;
companyId: string;
- createdBy: string;
+ userId: string;
}
) {
- const makeMethod = await client
- .from("quoteMakeMethod")
- .select("id")
- .eq("parentMaterialId", quoteMaterial.quoteMaterialId)
- .single();
- if (makeMethod.error) {
- return makeMethod;
- }
-
const { error } = await client.functions.invoke("get-method", {
body: {
type: "quoteMakeMethodToItem",
- sourceId: makeMethod.data.id,
- targetId: quoteMaterial.itemId,
- companyId: quoteMaterial.companyId,
- userId: quoteMaterial.createdBy,
+ sourceId: quoteMethod.sourceId,
+ targetId: quoteMethod.targetId,
+ companyId: quoteMethod.companyId,
+ userId: quoteMethod.userId,
},
});
@@ -2235,29 +2226,20 @@ export async function upsertQuoteMaterial(
export async function upsertQuoteMaterialMakeMethod(
client: SupabaseClient<Database>,
- quoteMaterial: {
- quoteMaterialId: string;
- itemId: string;
+ quoteMethod: {
+ sourceId: string;
+ targetId: string;
companyId: string;
- createdBy: string;
+ userId: string;
}
) {
- const makeMethod = await client
- .from("quoteMakeMethod")
- .select("id")
- .eq("parentMaterialId", quoteMaterial.quoteMaterialId)
- .single();
- if (makeMethod.error) {
- return makeMethod;
- }
-
const { error } = await client.functions.invoke("get-method", {
body: {
type: "itemToQuoteMakeMethod",
- sourceId: quoteMaterial.itemId,
- targetId: makeMethod.data.id,
- companyId: quoteMaterial.companyId,
- userId: quoteMaterial.createdBy,
+ sourceId: quoteMethod.sourceId,
+ targetId: quoteMethod.targetId,
+ companyId: quoteMethod.companyId,
+ userId: quoteMethod.userId,
},
});
diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteMakeMethodTools.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteMakeMethodTools.tsx
index 89b587fa0d..0bbc14c2ce 100644
--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteMakeMethodTools.tsx
+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteMakeMethodTools.tsx
@@ -30,7 +30,6 @@ import {
useFetcher,
useLocation,
useParams,
- useSearchParams,
} from "@remix-run/react";
import { Suspense, useEffect, useState } from "react";
import {
@@ -62,9 +61,6 @@ const QuoteMakeMethodTools = () => {
const { quoteId, lineId, methodId } = useParams();
if (!quoteId) throw new Error("quoteId not found");
- const [searchParams] = useSearchParams();
- const materialId = searchParams.get("materialId");
-
const fetcher = useFetcher<{ error: string | null }>();
const routeData = useRouteData<{
quote: Quotation;
@@ -74,14 +70,7 @@ const QuoteMakeMethodTools = () => {
const materialRouteData = useRouteData<{
makeMethod: { itemId: string; itemType: MethodItemType | null };
- }>(
- path.to.quoteLineMakeMethod(
- quoteId,
- lineId!,
- methodId!,
- materialId ?? undefined
- )
- );
+ }>(path.to.quoteLineMakeMethod(quoteId, lineId!, methodId!));
const itemId =
materialRouteData?.makeMethod?.itemId ??
@@ -298,7 +287,7 @@ const QuoteMakeMethodTools = () => {
) : (
<>
<Hidden name="type" value="method" />
- <Hidden name="targetId" value={materialId!} />
+ <Hidden name="targetId" value={methodId!} />
<VStack spacing={4}>
<Item
name="sourceId"
@@ -386,7 +375,7 @@ const QuoteMakeMethodTools = () => {
) : (
<>
<Hidden name="type" value="method" />
- <Hidden name="sourceId" value={materialId!} />
+ <Hidden name="sourceId" value={methodId!} />
</>
)}
diff --git a/apps/erp/app/routes/x+/quote+/methods+/get.tsx b/apps/erp/app/routes/x+/quote+/methods+/get.tsx
index 39e5163671..15b1177082 100644
--- a/apps/erp/app/routes/x+/quote+/methods+/get.tsx
+++ b/apps/erp/app/routes/x+/quote+/methods+/get.tsx
@@ -64,14 +64,10 @@ export async function action({ request }: ActionFunctionArgs) {
return validationError(validation.error);
}
- const quoteMaterialId = validation.data.targetId;
- const itemId = validation.data.sourceId;
-
const makeMethod = await upsertQuoteMaterialMakeMethod(serviceRole, {
- itemId,
- quoteMaterialId,
+ ...validation.data,
companyId,
- createdBy: userId,
+ userId,
});
if (makeMethod.error) {
diff --git a/apps/erp/app/routes/x+/quote+/methods+/save.tsx b/apps/erp/app/routes/x+/quote+/methods+/save.tsx
index fdabd1eabc..7ee9a2a066 100644
--- a/apps/erp/app/routes/x+/quote+/methods+/save.tsx
+++ b/apps/erp/app/routes/x+/quote+/methods+/save.tsx
@@ -49,14 +49,10 @@ export async function action({ request }: ActionFunctionArgs) {
return validationError(validation.error);
}
- const quoteMaterialId = validation.data.targetId;
- const itemId = validation.data.sourceId;
-
const makeMethod = await upsertMakeMethodFromQuoteMethod(serviceRole, {
- quoteMaterialId,
- itemId,
+ ...validation.data,
companyId,
- createdBy: userId,
+ userId,
});
if (makeMethod.error) {