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 server methods for operations

Brad Barbin94fae6226318
diff --git a/apps/carbon/app/modules/sales/sales.service.ts b/apps/carbon/app/modules/sales/sales.service.ts
index 257a2318db..32236e17f9 100644
--- a/apps/carbon/app/modules/sales/sales.service.ts
+++ b/apps/carbon/app/modules/sales/sales.service.ts
@@ -12,6 +12,7 @@ import type {
customerValidator,
quotationAssemblyValidator,
quotationLineValidator,
+ quotationOperationValidator,
quotationValidator,
} from "./sales.models";
@@ -67,6 +68,13 @@ export async function deleteQuoteLine(
return client.from("quoteLine").delete().eq("id", quoteLineId);
}
+export async function deleteQuoteOperation(
+ client: SupabaseClient<Database>,
+ quoteOperationId: string
+) {
+ return client.from("quoteOperation").delete().eq("id", quoteOperationId);
+}
+
export async function getCustomer(
client: SupabaseClient<Database>,
customerId: string
@@ -282,6 +290,23 @@ export async function getQuoteAssembly(
.single();
}
+export async function getQuoteAssembliesByLine(
+ client: SupabaseClient<Database>,
+ quoteLineId: string
+) {
+ return client
+ .from("quoteAssembly")
+ .select("*")
+ .eq("quoteLineId", quoteLineId);
+}
+
+export async function getQuoteAssembliesByQuote(
+ client: SupabaseClient<Database>,
+ quoteId: string
+) {
+ return client.from("quoteAssembly").select("*").eq("quoteId", quoteId);
+}
+
export async function getQuoteExternalDocuments(
client: SupabaseClient<Database>,
quoteId: string
@@ -320,6 +345,34 @@ export async function getQuoteLineQuantities(
.eq("quoteLineId", quoteLineId);
}
+export async function getQuoteOperation(
+ client: SupabaseClient<Database>,
+ quoteOperationId: string
+) {
+ return client
+ .from("quoteOperation")
+ .select("*")
+ .eq("id", quoteOperationId)
+ .single();
+}
+
+export async function getQuoteOperationsByLine(
+ client: SupabaseClient<Database>,
+ quoteLineId: string
+) {
+ return client
+ .from("quoteOperation")
+ .select("*")
+ .eq("quoteLineId", quoteLineId);
+}
+
+export async function getQuoteOperationsByQuote(
+ client: SupabaseClient<Database>,
+ quoteId: string
+) {
+ return client.from("quoteOperation").select("*").eq("quoteId", quoteId);
+}
+
export async function insertCustomer(
client: SupabaseClient<Database>,
customer:
@@ -644,3 +697,33 @@ export async function upsertQuoteLine(
}
return client.from("quoteLine").insert([quotationLine]).select("id").single();
}
+
+export async function upsertQuoteOperation(
+ client: SupabaseClient<Database>,
+ quotationOperation:
+ | (Omit<TypeOfValidator<typeof quotationOperationValidator>, "id"> & {
+ quoteId: string;
+ quoteLineId: string;
+ createdBy: string;
+ })
+ | (Omit<TypeOfValidator<typeof quotationOperationValidator>, "id"> & {
+ id: string;
+ quoteId: string;
+ quoteLineId: string;
+ updatedBy: string;
+ })
+) {
+ if ("id" in quotationOperation) {
+ return client
+ .from("quoteOperation")
+ .update(sanitize(quotationOperation))
+ .eq("id", quotationOperation.id)
+ .select("id")
+ .single();
+ }
+ return client
+ .from("quoteOperation")
+ .insert([quotationOperation])
+ .select("id")
+ .single();
+}
diff --git a/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.assembly.$assemblyId.delete.tsx b/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.assembly.$assemblyId.delete.tsx
index e02b80b0fc..cda0eac7d6 100644
--- a/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.assembly.$assemblyId.delete.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.assembly.$assemblyId.delete.tsx
@@ -38,6 +38,8 @@ export async function action({ request, params }: ActionFunctionArgs) {
}
export default function DeleteQuoteAssembly() {
+ const navigate = useNavigate();
+
const { id, lineId, assemblyId } = useParams();
if (!id) throw new Error("id not found");
if (!lineId) throw new Error("lineId not found");
@@ -46,19 +48,15 @@ export default function DeleteQuoteAssembly() {
const routeData = useRouteData<{ quoteAssembly: QuotationAssembly }>(
path.to.quoteAssembly(id, lineId, assemblyId)
);
- const navigate = useNavigate();
if (!routeData?.quoteAssembly) throw new Error("quote assembly not found");
- const onCancel = () =>
- navigate(path.to.quoteAssembly(id, lineId, assemblyId));
-
return (
<ConfirmDelete
action={path.to.deleteQuoteAssembly(id, lineId, assemblyId)}
name={routeData?.quoteAssembly.partId}
text={`Are you sure you want to delete the assembly: ${routeData?.quoteAssembly.partId}? This cannot be undone.`}
- onCancel={onCancel}
+ onCancel={() => navigate(path.to.quoteAssembly(id, lineId, assemblyId))}
/>
);
}
diff --git a/apps/carbon/app/routes/x+/quote+/$id.tsx b/apps/carbon/app/routes/x+/quote+/$id.tsx
index 511bbd49df..120fb3c481 100644
--- a/apps/carbon/app/routes/x+/quote+/$id.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$id.tsx
@@ -171,119 +171,119 @@ const data: BillOfMaterialNode[] = [
type: "parent",
children: [
{
- id: "cna3ivpvo0l18j8abtlg",
+ id: "cnad6opvo0l053gabtp0",
label: "P000000001",
type: "line",
children: [
{
- id: "cna3ivpvo0l18j8abtlg",
+ id: "cnad6opvo0l053gabtp0",
// parentId: "cn9v3tldq0l1lvlkrqmg",
label: "Assemblies",
type: "assemblies",
},
{
- id: "cna3ivpvo0l18j8abtlg",
+ id: "cnad6opvo0l053gabtp0",
label: "Operations",
type: "operations",
},
],
},
- // {
- // id: "2",
- // label: "P00001233",
- // type: "line",
- // children: [
- // {
- // id: "3",
- // label: "Assemblies",
- // type: "assemblies",
- // children: [
- // {
- // id: "4",
- // label: "F5000123",
- // type: "assembly",
- // children: [
- // {
- // id: "5",
- // label: "Assemblies",
- // type: "assemblies",
- // children: [],
- // },
- // {
- // id: "6",
- // label: "Operations",
- // type: "operations",
- // children: [
- // {
- // id: "7",
- // label: "OP0003",
- // type: "operation",
- // children: [
- // {
- // id: "8",
- // label: "Materials",
- // type: "materials",
- // children: [
- // {
- // id: "9",
- // label: "RAW000001",
- // type: "material",
- // },
- // {
- // id: "10",
- // label: "FAS000002",
- // type: "material",
- // },
- // ],
- // },
- // ],
- // },
- // ],
- // },
- // ],
- // },
- // ],
- // },
- // {
- // id: "11",
- // label: "Operations",
- // type: "operations",
- // children: [
- // {
- // id: "12",
- // label: "OP0001",
- // type: "operation",
- // children: [
- // {
- // id: "13",
- // label: "Materials",
- // type: "materials",
- // children: [
- // {
- // id: "14",
- // label: "RAW000003",
- // type: "material",
- // },
- // ],
- // },
- // ],
- // },
- // {
- // id: "13",
- // label: "OP0002",
- // type: "operation",
- // children: [
- // {
- // id: "13",
- // label: "Materials",
- // type: "materials",
- // },
- // ],
- // },
- // ],
- // },
- // ],
- // },
+ {
+ id: "2",
+ label: "P00001233",
+ type: "line",
+ children: [
+ {
+ id: "3",
+ label: "Assemblies",
+ type: "assemblies",
+ children: [
+ {
+ id: "4",
+ label: "F5000123",
+ type: "assembly",
+ children: [
+ {
+ id: "5",
+ label: "Assemblies",
+ type: "assemblies",
+ children: [],
+ },
+ {
+ id: "6",
+ label: "Operations",
+ type: "operations",
+ children: [
+ {
+ id: "7",
+ label: "OP0003",
+ type: "operation",
+ children: [
+ {
+ id: "8",
+ label: "Materials",
+ type: "materials",
+ children: [
+ {
+ id: "9",
+ label: "RAW000001",
+ type: "material",
+ },
+ {
+ id: "10",
+ label: "FAS000002",
+ type: "material",
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ {
+ id: "11",
+ label: "Operations",
+ type: "operations",
+ children: [
+ {
+ id: "12",
+ label: "OP0001",
+ type: "operation",
+ children: [
+ {
+ id: "13",
+ label: "Materials",
+ type: "materials",
+ children: [
+ {
+ id: "14",
+ label: "RAW000003",
+ type: "material",
+ },
+ ],
+ },
+ ],
+ },
+ {
+ id: "13",
+ label: "OP0002",
+ type: "operation",
+ children: [
+ {
+ id: "13",
+ label: "Materials",
+ type: "materials",
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ },
],
},
];