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(sales-orders): show a field error when a typed sales order number is already taken

aashu1570a8900f52
diff --git a/apps/erp/app/routes/x+/sales-order+/new.tsx b/apps/erp/app/routes/x+/sales-order+/new.tsx
index c2ad013548..e377784ecf 100644
--- a/apps/erp/app/routes/x+/sales-order+/new.tsx
+++ b/apps/erp/app/routes/x+/sales-order+/new.tsx
@@ -77,6 +77,19 @@ export async function action({ request }: ActionFunctionArgs) {
customFields: setCustomFields(formData)
});
+ // A typed number another sales order already has: keep the user on the form.
+ if (
+ result.error?.code === "23505" &&
+ result.error.details?.includes("salesOrderId") &&
+ data.salesOrderId
+ ) {
+ return validationError({
+ fieldErrors: {
+ salesOrderId: `Sales order ${data.salesOrderId} already exists`
+ }
+ });
+ }
+
if (result.error || !result.data) {
throw redirect(
path.to.salesOrders,