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): surface negative adjustment errors in modal (#983)

Carbon Agent32e4d6a2195a
diff --git a/apps/erp/app/routes/x+/inventory+/quantities+/$itemId.adjustment.tsx b/apps/erp/app/routes/x+/inventory+/quantities+/$itemId.adjustment.tsx
index f59cb7c361..909d90b1e8 100644
--- a/apps/erp/app/routes/x+/inventory+/quantities+/$itemId.adjustment.tsx
+++ b/apps/erp/app/routes/x+/inventory+/quantities+/$itemId.adjustment.tsx
@@ -1,7 +1,6 @@
-import { assertIsPost, error } from "@carbon/auth";
+import { assertIsPost } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { getCarbonServiceRole } from "@carbon/auth/client.server";
-import { flash } from "@carbon/auth/session.server";
import {
dedupeViolations,
evaluateLinesForSurface,
@@ -102,17 +101,22 @@ export async function action({ request, params }: ActionFunctionArgs) {
});
if (itemLedger.error) {
- const flashMessage =
+ // Return the error as fetcher data so the modal can toast the reason and
+ // stay open. A redirect+flash would be lost here: the modal submits via a
+ // fetcher, so a redirect-throw never surfaces the flash message.
+ const message =
itemLedger.error === "Insufficient quantity for negative adjustment"
? "Insufficient quantity for negative adjustment"
: itemLedger.error === "Serial number not found"
? "Serial number not found"
: "Failed to create manual inventory adjustment";
- throw redirect(
- path.to.inventoryItem(itemId),
- await flash(request, error(itemLedger.error, flashMessage))
- );
+ return {
+ error: { message },
+ data: null,
+ violations: [],
+ ruleNames: {}
+ };
}
throw redirect(requestReferrer(request) ?? path.to.inventoryItem(itemId));