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
fix: update item forms to use new data model
Brad Barbinc0d1f3b0cd86
diff --git a/apps/carbon/app/modules/items/items.service.ts b/apps/carbon/app/modules/items/items.service.tsindex e9e8e78d53..f0edbb20ef 100644--- a/apps/carbon/app/modules/items/items.service.ts+++ b/apps/carbon/app/modules/items/items.service.ts@@ -956,7 +956,7 @@ export async function upsertFixture(};const fixtureUpdate = {- customerId: fixture.customerId,+ customerId: fixture.customerId ? fixture.customerId : undefined,customFields: fixture.customFields,};diff --git a/apps/carbon/app/modules/items/ui/Consumables/ConsumableForm.tsx b/apps/carbon/app/modules/items/ui/Consumables/ConsumableForm.tsxindex d9cdf6c1ec..472fbcf6e2 100644--- a/apps/carbon/app/modules/items/ui/Consumables/ConsumableForm.tsx+++ b/apps/carbon/app/modules/items/ui/Consumables/ConsumableForm.tsx@@ -13,15 +13,15 @@ import {import { ValidatedForm } from "@carbon/remix-validated-form";import { useFetcher } from "@remix-run/react";import type { PostgrestResponse } from "@supabase/supabase-js";-import { useEffect } from "react";+import { useEffect, useState } from "react";import type { z } from "zod";import {Boolean,CustomFormFields,+ DefaultMethodType,Hidden,Input,InputControlled,- ItemPostingGroup,Select,Submit,TextArea,@@ -63,6 +63,10 @@ const ConsumableForm = ({const permissions = usePermissions();const isEditing = !!initialValues.id;+ const [defaultMethodType, setDefaultMethodType] = useState<string>(+ initialValues.defaultMethodType ?? "Buy"+ );+const itemTrackingTypeOptions =itemTrackingTypes.map((itemTrackingType) => ({label: itemTrackingType,@@ -93,6 +97,7 @@ const ConsumableForm = ({</ModalCardHeader><ModalCardBody><Hidden name="type" value={type} />+ <Hidden name="replenishmentSystem" value="Buy" /><divclassName={cn("grid w-full gap-x-8 gap-y-4",@@ -127,16 +132,20 @@ const ConsumableForm = ({<TextArea name="description" label="Description" />)}+ <DefaultMethodType+ name="defaultMethodType"+ label="Default Method Type"+ replenishmentSystem="Buy"+ value={defaultMethodType}+ onChange={(newValue) =>+ setDefaultMethodType(newValue?.value ?? "Buy")+ }+ /><UnitOfMeasurename="unitOfMeasureCode"label="Unit of Measure"/>- <ItemPostingGroup- name="itemPostingGroupId"- label="Posting Group"- />- <Boolean name="pullFromInventory" label="Pull from Inventory" /><Boolean name="active" label="Active" /><CustomFormFields table="consumable" />diff --git a/apps/carbon/app/modules/items/ui/Fixtures/FixtureForm.tsx b/apps/carbon/app/modules/items/ui/Fixtures/FixtureForm.tsxindex 1f7104026f..e84d133c8f 100644--- a/apps/carbon/app/modules/items/ui/Fixtures/FixtureForm.tsx+++ b/apps/carbon/app/modules/items/ui/Fixtures/FixtureForm.tsx@@ -13,22 +13,26 @@ import {import { ValidatedForm } from "@carbon/remix-validated-form";import { useFetcher } from "@remix-run/react";import type { PostgrestResponse } from "@supabase/supabase-js";-import { useEffect } from "react";+import { useEffect, useState } from "react";import type { z } from "zod";import {Boolean,CustomFormFields,Customer,+ DefaultMethodType,Hidden,Input,InputControlled,- ItemPostingGroup,Select,Submit,TextArea,} from "~/components/Form";import { useNextItemId, usePermissions } from "~/hooks";-import { fixtureValidator, itemTrackingTypes } from "~/modules/items";+import {+ fixtureValidator,+ itemReplenishmentSystems,+ itemTrackingTypes,+} from "~/modules/items";import { path } from "~/utils/path";type FixtureFormProps = {@@ -69,6 +73,18 @@ const FixtureForm = ({value: itemTrackingType,})) ?? [];+ const [replenishmentSystem, setReplenishmentSystem] = useState<string>(+ initialValues.replenishmentSystem ?? "Buy"+ );+ const [defaultMethodType, setDefaultMethodType] = useState<string>(+ initialValues.defaultMethodType ?? "Buy"+ );+ const itemReplenishmentSystemOptions =+ itemReplenishmentSystems.map((itemReplenishmentSystem) => ({+ label: itemReplenishmentSystem,+ value: itemReplenishmentSystem,+ })) ?? [];+return (<ModalCardProvider type={type}><ModalCard onClose={onClose}>@@ -94,7 +110,7 @@ const FixtureForm = ({<ModalCardBody><Hidden name="type" value={type} /><Hidden name="unitOfMeasureCode" value="EA" />- <Hidden name="pullFromInventory" value="on" />+<divclassName={cn("grid w-full gap-x-8 gap-y-4",@@ -120,20 +136,38 @@ const FixtureForm = ({)}<Input name="name" label="Name" />- <Customer name="customerId" label="Customer" />- {isEditing && (- <TextArea name="description" label="Description" />- )}-<Selectname="itemTrackingType"label="Tracking Type"options={itemTrackingTypeOptions}/>- <ItemPostingGroup- name="itemPostingGroupId"- label="Posting Group"+ {isEditing && (+ <TextArea name="description" label="Description" />+ )}+ <Select+ name="replenishmentSystem"+ label="Replenishment System"+ options={itemReplenishmentSystemOptions}+ onChange={(newValue) => {+ setReplenishmentSystem(newValue?.value ?? "Buy");+ if (newValue?.value === "Buy") {+ setDefaultMethodType("Buy");+ } else {+ setDefaultMethodType("Make");+ }+ }}+ />+ <DefaultMethodType+ name="defaultMethodType"+ label="Default Method Type"+ replenishmentSystem={replenishmentSystem}+ value={defaultMethodType}+ onChange={(newValue) =>+ setDefaultMethodType(newValue?.value ?? "Buy")+ }/>++ <Customer name="customerId" label="Customer" /><Boolean name="active" label="Active" /><CustomFormFields table="fixture" />diff --git a/apps/carbon/app/modules/items/ui/Fixtures/useFixtureNavigation.tsx b/apps/carbon/app/modules/items/ui/Fixtures/useFixtureNavigation.tsxindex 2e211c2e4e..ebd960f1f2 100644--- a/apps/carbon/app/modules/items/ui/Fixtures/useFixtureNavigation.tsx+++ b/apps/carbon/app/modules/items/ui/Fixtures/useFixtureNavigation.tsx@@ -1,15 +1,25 @@import { useParams } from "@remix-run/react";+import { BiListCheck } from "react-icons/bi";import { LuBox, LuFileText, LuShoppingCart, LuTags } from "react-icons/lu";-import { usePermissions } from "~/hooks";+import { usePermissions, useRouteData } from "~/hooks";import type { Role } from "~/types";import { path } from "~/utils/path";+import type { Fixture } from "../../types";export function useFixtureNavigation() {const permissions = usePermissions();const { itemId } = useParams();if (!itemId) throw new Error("itemId not found");+ const routeData = useRouteData<{+ fixtureSummary: Fixture;+ }>(path.to.fixture(itemId));+ if (!routeData?.fixtureSummary?.replenishmentSystem)+ throw new Error("Could not find replenishmentSystem in routeData");++ const replenishment = routeData.fixtureSummary.replenishmentSystem;+return [{name: "Details",@@ -20,10 +30,19 @@ export function useFixtureNavigation() {{name: "Purchasing",to: path.to.fixturePurchasing(itemId),+ isDisabled: replenishment === "Make",role: ["employee", "supplier"],icon: LuShoppingCart,shortcut: "Command+Shift+p",},+ {+ name: "Manufacturing",+ to: path.to.fixtureManufacturing(itemId),+ isDisabled: replenishment === "Buy",+ role: ["employee"],+ icon: BiListCheck,+ shortcut: "Command+Shift+m",+ },{name: "Accounting",to: path.to.fixtureCosting(itemId),@@ -40,7 +59,8 @@ export function useFixtureNavigation() {},].filter((item) =>- item.role === undefined ||- item.role.some((role) => permissions.is(role as Role))+ !item.isDisabled &&+ (item.role === undefined ||+ item.role.some((role) => permissions.is(role as Role))));}diff --git a/apps/carbon/app/modules/items/ui/Services/ServiceForm.tsx b/apps/carbon/app/modules/items/ui/Services/ServiceForm.tsxindex 529c767e83..997204816e 100644--- a/apps/carbon/app/modules/items/ui/Services/ServiceForm.tsx+++ b/apps/carbon/app/modules/items/ui/Services/ServiceForm.tsx@@ -15,7 +15,6 @@ import {Hidden,Input,InputControlled,- ItemPostingGroup,Select,Submit,TextArea,@@ -59,7 +58,8 @@ const ServiceForm = ({ initialValues }: ServiceFormProps) => {<CardContent><Hidden name="itemTrackingType" value="Non-Inventory" /><Hidden name="unitOfMeasureCode" value="EA" />- <Hidden name="pullFromInventory" value="on" />+ <Hidden name="replenishmentSystem" value="Buy" />+ <Hidden name="defaultMethodType" value="Buy" /><divclassName={cn("grid w-full gap-x-8 gap-y-4",@@ -87,7 +87,6 @@ const ServiceForm = ({ initialValues }: ServiceFormProps) => {label="Service Type"options={serviceTypeOptions}/>- <ItemPostingGroup name="itemPostingGroupId" label="Posting Group" /><Boolean name="active" label="Active" /><CustomFormFields table="service" />diff --git a/apps/carbon/app/modules/items/ui/Tools/ToolForm.tsx b/apps/carbon/app/modules/items/ui/Tools/ToolForm.tsxindex 671c315d2a..01d18cadd9 100644--- a/apps/carbon/app/modules/items/ui/Tools/ToolForm.tsx+++ b/apps/carbon/app/modules/items/ui/Tools/ToolForm.tsx@@ -13,15 +13,15 @@ import {import { ValidatedForm } from "@carbon/remix-validated-form";import { useFetcher } from "@remix-run/react";import type { PostgrestResponse } from "@supabase/supabase-js";-import { useEffect } from "react";+import { useEffect, useState } from "react";import type { z } from "zod";import {Boolean,CustomFormFields,+ DefaultMethodType,Hidden,Input,InputControlled,- ItemPostingGroup,Select,Submit,TextArea,@@ -65,6 +65,10 @@ const ToolForm = ({ initialValues, type = "card", onClose }: ToolFormProps) => {value: itemTrackingType,})) ?? [];+ const [defaultMethodType, setDefaultMethodType] = useState<string>(+ initialValues.defaultMethodType ?? "Buy"+ );+return (<ModalCardProvider type={type}><ModalCard onClose={onClose}>@@ -89,6 +93,7 @@ const ToolForm = ({ initialValues, type = "card", onClose }: ToolFormProps) => {</ModalCardHeader><ModalCardBody><Hidden name="type" value={type} />+ <Hidden name="replenishmentSystem" value="Buy" /><divclassName={cn("grid w-full gap-x-8 gap-y-4",@@ -123,16 +128,21 @@ const ToolForm = ({ initialValues, type = "card", onClose }: ToolFormProps) => {<TextArea name="description" label="Description" />)}+ <DefaultMethodType+ name="defaultMethodType"+ label="Default Method Type"+ replenishmentSystem="Buy"+ value={defaultMethodType}+ onChange={(newValue) =>+ setDefaultMethodType(newValue?.value ?? "Buy")+ }+ />+<UnitOfMeasurename="unitOfMeasureCode"label="Unit of Measure"/>- <ItemPostingGroup- name="itemPostingGroupId"- label="Posting Group"- />- <Boolean name="pullFromInventory" label="Pull from Inventory" /><Boolean name="active" label="Active" /><CustomFormFields table="tool" />diff --git a/apps/carbon/app/routes/x+/fixture+/$itemId.manufacturing.tsx b/apps/carbon/app/routes/x+/fixture+/$itemId.manufacturing.tsxnew file mode 100644index 0000000000..af92fabb44--- /dev/null+++ b/apps/carbon/app/routes/x+/fixture+/$itemId.manufacturing.tsx@@ -0,0 +1,3 @@+export default function FixtureManufacturingRoute() {+ return <pre>TODO</pre>;+}diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.tsindex 8e05210185..fa670cd934 100644--- a/apps/carbon/app/utils/path.ts+++ b/apps/carbon/app/utils/path.ts@@ -295,6 +295,8 @@ export const path = {generatePath(`${x}/fixture/${id}/inventory`),fixtureInventoryLocation: (id: string, locationId: string) =>generatePath(`${x}/fixture/${id}/inventory?location=${locationId}`),+ fixtureManufacturing: (id: string) =>+ generatePath(`${x}/fixture/${id}/manufacturing`),fixturePlanning: (id: string) =>generatePath(`${x}/fixture/${id}/planning`),fixturePlanningLocation: (id: string, locationId: string) =>diff --git a/packages/database/supabase/migrations/20240619095417_methods.sql b/packages/database/supabase/migrations/20240619095417_methods.sqlindex 64db607b8b..3971d65951 100644--- a/packages/database/supabase/migrations/20240619095417_methods.sql+++ b/packages/database/supabase/migrations/20240619095417_methods.sql@@ -16,40 +16,6 @@ CREATE TABLE "makeMethod" (CONSTRAINT "method_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user" ("id") ON UPDATE CASCADE ON DELETE RESTRICT);-CREATE FUNCTION public.create_make_method_related_records()-RETURNS TRIGGER AS $$-BEGIN- -- if part.replenishmentSystem is 'Make' or 'Buy and Make' then create a make method record- IF new."replenishmentSystem" = 'Make' OR new."replenishmentSystem" = 'Buy and Make' THEN- INSERT INTO public."makeMethod"("itemId", "createdBy", "companyId")- VALUES (new."itemId", new."createdBy", new."companyId");- END IF;-- RETURN new;-END;-$$ LANGUAGE plpgsql SECURITY DEFINER;--CREATE FUNCTION public.update_make_method_related_records()-RETURNS TRIGGER AS $$-BEGIN- -- if part.replenishmentSystem is 'Make' or 'Buy and Make' then create a make method record- IF old."replenishmentSystem" = 'Buy' AND (new."replenishmentSystem" = 'Make' OR new."replenishmentSystem" = 'Buy and Make') THEN- INSERT INTO public."makeMethod"("itemId", "createdBy", "companyId")- VALUES (new."itemId", new."createdBy", new."companyId");- END IF;-- RETURN new;-END;-$$ LANGUAGE plpgsql SECURITY DEFINER;--CREATE TRIGGER create_part_make_method_related_records- AFTER INSERT on public.part- FOR EACH ROW EXECUTE PROCEDURE public.create_make_method_related_records();--CREATE TRIGGER update_part_make_method_related_records- AFTER UPDATE on public.part- FOR EACH ROW EXECUTE PROCEDURE public.update_make_method_related_records();-CREATE TYPE "methodOperationOrder" AS ENUM (diff --git a/packages/database/supabase/migrations/20240621114604_method-rls.sql b/packages/database/supabase/migrations/20240621114604_method-rls.sqlindex 557ace2c40..a8ab66cc7b 100644--- a/packages/database/supabase/migrations/20240621114604_method-rls.sql+++ b/packages/database/supabase/migrations/20240621114604_method-rls.sql@@ -13,12 +13,6 @@ VALUESALTER TABLE "makeMethod" ADD CONSTRAINT "makeMethod_unique_itemId" UNIQUE ("itemId", "companyId");-DROP TRIGGER IF EXISTS create_part_make_method_related_records ON public.part;-DROP TRIGGER IF EXISTS update_part_make_method_related_records ON public.part;--DROP FUNCTION IF EXISTS public.create_make_method_related_records();-DROP FUNCTION IF EXISTS public.update_make_method_related_records();-CREATE FUNCTION public.create_make_method_related_records()RETURNS TRIGGER AS $$BEGIN@@ -34,6 +28,10 @@ CREATE TRIGGER create_part_make_method_related_recordsAFTER INSERT on public.partFOR EACH ROW EXECUTE PROCEDURE public.create_make_method_related_records();+CREATE TRIGGER create_fixture_make_method_related_records+ AFTER INSERT on public.fixture+ FOR EACH ROW EXECUTE PROCEDURE public.create_make_method_related_records();+ALTER TABLE "methodOperation" ALTER COLUMN "description" SET NOT NULL;