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: update method materials when we make the revision the default revision

Brad Barbina02f4743eaab
diff --git a/apps/erp/app/modules/items/items.service.ts b/apps/erp/app/modules/items/items.service.ts
index a9fa0b7766..9f1a6de699 100644
--- a/apps/erp/app/modules/items/items.service.ts
+++ b/apps/erp/app/modules/items/items.service.ts
@@ -1328,6 +1328,40 @@ export async function updateConfigurationParameterGroupOrder(
.eq("id", data.id);
}
+export async function updateDefaultRevision(
+ client: SupabaseClient<Database>,
+ data: {
+ id: string;
+ updatedBy: string;
+ }
+) {
+ const [item, makeMethod] = await Promise.all([
+ client
+ .from("item")
+ .select("id,readableId, readableIdWithRevision")
+ .eq("id", data.id)
+ .single(),
+ client.from("makeMethod").select("id").eq("itemId", data.id).maybeSingle(),
+ ]);
+ if (item.error) return item;
+ const readableId = item.data.readableId;
+ const relatedItems = await client
+ .from("item")
+ .select("id")
+ .eq("readableId", readableId);
+
+ const itemIds = relatedItems.data?.map((item) => item.id) ?? [];
+
+ return client
+ .from("methodMaterial")
+ .update({
+ itemId: item.data.id,
+ itemReadableId: item.data.readableId,
+ materialMakeMethodId: makeMethod.data?.id,
+ })
+ .in("itemId", itemIds);
+}
+
export async function updateConfigurationParameterOrder(
client: SupabaseClient<Database>,
data: Omit<
diff --git a/apps/erp/app/modules/items/ui/Item/UsedIn.tsx b/apps/erp/app/modules/items/ui/Item/UsedIn.tsx
index 4f077f3f59..b6409ab411 100644
--- a/apps/erp/app/modules/items/ui/Item/UsedIn.tsx
+++ b/apps/erp/app/modules/items/ui/Item/UsedIn.tsx
@@ -314,10 +314,7 @@ export function RevisionsItem({
)}
{defaultDisclosure.isOpen && selectedRevision && (
<Confirm
- action={path.to.defaultRevision(
- selectedRevision.id,
- selectedRevision.revision
- )}
+ action={path.to.defaultRevision(selectedRevision.id!)}
confirmText="Make Default"
title={`Make revision ${selectedRevision.revision} default?`}
text="This will replace all method materials of other revisions with this revision."
diff --git a/apps/erp/app/routes/x+/items+/revisions.default.$id.$revisionId.tsx b/apps/erp/app/routes/x+/items+/revisions.default.$id.$revisionId.tsx
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/apps/erp/app/utils/path.ts b/apps/erp/app/utils/path.ts
index bd97a06ecb..ddf78c9d68 100644
--- a/apps/erp/app/utils/path.ts
+++ b/apps/erp/app/utils/path.ts
@@ -378,8 +378,8 @@ export const path = {
deactivateGauge: (id: string) =>
generatePath(`${x}/quality/gauges/deactivate/${id}`),
deactivateUsers: `${x}/users/deactivate`,
- defaultRevision: (id: string, revision: string) =>
- generatePath(`${x}/items/revisions/default/${id}/${revision}`),
+ defaultRevision: (id: string) =>
+ generatePath(`${x}/items/revisions/default/${id}`),
deleteAbility: (id: string) =>
generatePath(`${x}/resources/abilities/delete/${id}`),
deleteAccountingCategory: (id: string) =>