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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
fix: support no customer part revision
Brad Barbin1b6e570fdb41
diff --git a/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQForm.tsx b/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQForm.tsxindex 9c1af54727..bd3c014277 100644--- a/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQForm.tsx+++ b/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQForm.tsx@@ -79,12 +79,17 @@ const SalesRFQForm = ({ initialValues }: SalesRFQFormProps) => {setCustomer(newValue?.value as string | undefined)}/>+ <Input name="customerReference" label="Customer Ref. Number" /><CustomerLocationname="customerLocationId"label="Customer Location"customer={customer}/>- <Input name="customerReference" label="Customer Ref. Number" />+ <CustomerContact+ name="customerContactId"+ label="Customer Contact"+ customer={customer}+ />{isEditing && permissions.can("delete", "sales") && (<Selectname="status"@@ -95,12 +100,6 @@ const SalesRFQForm = ({ initialValues }: SalesRFQFormProps) => {/>)}- <CustomerContact- name="customerContactId"- label="Customer Contact"- customer={customer}- />-<DatePickername="rfqDate"label="RFQ Date"diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.delete.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.delete.tsxnew file mode 100644index 0000000000..faf1a394e3--- /dev/null+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.delete.tsx@@ -0,0 +1,33 @@+import { json, redirect } from "@remix-run/react";++import type { ActionFunctionArgs } from "@remix-run/node";+import { deleteQuote } from "~/modules/sales";+import { requirePermissions } from "~/services/auth/auth.server";+import { flash } from "~/services/session.server";+import { assertIsPost } from "~/utils/http";+import { path } from "~/utils/path";+import { error } from "~/utils/result";++export async function action({ request, params }: ActionFunctionArgs) {+ assertIsPost(request);+ const { client } = await requirePermissions(request, {+ delete: "sales",+ });++ const { quoteId } = params;+ if (!quoteId) throw new Error("Could not find quoteId");++ const quoteDelete = await deleteQuote(client, quoteId);++ if (quoteDelete.error) {+ return json(+ path.to.quotes,+ await flash(+ request,+ error(quoteDelete.error, "Failed to delete quote line")+ )+ );+ }++ throw redirect(path.to.quotes);+}diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.tsindex bb5c67625a..e5268585bf 100644--- a/apps/carbon/app/utils/path.ts+++ b/apps/carbon/app/utils/path.ts@@ -234,7 +234,7 @@ export const path = {generatePath(`${x}/purchase-order/delete/${id}`),deletePurchaseOrderLine: (orderId: string, lineId: string) =>generatePath(`${x}/purchase-order/${orderId}/lines/delete/${lineId}`),- deleteQuote: (id: string) => generatePath(`${x}/quote/delete/${id}`),+ deleteQuote: (id: string) => generatePath(`${x}/quote/${id}/delete`),deleteQuoteLine: (id: string, lineId: string) =>generatePath(`${x}/quote/${id}/${lineId}/delete`),deleteQuoteLineCost: (quoteId: string, lineId: string) =>diff --git a/packages/database/src/types.ts b/packages/database/src/types.tsindex a90cd1d59e..16350fca18 100644--- a/packages/database/src/types.ts+++ b/packages/database/src/types.ts@@ -3406,21 +3406,21 @@ export type Database = {companyId: stringcustomerId: stringcustomerPartId: string- customerPartRevision: string+ customerPartRevision: string | nullitemId: string}Insert: {companyId: stringcustomerId: stringcustomerPartId: string- customerPartRevision: string+ customerPartRevision?: string | nullitemId: string}Update: {companyId?: stringcustomerId?: stringcustomerPartId?: string- customerPartRevision?: string+ customerPartRevision?: string | nullitemId?: string}Relationships: [diff --git a/packages/database/supabase/functions/convert/index.ts b/packages/database/supabase/functions/convert/index.tsindex 374cf1bb8d..83bc7121f8 100644--- a/packages/database/supabase/functions/convert/index.ts+++ b/packages/database/supabase/functions/convert/index.ts@@ -143,15 +143,20 @@ serve(async (req: Request) => {companyId,customerId: salesRfq.data?.customerId!,customerPartId: line.customerPartId!,- customerPartRevision: line.customerPartRevision,+ customerPartRevision: line.customerPartRevision ?? "",itemId: line.itemId!,})).filter((line) => !!line.itemId && !!line.customerPartId);if (customerPartToItemInserts.length > 0) {await trx.insertInto("customerPartToItem")- // @ts-ignore ...values(customerPartToItemInserts)+ .onConflict((oc) =>+ oc.columns(["customerId", "itemId"]).doUpdateSet((eb) => ({+ customerPartId: eb.ref("excluded.customerPartId"),+ customerPartRevision: eb.ref("excluded.customerPartRevision"),+ }))+ ).execute();}diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.tsindex a90cd1d59e..16350fca18 100644--- a/packages/database/supabase/functions/lib/types.ts+++ b/packages/database/supabase/functions/lib/types.ts@@ -3406,21 +3406,21 @@ export type Database = {companyId: stringcustomerId: stringcustomerPartId: string- customerPartRevision: string+ customerPartRevision: string | nullitemId: string}Insert: {companyId: stringcustomerId: stringcustomerPartId: string- customerPartRevision: string+ customerPartRevision?: string | nullitemId: string}Update: {companyId?: stringcustomerId?: stringcustomerPartId?: string- customerPartRevision?: string+ customerPartRevision?: string | nullitemId?: string}Relationships: [diff --git a/packages/database/supabase/migrations/20240811231527_convert-rfq.sql b/packages/database/supabase/migrations/20240811231527_convert-rfq.sqlindex 2d8f1bfeea..9746c73387 100644--- a/packages/database/supabase/migrations/20240811231527_convert-rfq.sql+++ b/packages/database/supabase/migrations/20240811231527_convert-rfq.sql@@ -26,18 +26,19 @@ CREATE POLICY "Employees with sales_create can insert salesRfqToQuote" ON "salesCREATE TABLE "customerPartToItem" ("customerId" TEXT NOT NULL,"customerPartId" TEXT NOT NULL,- "customerPartRevision" TEXT,+ "customerPartRevision" TEXT DEFAULT '',"itemId" TEXT NOT NULL,"companyId" TEXT NOT NULL,- PRIMARY KEY ("customerId", "customerPartId", "customerPartRevision"),- FOREIGN KEY ("customerId") REFERENCES "customer" ("id") ON DELETE CASCADE,- FOREIGN KEY ("itemId") REFERENCES "item" ("id") ON DELETE CASCADE,- FOREIGN KEY ("companyId") REFERENCES "company" ("id") ON DELETE CASCADE+ CONSTRAINT "customerPartToItem_pkey" PRIMARY KEY ("customerId", "itemId"),+ CONSTRAINT "customerPartToItem_customerId_itemId_key" UNIQUE ("customerId", "itemId"),+ CONSTRAINT "customerPartToItem_customerId_fkey" FOREIGN KEY ("customerId") REFERENCES "customer" ("id") ON DELETE CASCADE,+ CONSTRAINT "customerPartToItem_itemId_fkey" FOREIGN KEY ("itemId") REFERENCES "item" ("id") ON DELETE CASCADE,+ CONSTRAINT "customerPartToItem_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company" ("id") ON DELETE CASCADE);-CREATE INDEX "customerPartToItem_companyId_idx" ON "customerPartToItem" ("companyId");-CREATE INDEX "customerPartToItem_customerPartId_idx" ON "customerPartToItem" ("customerPartId", "customerPartRevision");+CREATE INDEX "customerPartToItem_companyId_idx" ON "customerPartToItem" ("itemId");+CREATE INDEX "customerPartToItem_customerPartId_idx" ON "customerPartToItem" ("customerPartId", "customerPartRevision", "companyId");ALTER TABLE "customerPartToItem" ENABLE ROW LEVEL SECURITY;