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
// SPDX-License-Identifier: AGPL-3.0-only
// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
// including ports, remain AGPLv3; serving them over a network requires releasing their source.
import { assertIsPost, error } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { redirect } from "@carbon/utils";
import type { ActionFunctionArgs } from "react-router";
import { isRfqLocked } from "~/modules/purchasing/purchasing.models";
import {
deletePurchasingRFQLine,
getPurchasingRFQ
} from "~/modules/purchasing/purchasing.service";
import { requireUnlocked } from "~/utils/lockedGuard.server";
import { path } from "~/utils/path";
export async function action({ request, params }: ActionFunctionArgs) {
assertIsPost(request);
const { client: viewClient } = await requirePermissions(request, {
view: "purchasing"
});
const { client } = await requirePermissions(request, {
delete: "purchasing"
});
const { rfqId, lineId } = params;
if (!rfqId) {
throw new Error("rfqId not found");
}
if (!lineId) {
throw new Error("lineId not found");
}
const rfq = await getPurchasingRFQ(viewClient, rfqId);
await requireUnlocked({
request,
isLocked: isRfqLocked(rfq.data?.status),
redirectTo: path.to.purchasingRfq(rfqId),
message: "Cannot modify a locked RFQ. Reopen it first."
});
const deleteLine = await deletePurchasingRFQLine(client, lineId);
if (deleteLine.error) {
throw redirect(
path.to.purchasingRfqLine(rfqId, lineId),
await flash(request, error(deleteLine.error, "Failed to delete RFQ line"))
);
}
throw redirect(path.to.purchasingRfq(rfqId));
}