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: don't add pos for outside operations if they already exsist
Brad Barbin593ba34f8e0c
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx b/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsxindex a657867283..d1d099d2c8 100644--- a/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx+++ b/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx@@ -492,18 +492,41 @@ export function JobStartModal({carbon.from("jobOperation").select("*").eq("jobId", job.id!),]);- const uniqueOutsideProcessIds =- operations.data?.reduce<string[]>((acc, op) => {- if (op.operationType === "Outside" && op.operationSupplierProcessId) {- acc.push(op.operationSupplierProcessId);- }- return acc;- }, []) || [];+ // Check for existing purchase order lines for outside operations+ const outsideOperations =+ operations.data?.filter((op) => op.operationType === "Outside") || [];+ const existingPurchaseOrderLines =+ outsideOperations.length > 0+ ? await carbon+ .from("purchaseOrderLine")+ .select("jobOperationId")+ .in(+ "jobOperationId",+ outsideOperations.map((op) => op.id)+ )+ : { data: [] };++ const existingJobOperationIds = new Set(+ existingPurchaseOrderLines.data?.map((pol) => pol.jobOperationId) ?? []+ );- const supplierProcesses = await carbon- .from("supplierProcess")- .select("supplierId")- .in("id", uniqueOutsideProcessIds);+ // Filter out operations that already have purchase order lines+ const operationsNeedingPurchaseOrders = outsideOperations.filter(+ (op) =>+ !existingJobOperationIds.has(op.id) && op.operationSupplierProcessId+ );++ const uniqueOutsideProcessIds = operationsNeedingPurchaseOrders.map(+ (op) => op.operationSupplierProcessId!+ );++ const supplierProcesses =+ uniqueOutsideProcessIds.length > 0+ ? await carbon+ .from("supplierProcess")+ .select("supplierId")+ .in("id", uniqueOutsideProcessIds)+ : { data: [] };const uniqueSupplierIds = new Set(supplierProcesses.data?.map((sp) => sp.supplierId) ?? []@@ -571,18 +594,15 @@ export function JobStartModal({));- setHasOutsideOperations(- Array.isArray(operations?.data) &&- operations.data.length > 0 &&- operations.data.some((op) => op.operationType === "Outside")- );+ // Only show purchase order UI if there are outside operations that need purchase orders+ setHasOutsideOperations(operationsNeedingPurchaseOrders.length > 0);+ // Check if all outside operations that need purchase orders have supplierssetEachOutsideOperationHasASupplier(- operations.data?.every(- (op) =>- op.operationType === "Inside" ||- op.operationSupplierProcessId !== null- ) ?? false+ operationsNeedingPurchaseOrders.length === 0 ||+ operationsNeedingPurchaseOrders.every(+ (op) => op.operationSupplierProcessId !== null+ ));});@@ -696,7 +716,7 @@ export function JobStartModal({</AlertDescription></Alert>)}- {!eachOutsideOperationHasASupplier && (+ {!eachOutsideOperationHasASupplier && hasOutsideOperations && (<Alert variant="warning"><LuTriangleAlert /><AlertTitle>Missing Suppliers</AlertTitle>diff --git a/apps/erp/app/routes/file+/shipment+/$id[.]pdf.tsx b/apps/erp/app/routes/file+/shipment+/$id[.]pdf.tsxindex fd2e5d6d02..6f36b529a5 100644--- a/apps/erp/app/routes/file+/shipment+/$id[.]pdf.tsx+++ b/apps/erp/app/routes/file+/shipment+/$id[.]pdf.tsx@@ -89,7 +89,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {.select("*").eq("id", salesOrder.data?.customerId ?? "").single(),- getCustomerLocation(client, salesOrder.data?.locationId ?? ""),+ getCustomerLocation(client, salesOrder.data?.customerLocationId ?? ""),getPaymentTerm(client, salesOrder.data?.paymentTermId ?? ""),getShippingMethod(client,@@ -153,7 +153,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {shipment={shipment.data}shipmentLines={shipmentLines.data ?? []}// @ts-ignore- shippingAddress={customerLocation.data?.address}+ shippingAddress={customerLocation.data?.address ?? null}terms={(terms?.data?.salesTerms ?? {}) as JSONContent}paymentTerm={paymentTerm.data ?? { id: "", name: "" }}shippingMethod={shippingMethod.data ?? { id: "", name: "" }}@@ -265,7 +265,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {shipment={shipment.data}shipmentLines={shipmentLines.data ?? []}// @ts-ignore- shippingAddress={customerLocation.data?.address}+ shippingAddress={customerLocation.data?.address ?? null}terms={(terms?.data?.salesTerms ?? {}) as JSONContent}paymentTerm={paymentTerm.data ?? { id: "", name: "" }}shippingMethod={shippingMethod.data ?? { id: "", name: "" }}@@ -307,7 +307,10 @@ export async function loader({ request, params }: LoaderFunctionArgs) {.select("*").eq("id", purchaseOrder.data?.supplierId ?? "").single(),- getSupplierLocation(client, purchaseOrder.data?.locationId ?? ""),+ getSupplierLocation(+ client,+ purchaseOrder.data?.supplierLocationId ?? ""+ ),getPaymentTerm(client, purchaseOrder.data?.paymentTermId ?? ""),getShippingMethod(client,@@ -369,7 +372,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {shipment={shipment.data}shipmentLines={shipmentLines.data ?? []}// @ts-ignore- shippingAddress={supplierLocation.data?.address}+ shippingAddress={supplierLocation.data?.address ?? null}terms={(terms?.data?.salesTerms ?? {}) as JSONContent}paymentTerm={poPaymentTerm.data ?? { id: "", name: "" }}shippingMethod={poShippingMethod.data ?? { id: "", name: "" }}diff --git a/packages/documents/src/pdf/PackingSlipPDF.tsx b/packages/documents/src/pdf/PackingSlipPDF.tsxindex a2f3d39db4..ce647392a7 100644--- a/packages/documents/src/pdf/PackingSlipPDF.tsx+++ b/packages/documents/src/pdf/PackingSlipPDF.tsx@@ -125,21 +125,23 @@ const PackingSlipPDF = ({><View style={tw("flex flex-col gap-2 w-1/3")}><Text style={tw("text-gray-500 text-xs")}>Ship To</Text>- <Text style={tw("text-sm")}>{customer.name}</Text>- {shippingAddress && (- <>- {addressLine1 && (- <Text style={tw("text-sm")}>{addressLine1}</Text>- )}- {addressLine2 && (- <Text style={tw("text-sm")}>{addressLine2}</Text>- )}- <Text style={tw("text-sm")}>- {formatCityStatePostalCode(city, stateProvince, postalCode)}- </Text>- <Text style={tw("text-sm")}>{countryCode}</Text>- </>- )}+ <View style={tw("flex flex-col")}>+ <Text style={tw("text-sm")}>{customer.name}</Text>+ {shippingAddress && (+ <>+ {addressLine1 && (+ <Text style={tw("text-sm")}>{addressLine1}</Text>+ )}+ {addressLine2 && (+ <Text style={tw("text-sm")}>{addressLine2}</Text>+ )}+ <Text style={tw("text-sm")}>+ {formatCityStatePostalCode(city, stateProvince, postalCode)}+ </Text>+ <Text style={tw("text-sm")}>{countryCode}</Text>+ </>+ )}+ </View></View><View style={tw("flex flex-col gap-2 w-1/3")}>