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.
description: How a manufacturing method's materials are defined and how sourcing (make vs buy / supplier) is determined, item-level vs per-row. paths: - "apps/erp/app/modules/items/items.service.ts" - "apps/erp/app/routes/x+/items+/update.tsx" - "apps/erp/app/modules/items/items.server.ts" - "apps/erp/app/modules/items/ui/Item/BillOfMaterial.tsx" - "packages/database/supabase/migrations/**"
Method Material Sourcing & Method Type (item-level)
A methodMaterial is a component line on a make method's bill of material. Its
sourcingType and methodType are read-only mirrors of the referenced
component item (methodMaterial.itemId) — they are NOT edited per-row in the
BOM editor. They are derived from two item-level properties:
item.defaultMethodType— enummethodType.item.sourcingType— enumsourcingType.
Enums (DB + UI in sync, no translation)
methodType:Purchase to Order,Pull from Inventory,Make to Order. Created (renamed from oldBuy/Pick/Make) in20260321143847_method-type-migration.sql.sourcingType:Specified,Drop Ship,Ship from Inventory. Enum + themethodMaterial.sourcingTypecolumn added in20260321230229_sourcing-types.sql. Theitem.sourcingTypecolumn (andget_part_details/get_tool_detailsRPC recreations that surface it) were added later in20260615143722_item-sourcing-type.sql.
Zod enums live in apps/erp/app/modules/shared/shared.models.ts (L149-159);
types L95-96).MethodType / SourcingType in apps/erp/app/modules/shared/types.ts
(
Schema (verified)
methodMaterialcols:methodType "methodType" NOT NULL DEFAULT 'Pull from Inventory',sourcingType "sourcingType" NOT NULL DEFAULT 'Specified',itemId(FK→item),makeMethodId(FK→makeMethod),materialMakeMethodId(nullable FK→makeMethod, the sub-method for Make-to-Order rows). Base table:20240619095417_methods.sql.itemcols:defaultMethodType "methodType" NOT NULL DEFAULT 'Pull from Inventory',sourcingType "sourcingType" NOT NULL DEFAULT 'Specified'.makeMethod.statusenummakeMethodStatus:Draft,Active,Archived(20250603011801_make-method-version.sql).
Where item-level fields are edited
- Part:
apps/erp/app/modules/items/ui/Parts/PartProperties.tsx— "Default Method Type"<Select>+<SourcingTypeProperty />. - Tool:
apps/erp/app/modules/items/ui/Tools/ToolProperties.tsx— same. - The Sourcing control (
SourcingTypeProperty.tsx) rendersnullunlessreplenishmentSystem === "Buy and Make". - Both submit via
onUpdate(field, value)→fetcher.submit(..., { action: path.to.bulkUpdateItems }).
Server-side update + sourcing → method-type mapping
Route apps/erp/app/routes/x+/items+/update.tsx calls setItemSourcing
(setItemSourcing in items.server.ts). The interlocked fields
replenishmentSystem, defaultMethodType, sourcingType (exactly one per call)
are derived by deriveItemMethodUpdate(field, value) then applied by
updateItemMethodAndSourcing (one transaction: item write + cascade).
Sourcing drives method type (sourcingType case, ~L73-89):
Drop Ship→Purchase to OrderShip from Inventory→Pull from InventorySpecified→ leavedefaultMethodTypeas-is
(itemTrackingType is a separate operation, setItemTrackingType, that
cascades via cascadeItemTrackingType.)
Cascade + derivation (items.service.ts)
updateItemMethodAndSourcing(db, args)(L2745) — writesL2790, not exported) inside one Kysely transaction.itemthen calls the internal helpercascadeSourcingAndMethodTypeToMethodMaterials(trx, args)(- The cascade mirrors the item's
sourcingType/methodTypeonto everymethodMaterialreferencing it, but only where the make method isDraft(makeMethod.status = 'Draft'); Active/Archived methods are frozen. ForMake to Orderrows it resolvesmaterialMakeMethodIdfrom theactiveMakeMethodsview per item (null if none). upsertMethodMaterial(~L3439) re-derivesmethodType/sourcingTypefrom the component item (item.defaultMethodType ?? methodType,item.sourcingType) — the submitted form values are advisory/display-only.getMethodMaterialsByMakeMethod(~L1321) selectsitem(name, itemTrackingType, replenishmentSystem, defaultMethodType, sourcingType).
BOM editor display (read-only)
apps/erp/app/modules/items/ui/Item/BillOfMaterial.tsx:
- Sourcing section (~L859) is gated on the component item's replenishment
(
itemData.itemReplenishmentSystem === "Buy and Make"), not the parent's, and renders thesourcingType<Select isReadOnly>. - Method Type section (~L922) shows a read-only
<DefaultMethodType isReadOnly>; label is "Finish To" whenmethodType === "Make to Order", else "Pull From". - Values are submitted via hidden inputs only to satisfy
methodMaterialValidator;upsertMethodMaterialre-derives them, so they are not the source of truth.
Gotchas
- Don't treat BOM-submitted
sourcingType/methodTypeas authoritative — the service overwrites them from the item. Change sourcing on the item, not the row. - Cascade only touches Draft make methods. Editing an item's sourcing won't retro-update materials on Active/Archived methods.
methodTypeenum values wereBuy/Pick/Makebefore migration20260321143847; older migrations referencing those are pre-rename.