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: warn on no supplier for outside operations

Brad Barbina0f7cffe49a4
diff --git a/apps/erp/app/modules/production/production.models.ts b/apps/erp/app/modules/production/production.models.ts
index 4e403d243d..9091a2caed 100644
--- a/apps/erp/app/modules/production/production.models.ts
+++ b/apps/erp/app/modules/production/production.models.ts
@@ -325,6 +325,7 @@ export const jobOperationValidator = baseJobOperationValidator
export const jobOperationValidatorForReleasedJob = baseJobOperationValidator
.merge(
z.object({
+
workCenterId: z.string().min(1, { message: "Work center is required" }),
})
)
@@ -364,6 +365,18 @@ export const jobOperationValidatorForReleasedJob = baseJobOperationValidator
path: ["operationLeadTime"],
}
)
+ .refine(
+ (data) => {
+ if (data.operationType === "Outside") {
+ return !!data.operationSupplierProcessId;
+ }
+ return true;
+ },
+ {
+ message: "Supplier is required",
+ path: ["operationSupplierProcessId"],
+ }
+ )
.refine(
(data) => {
if (data.operationType === "Inside") {
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx b/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx
index ff4efc455f..7d44bc1d48 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx
@@ -370,6 +370,8 @@ function JobStartModal({
const [loading, setLoading] = useState(true);
const [eachAssemblyHasAnOperation, setEachAssemblyHasAnOperation] =
useState(false);
+ const [eachOutsideOperationHasASupplier, setEachOutsideOperationHasASupplier] =
+ useState(false);
const validate = async () => {
if (!carbon || !job) return;
@@ -406,6 +408,10 @@ function JobStartModal({
) ?? false
)
);
+
+ setEachOutsideOperationHasASupplier(
+ operations.data?.every((op) => op.operationType === "Inside" || op.operationSupplierProcessId !== null) ?? false
+ );
});
setLoading(false);
@@ -440,12 +446,13 @@ function JobStartModal({
) : (
<>
<ModalBody>
- {eachAssemblyHasAnOperation ? (
+ {eachAssemblyHasAnOperation && eachOutsideOperationHasASupplier && (
<p>
Are you sure you want to start this job? It will become
- available to the shop floor.
+ available to the shop floor and purchase orders will be created for any outside operations.
</p>
- ) : (
+ )}
+ {!eachAssemblyHasAnOperation && (
<Alert variant="warning">
<LuTriangleAlert />
<AlertTitle>Missing Operations</AlertTitle>
@@ -456,7 +463,19 @@ function JobStartModal({
</AlertDescription>
</Alert>
)}
+ {!eachOutsideOperationHasASupplier && (
+ <Alert variant="warning">
+ <LuTriangleAlert />
+ <AlertTitle>Missing Suppliers</AlertTitle>
+ <AlertDescription>
+ There are outside operations associated with this job that
+ have no suppliers. Please assign a supplier to each outside
+ operation before releasing it.
+ </AlertDescription>
+ </Alert>
+ )}
</ModalBody>
+
<ModalFooter>
<Button variant="secondary" onClick={onClose}>
Cancel
@@ -473,7 +492,7 @@ function JobStartModal({
fetcher.formData?.get("status") === "Ready"
}
isDisabled={
- fetcher.state !== "idle" || !eachAssemblyHasAnOperation
+ fetcher.state !== "idle" || !eachAssemblyHasAnOperation || !eachOutsideOperationHasASupplier
}
type="submit"
>
diff --git a/apps/erp/app/routes/x+/job+/$jobId.status.tsx b/apps/erp/app/routes/x+/job+/$jobId.status.tsx
index cedc30b27d..47efc9ea42 100644
--- a/apps/erp/app/routes/x+/job+/$jobId.status.tsx
+++ b/apps/erp/app/routes/x+/job+/$jobId.status.tsx
@@ -50,7 +50,9 @@ export async function action({ request, params }: ActionFunctionArgs) {
if (status === "Ready" && shouldSchedule) {
try {
- const scheduler = await getCarbonServiceRole().functions.invoke(
+ const serviceRole = getCarbonServiceRole();
+ const [scheduler, inventoryDocument] = await Promise.all([
+ serviceRole.functions.invoke(
"scheduler",
{
body: {
@@ -59,7 +61,16 @@ export async function action({ request, params }: ActionFunctionArgs) {
userId,
},
}
- );
+ ), serviceRole.functions.invoke(
+ "create-inventory-document",
+ {
+ body: {
+ jobId: id,
+ companyId,
+ userId,
+ },
+ })
+ ]);
if (scheduler.error) {
throw redirect(