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: manual material id flow

Brad Barbine3c7f73b4348
diff --git a/apps/erp/app/modules/items/ui/Materials/MaterialForm.tsx b/apps/erp/app/modules/items/ui/Materials/MaterialForm.tsx
index c46dd62314..e0d5b2410d 100644
--- a/apps/erp/app/modules/items/ui/Materials/MaterialForm.tsx
+++ b/apps/erp/app/modules/items/ui/Materials/MaterialForm.tsx
@@ -31,7 +31,7 @@ import MaterialGrade from "~/components/Form/MaterialGrade";
import MaterialType, { useMaterialTypes } from "~/components/Form/MaterialType";
import Shape, { useShape } from "~/components/Form/Shape";
import Substance, { useSubstance } from "~/components/Form/Substance";
-import { useNextItemId, usePermissions, useUser } from "~/hooks";
+import { useNextItemId, usePermissions } from "~/hooks";
import { useSettings } from "~/hooks/useSettings";
import { getMaterialDescription, getMaterialId } from "~/utils/items";
import { path } from "~/utils/path";
@@ -56,9 +56,6 @@ const MaterialForm = ({
type = "card",
onClose,
}: MaterialFormProps) => {
- const { company } = useUser();
- const baseCurrency = company?.baseCurrencyCode;
-
const [materialId, setMaterialId] = useState(initialValues.id ?? "");
const [description, setDescription] = useState(
initialValues.description ?? ""
@@ -167,7 +164,12 @@ const MaterialForm = ({
<InputControlled
name="id"
label="Material ID"
- value={materialId}
+ helperText={
+ startsWithLetter(id)
+ ? "Use ... to get the next material ID"
+ : undefined
+ }
+ value={id}
onChange={onIdChange}
isDisabled={loading}
isUppercase
diff --git a/apps/erp/app/modules/items/ui/Materials/MaterialProperties.tsx b/apps/erp/app/modules/items/ui/Materials/MaterialProperties.tsx
index f0af0aa995..966e4f586b 100644
--- a/apps/erp/app/modules/items/ui/Materials/MaterialProperties.tsx
+++ b/apps/erp/app/modules/items/ui/Materials/MaterialProperties.tsx
@@ -304,30 +304,37 @@ const MaterialProperties = () => {
</HStack>
</HStack>
<VStack spacing={1} className="pt-2">
- <ValidatedForm
- defaultValues={{
- materialId:
- routeData?.materialSummary?.readableIdWithRevision ?? undefined,
- }}
- validator={z.object({
- materialId: z.string(),
- })}
- className="w-full -mt-2"
- >
- <span className="text-sm">
- <InputControlled
- label=""
- name="materialId"
- inline
- size="sm"
- value={routeData?.materialSummary?.readableId ?? ""}
- onBlur={(e) => {
- onUpdate("materialId", e.target.value ?? null);
- }}
- className="text-muted-foreground"
- />
+ {settings.materialGeneratedIds ? (
+ <span className="text-sm tracking-tight">
+ {routeData?.materialSummary?.readableIdWithRevision}
</span>
- </ValidatedForm>
+ ) : (
+ <ValidatedForm
+ defaultValues={{
+ materialId:
+ routeData?.materialSummary?.readableIdWithRevision ??
+ undefined,
+ }}
+ validator={z.object({
+ materialId: z.string(),
+ })}
+ className="w-full -mt-2"
+ >
+ <span className="text-sm">
+ <InputControlled
+ label=""
+ name="materialId"
+ inline
+ size="sm"
+ value={routeData?.materialSummary?.readableId ?? ""}
+ onBlur={(e) => {
+ onUpdate("materialId", e.target.value ?? null);
+ }}
+ className="text-muted-foreground"
+ />
+ </span>
+ </ValidatedForm>
+ )}
<ValidatedForm
defaultValues={{
name: routeData?.materialSummary?.name ?? undefined,
diff --git a/apps/erp/app/routes/x+/items+/update.tsx b/apps/erp/app/routes/x+/items+/update.tsx
index 1057441a5f..3121fc4de1 100644
--- a/apps/erp/app/routes/x+/items+/update.tsx
+++ b/apps/erp/app/routes/x+/items+/update.tsx
@@ -300,6 +300,7 @@ export async function action({ request }: ActionFunctionArgs) {
.from("item")
.select("readableId, type")
.eq("id", item)
+ .eq("type", "Part")
.eq("companyId", companyId)
.single();
@@ -307,6 +308,7 @@ export async function action({ request }: ActionFunctionArgs) {
return json(itemData);
}
if (itemData.data?.type !== "Part") {
+ console.error("itemData.data?.type", itemData.data?.type);
return json({ error: { message: "Item is not a part" }, data: null });
}
@@ -366,6 +368,7 @@ export async function action({ request }: ActionFunctionArgs) {
.from("item")
.select("readableId, type")
.eq("id", consumableItem)
+ .eq("type", "Consumable")
.eq("companyId", companyId)
.single();
@@ -437,6 +440,7 @@ export async function action({ request }: ActionFunctionArgs) {
.from("item")
.select("readableId, type")
.eq("id", materialItem)
+ .eq("type", "Material")
.eq("companyId", companyId)
.single();
@@ -506,6 +510,7 @@ export async function action({ request }: ActionFunctionArgs) {
.from("item")
.select("readableId, type")
.eq("id", toolItem)
+ .eq("type", "Tool")
.eq("companyId", companyId)
.single();
diff --git a/packages/database/supabase/migrations/20250719100358_material-seed.sql b/packages/database/supabase/migrations/20250719100358_material-seed.sql
index 29bceb1902..b8b858c1e9 100644
--- a/packages/database/supabase/migrations/20250719100358_material-seed.sql
+++ b/packages/database/supabase/migrations/20250719100358_material-seed.sql
@@ -7,7 +7,7 @@ ALTER TABLE "materialForm" ADD COLUMN "code" TEXT;
COMMIT;
-- Set materialGeneratedIds to false for all existing companies
-UPDATE "companySettings" SET "materialGeneratedIds" = false;
+UPDATE "companySettings" SET "materialGeneratedIds" = true;
INSERT INTO "materialForm" ("id", "name", "code", "createdBy") VALUES