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: don't allow updating purchase invoice without posting

Sidwebworks7125406bf9c1
diff --git a/apps/erp/app/routes/x+/purchase-invoice+/$invoiceId.status.tsx b/apps/erp/app/routes/x+/purchase-invoice+/$invoiceId.status.tsx
index 60a6f3daa8..c7ef3654d0 100644
--- a/apps/erp/app/routes/x+/purchase-invoice+/$invoiceId.status.tsx
+++ b/apps/erp/app/routes/x+/purchase-invoice+/$invoiceId.status.tsx
@@ -3,7 +3,10 @@ import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import type { ActionFunctionArgs } from "react-router";
import { redirect } from "react-router";
-import { updatePurchaseInvoiceStatus } from "~/modules/invoicing";
+import {
+ getPurchaseInvoice,
+ updatePurchaseInvoiceStatus
+} from "~/modules/invoicing";
import { purchaseInvoiceStatusType } from "~/modules/invoicing/invoicing.models";
import { path, requestReferrer } from "~/utils/path";
@@ -28,6 +31,31 @@ export async function action({ request, params }: ActionFunctionArgs) {
);
}
+ const invoice = await getPurchaseInvoice(client, id);
+
+ if (invoice.error || !invoice.data) {
+ throw redirect(
+ requestReferrer(request) ?? path.to.purchaseInvoiceDetails(id),
+ await flash(
+ request,
+ error(invoice.error, "Failed to get purchase invoice")
+ )
+ );
+ }
+
+ if (!invoice.data.postingDate) {
+ throw redirect(
+ requestReferrer(request) ?? path.to.purchaseInvoiceDetails(id),
+ await flash(
+ request,
+ error(
+ null,
+ "Cannot update status of draft purchase invoice. Please post the invoice first."
+ )
+ )
+ );
+ }
+
const [update] = await Promise.all([
updatePurchaseInvoiceStatus(client, {
id,