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: save quote line method operations

Brad Barbinbc3408e7d99c
diff --git a/apps/carbon/app/components/Table/Table.tsx b/apps/carbon/app/components/Table/Table.tsx
index e7df046adf..7d152e6e5a 100644
--- a/apps/carbon/app/components/Table/Table.tsx
+++ b/apps/carbon/app/components/Table/Table.tsx
@@ -557,7 +557,7 @@ const Table = <T extends object>({
<div className="flex max-w-full h-full">
<TableBase
ref={tableRef}
- className="relative table-fixed border-separate border-spacing-0"
+ className="relative table-fixed border-collapse border-spacing-0"
>
<Thead className="sticky top-0 z-10">
{table.getHeaderGroups().map((headerGroup) => (
diff --git a/packages/database/supabase/functions/get-method/index.ts b/packages/database/supabase/functions/get-method/index.ts
index 9a6c6aa08b..db98e8065e 100644
--- a/packages/database/supabase/functions/get-method/index.ts
+++ b/packages/database/supabase/functions/get-method/index.ts
@@ -430,7 +430,7 @@ serve(async (req: Request) => {
.is("parentMaterialId", null)
.single(),
client
- .from("quoteOperation")
+ .from("quoteOperationsWithMakeMethods")
.select("*")
.eq("quoteLineId", quoteLineId),
]);
@@ -480,20 +480,7 @@ serve(async (req: Request) => {
makeMethodByItemId[m.itemId] = m.id;
});
- const operationsByQuoteMethodId: Record<
- string,
- typeof quoteOperations.data
- > = {};
- quoteOperations.data?.forEach((op) => {
- if (!operationsByQuoteMethodId[op.quoteMakeMethodId!]) {
- operationsByQuoteMethodId[op.quoteMakeMethodId!] = [];
- }
- operationsByQuoteMethodId[op.quoteMakeMethodId!].push(op);
- });
-
await db.transaction().execute(async (trx) => {
- // delete existing makeMaterials and makeOperations for any made quote method
-
const makeMethodsToDelete: string[] = [];
const materialInserts: Database["public"]["Tables"]["methodMaterial"]["Insert"][] =
[];
@@ -505,10 +492,6 @@ serve(async (req: Request) => {
makeMethodsToDelete.push(makeMethodByItemId[node.data.itemId]);
}
- const relatedOperations =
- operationsByQuoteMethodId[node.data.quoteMakeMethodId];
- console.log({ node, relatedOperations });
-
node.children.forEach((child) => {
materialInserts.push({
makeMethodId: makeMethodByItemId[node.data.itemId],
@@ -540,10 +523,36 @@ serve(async (req: Request) => {
]);
}
- await trx
- .insertInto("methodMaterial")
- .values(materialInserts)
- .execute();
+ if (materialInserts.length > 0) {
+ await trx
+ .insertInto("methodMaterial")
+ .values(materialInserts)
+ .execute();
+ }
+
+ quoteOperations.data?.forEach((op) => {
+ operationInserts.push({
+ makeMethodId: op.makeMethodId,
+ description: op.description ?? "",
+ workCellTypeId: op.workCellTypeId,
+ equipmentTypeId: op.equipmentTypeId,
+ setupHours: op.setupHours,
+ standardFactor: op.standardFactor,
+ productionStandard: op.productionStandard,
+ order: op.order,
+ operationOrder: op.operationOrder,
+ companyId,
+ createdBy: userId,
+ customFields: {},
+ });
+ });
+
+ if (operationInserts.length > 0) {
+ await trx
+ .insertInto("methodOperation")
+ .values(operationInserts)
+ .execute();
+ }
});
break;
diff --git a/packages/database/supabase/migrations/20240811205828_quote-operations-with-make-methods.sql b/packages/database/supabase/migrations/20240811205828_quote-operations-with-make-methods.sql
new file mode 100644
index 0000000000..3275df665a
--- /dev/null
+++ b/packages/database/supabase/migrations/20240811205828_quote-operations-with-make-methods.sql
@@ -0,0 +1,9 @@
+CREATE OR REPLACE VIEW "quoteOperationsWithMakeMethods" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ mm.id AS "makeMethodId",
+ qo.*
+ FROM "quoteOperation" qo
+ INNER JOIN "quoteMakeMethod" qmm
+ ON qo."quoteMakeMethodId" = qmm.id
+ LEFT JOIN "makeMethod" mm
+ ON qmm."itemId" = mm."itemId";
\ No newline at end of file