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(inventory): prevent posting voided receipts

sidgaikwad019f07fb9bb0
diff --git a/apps/erp/app/modules/inventory/ui/Receipts/ReceiptForm/ReceiptForm.tsx b/apps/erp/app/modules/inventory/ui/Receipts/ReceiptForm/ReceiptForm.tsx
index 4210409bb0..3aa273a00b 100644
--- a/apps/erp/app/modules/inventory/ui/Receipts/ReceiptForm/ReceiptForm.tsx
+++ b/apps/erp/app/modules/inventory/ui/Receipts/ReceiptForm/ReceiptForm.tsx
@@ -207,10 +207,15 @@ const ReceiptForm = ({
</Link>
</Button>
<Button
- variant={canPost && !isPosted ? "primary" : "secondary"}
+ variant={
+ canPost && !isPosted && !isVoided ? "primary" : "secondary"
+ }
onClick={postModal.onOpen}
isDisabled={
- !canPost || isPosted || !permissions.is("employee")
+ !canPost ||
+ isPosted ||
+ isVoided ||
+ !permissions.is("employee")
}
leftIcon={<LuCheckCheck />}
>
diff --git a/apps/erp/app/routes/x+/receipt+/$receiptId.post.tsx b/apps/erp/app/routes/x+/receipt+/$receiptId.post.tsx
index a2ba657d11..b766972559 100644
--- a/apps/erp/app/routes/x+/receipt+/$receiptId.post.tsx
+++ b/apps/erp/app/routes/x+/receipt+/$receiptId.post.tsx
@@ -47,9 +47,21 @@ export async function action({ request, params }: ActionFunctionArgs) {
// fire here too.
const { data: receiptForSurface } = await serviceRole
.from("receipt")
- .select("sourceDocument")
+ .select("sourceDocument, status")
.eq("id", receiptId)
.single();
+
+ // A voided receipt has already been reversed — re-posting would duplicate
+ // ledger entries, cost layers and journal lines. Block it before mutating
+ // any state (the route flips status to "Pending" below, which is why this
+ // guard lives here and not in the edge function).
+ if (receiptForSurface?.status === "Voided") {
+ throw redirect(
+ path.to.receipt(receiptId),
+ await flash(request, error(null, "Cannot post a voided receipt"))
+ );
+ }
+
const surfaces: ("receipt" | "warehouseTransfer")[] = ["receipt"];
if (receiptForSurface?.sourceDocument === "Inbound Transfer") {
surfaces.push("warehouseTransfer");
diff --git a/packages/database/supabase/functions/post-receipt/index.ts b/packages/database/supabase/functions/post-receipt/index.ts
index 7515bbdb2b..97f3ad0927 100644
--- a/packages/database/supabase/functions/post-receipt/index.ts
+++ b/packages/database/supabase/functions/post-receipt/index.ts
@@ -535,6 +535,10 @@ serve(async (req: Request) => {
});
}
+ if (receipt.data?.status === "Voided") {
+ throw new Error("Cannot post a voided receipt");
+ }
+
switch (receipt.data?.sourceDocument) {
case "Purchase Order": {
if (!receipt.data.sourceDocumentId)