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.

feat(items): import BOM & BOP (method import) via CSV

sidgaikwadfbb2c90066d4
diff --git a/PRD-import-bom-bop.md b/PRD-import-bom-bop.md
new file mode 100644
index 0000000000..d057aa7cd1
--- /dev/null
+++ b/PRD-import-bom-bop.md
@@ -0,0 +1,243 @@
+# PRD: Import BOM & BOP (Method Import)
+
+> Vocabulary follows [CONTEXT.md](./CONTEXT.md). Decisions are bound by
+> [ADR-0001](./docs/adr/0001-method-import-is-atomic-per-parent-part.md) and
+> [ADR-0002](./docs/adr/0002-method-import-file-format.md). Implementation checklist lives in
+> [llm/tasks/import-bom-bop.md](./llm/tasks/import-bom-bop.md).
+
+## Problem Statement
+
+Carbon has bulk CSV importers for parts, materials, customers, contacts, and similar
+entities. When a user uploads a part, there is no way to upload the part's associated
+**BOM** (its Bill of Materials — what it is built from) or **BOP** (its Bill of Process —
+the operations used to build it). A team onboarding onto Carbon, or migrating a catalog
+from a legacy ERP, can load thousands of parts but must then hand-build every part's
+recipe in the UI, one line at a time. For a real manufacturing catalog this is prohibitive,
+so the parts arrive in Carbon with no method and the system cannot plan, cost, or
+manufacture them until someone manually recreates work that already exists in a spreadsheet.
+
+## Solution
+
+Add the ability to bulk-import a part's Make Method — its BOM and BOP, including the
+nested detail of each operation (procedure steps, required tools, and process
+parameters) — via CSV, using the same import experience users already know.
+
+The user chooses how they want to work:
+
+- **Import BOM** — a focused file of BOM lines against parts that already exist.
+- **Import Operations** — a focused file of operations (and their steps/tools/parameters)
+ against parts that already exist.
+- **Import Parts with Methods** — one combined file that creates the parts *and* their
+ full BOM and BOP together, for a clean catalog migration in a single upload.
+
+These appear in the existing **Bulk Import** dropdown on the Parts and Tools lists. Every
+row names its parent part explicitly, so multi-level assemblies, multiple part revisions,
+and even specific recipe versions all import correctly. The importer is safe by
+construction: it validates the whole file first, treats each part's recipe as
+all-or-nothing, never overwrites a recipe that already has content, and reports results
+per part so the user knows exactly what imported, what was skipped, and why.
+
+## User Stories
+
+1. As a data-migration user, I want to upload a CSV of BOM lines for parts that already
+ exist, so that I do not have to hand-enter each component in the UI.
+2. As a data-migration user, I want to upload a CSV of operations for parts that already
+ exist, so that I can populate routings in bulk.
+3. As a data-migration user, I want to upload one combined file that creates parts and
+ their BOM and BOP together, so that I can migrate a whole catalog in a single step.
+4. As an engineer, I want every BOM/BOP row to name its parent part by readable ID and
+ revision, so that the importer never guesses which part a line belongs to.
+5. As an engineer, I want a sub-assembly's components to be expressed as that
+ sub-assembly's own BOM lines, so that multi-level BOMs import without a fragile level
+ column.
+6. As an engineer, I want to import the BOM/BOP for a specific part revision, so that
+ revision A and revision B each get their own independent recipe.
+7. As an engineer, I want to optionally target a specific Make Method Version, so that a
+ migrated part can carry more than just its current recipe.
+8. As an engineer, when I leave the version blank, I want the importer to fill the part's
+ current method, so that the common case needs no extra columns.
+9. As an engineer, I want an explicitly versioned import to create a Draft and never change
+ which version is Active, so that importing cannot disturb live production.
+10. As an engineer, I want the importer to fill a recipe only when it is empty, so that a
+ part that already has a BOM/BOP is never silently overwritten or duplicated.
+11. As an engineer, I want a part that already has a recipe to be skipped and reported, so
+ that re-running the same file is safe.
+12. As an engineer, I want each operation to carry an operation number unique within the
+ part, so that I can attach steps, tools, and parameters to the right operation.
+13. As an engineer, I want to import procedure steps for an operation, including the step
+ type, whether it is required, measurement bounds, and list options, so that work
+ instructions migrate with the routing.
+14. As an engineer, I want to import the tools required by an operation with quantities, so
+ that tooling requirements migrate with the routing.
+15. As an engineer, I want to import the parameters of an operation as key/value pairs, so
+ that process settings migrate with the routing.
+16. As a process planner, I want to import both in-house (Inside) and outsourced (Outside)
+ operations, so that a routing with outsourced steps like plating or heat-treat imports
+ completely.
+17. As a process planner, I want to optionally link an Outside operation to a supplier and
+ that supplier's process, so that outsourced costing is captured where known.
+18. As a cost engineer, I want method type and sourcing to come from the component item
+ rather than the BOM line, so that the same component behaves consistently everywhere it
+ is used.
+19. As an engineer, I want components, processes, work centers, tools, and units of measure
+ to already exist, so that an import never invents a junk record from a stray cell.
+20. As an engineer, I want a missing reference to fail only the affected part's recipe, so
+ that one bad line does not silently produce an incomplete recipe.
+21. As an engineer, I want validation to run across the whole file before anything is
+ written, so that I can see and fix every error up front.
+22. As an engineer, I want each part's recipe to import all-or-nothing, so that I never end
+ up with a partial recipe missing a component.
+23. As an engineer, I want one bad part to not block the rest of the file, so that a single
+ error does not waste a large import.
+24. As an engineer importing a combined file, if a new part's recipe fails, I want the part
+ itself to not be created, so that I am not left with orphaned parts.
+25. As an engineer importing against an existing part, if its incoming recipe fails, I want
+ the existing part left untouched, so that the import never destroys data I did not
+ upload.
+26. As an engineer, I want a per-part result of what was created, updated, skipped, and why,
+ so that I can reconcile the import against my source data.
+27. As an engineer, I want to import a method only for makeable items (Parts and Tools), and
+ get a clear error if I point a BOM at a Material, so that I am not misled into an
+ impossible operation.
+28. As an engineer, I only want these import options to appear where they make sense (the
+ Parts and Tools lists), so that the UI does not offer dead-ends on Materials or
+ Consumables.
+29. As an engineer, I want to download a template for each import type, so that I know the
+ exact columns expected.
+30. As an engineer, I want to map my spreadsheet columns to the expected fields with the
+ existing column-mapper, so that my source file does not have to match Carbon's headers
+ exactly.
+31. As an engineer, I want list-valued step options expressed with a simple delimiter in one
+ cell, so that I can author them in a spreadsheet.
+32. As an engineer, I want operation order (After Previous / With Previous) as an explicit
+ column defaulting to After Previous, so that parallel steps are expressible and the
+ common sequential case needs no input.
+33. As an engineer, I want BOM line order to follow the row order in the file, so that I do
+ not have to hand-number sequence columns.
+
+## Implementation Decisions
+
+- **One engine, three entry points.** A single row-type-multiplexed importer backs three
+ import types — `bom`, `operations`, and a combined `partWithMethod` — surfaced as **Import
+ BOM**, **Import Operations**, and **Import Parts with Methods** in the existing Bulk
+ Import dropdown on the Parts and Tools lists. The combined file may contain all row types;
+ the focused files carry a subset. All share validation, error reporting, and the
+ column-mapper.
+
+- **Row-type multiplexing.** A `Row Type` column discriminates six types: `PART`, `BOM`,
+ `BOP`, `STEP`, `TOOL`, `PARAM`. Each routes to its own processor. (ADR-0002)
+
+- **Explicit parent keying.** Every BOM/BOP/STEP/TOOL/PARAM row names its parent by
+ `Parent ID + Parent Revision` plus an optional `Make Method Version`. Multi-level BOM is
+ recursive: a sub-assembly is another part that owns its own rows. The positional `Level`
+ format is export-only. (ADR-0002)
+
+- **Operation correlation key.** Each `BOP` row carries an `Op No` unique within the parent.
+ It sets the operation's sequence and is the key that `STEP`/`TOOL`/`PARAM` rows reference
+ via `(Parent + Op No)`. BOM line order is positional (row order within the parent).
+ (ADR-0002)
+
+- **Method type and sourcing are item-level, not line-level.** A BOM line mirrors its
+ component item for method type and sourcing; these are derived from the component, never
+ read from the import. The half-built `methodMaterial` stub's `methodType` column and
+ `level` column are removed.
+
+- **Versioning.** Blank version targets the part's current method (`activeMakeMethods` — for
+ a new part, the empty Draft v1 created by the make-method trigger). An explicit version
+ finds-or-creates that Make Method Version as a **Draft** and fills it with the file's
+ content exactly (no copy-from-prior). The importer never changes which version is Active.
+ (ADR-0002)
+
+- **Create-only / fill-if-empty, evaluated per version.** A method is filled only if the
+ targeted version has zero materials and zero operations. A populated version is skipped
+ and reported, never clobbered. (ADR-0001)
+
+- **Atomicity per parent part.** The whole file is validated before any write. Each part's
+ recipe commits all-or-nothing; other parts proceed. In a combined file the new part row is
+ part of the unit and rolls back with a failed recipe; a pre-existing part is never rolled
+ back. (ADR-0001)
+
+- **Reference resolution.** Items (parent, component, tool) resolve by `readableId + revision`
+ within the company; the parent must be a makeable item (Part or Tool) or the part errors.
+ Process and work center resolve by name; an ambiguous name errors. UOM resolves by code
+ (default EA). Outside operations may optionally link a supplier process by supplier + process
+ name. Missing references hard-fail the affected part; nothing is auto-created.
+
+- **Processing order.** Within a file, all `PART` rows are processed first, then `BOM`, then
+ `BOP`, then `STEP`/`TOOL`/`PARAM`, so that parents and components defined in the same file
+ resolve.
+
+- **Modules touched.** Import rulebook (`apps/erp/app/modules/shared/imports.models.ts`):
+ replace the `methodMaterial` stub, add field mappings + Zod schemas + the `parts`
+ permission for the three types. The `import-csv` edge function
+ (`packages/database/supabase/functions/import-csv/`): row-type splitter, per-parent
+ grouping, up-front validation pass, atomic-per-part transactions, reference resolution, and
+ Make Method find-or-create. The Bulk Import dropdown (`TableHeader.tsx`) on the Parts and
+ Tools lists. Template generation for the three types.
+
+- **Edge-function caveat (architectural risk).** The `import-csv` edge function writes
+ directly to the database and does **not** call the app's `items.service.ts` upsert
+ functions. The derivation logic those functions own — method type/sourcing from the
+ component item, `materialMakeMethodId` resolution for Make-to-Order components, and
+ storage-unit seeding — must be replicated inside the edge function rather than reused.
+
+- **Result contract.** The importer returns a per-part summary in the existing
+ `{ inserted/created, updated, skipped, errors[] }` shape, keyed by part, surfaced in the
+ import modal.
+
+## Testing Decisions
+
+- **What makes a good test here:** assert external behavior, not internals. Drive the
+ importer with CSV content + column/enum mappings and assert (a) the resulting Make Method
+ state — which `methodMaterial`, `methodOperation`, and nested step/tool/parameter rows
+ exist under which version — and (b) the returned per-part summary (created/updated/skipped
+ + error reasons). Do not assert on private helper shapes or row-classification internals.
+
+- **Primary seam — the `import-csv` edge function.** This is the highest existing seam that
+ exercises parse → classify → validate → write end-to-end. Prefer it over introducing new
+ seams. New per-row validation is expressed through the Zod schemas in the import rulebook
+ and is covered transitively by edge-function tests; add focused schema tests only where a
+ conditional rule (e.g. Inside ⇒ units required, List ⇒ list values required) warrants it.
+
+- **Modules tested:** the `import-csv` edge function (behavioral, the bulk of coverage) and
+ the new import Zod schemas (targeted).
+
+- **Prior art:** follow the existing import-csv processing and `classify-import-row` logic and
+ any existing tests around it; mirror their fixture-driven style (CSV in, summary +
+ resulting rows out).
+
+- **Behavioral cases to cover:** combined file creating a new part with a multi-level BOM and
+ mixed Inside/Outside operations plus steps/tools/parameters; focused BOM and Operations
+ files against pre-existing parts; skip-if-content on re-run; atomicity (one bad line fails
+ only its part; a new part with a failing recipe is not persisted; a pre-existing part is
+ untouched); makeable-parent guard (Material parent errors); explicit version fills a new
+ Draft without disturbing the Active version; missing-reference hard-fail.
+
+## Out of Scope
+
+- A per-part "Import Method" button on the part's method page (the round-trip editing use
+ case). The same engine could power it later, but it is not part of this work.
+- A new round-trippable, import-shaped BOM/BOP **export**. The existing export remains a
+ cost report; this PRD does not make it byte-identical to the import format.
+- **Overwrite** of an existing populated recipe. The importer is create-only; overwrite would
+ be a separate, explicit opt-in.
+- Creating a new Make Method **Version** as a copy of a prior version (the in-app
+ copy-then-edit workflow). The importer only fills empty versions with explicit content.
+- Auto-creating components, processes, work centers, tools, or units of measure referenced by
+ the file. These must pre-exist.
+- Importing methods for non-makeable items (Material, Consumable, Fixture) as parents.
+- Non-CSV formats (xlsx, CAD files). Part upload is CSV-only and this feature stays in CSV.
+
+## Further Notes
+
+- There is an abandoned `methodMaterial` import stub in the rulebook with a `level` column
+ and a `methodType` column and no parent key; it is unwired in the edge function. This work
+ replaces that stub rather than extending it.
+- The make-method trigger creates an empty Draft v1 for every new Part and Tool, which is why
+ "already has a BOM" must mean "has method content," not "has a make method row."
+- Make Method Versions and Part Revisions are independent in the schema (separate rows,
+ cascade-scoped), which is what makes per-version and per-revision import safe. Jobs snapshot
+ the active version at creation, so importing into a method never disturbs running jobs.
+- The combined file carries the union of all six row types' columns and is therefore wide and
+ mostly-empty per row; the focused BOM and Operations files exist for users who want narrow
+ sheets.
diff --git a/apps/erp/app/modules/items/ui/Item/BoMExplorer.tsx b/apps/erp/app/modules/items/ui/Item/BoMExplorer.tsx
index 3c6046ae23..d4bdbc4cb8 100644
--- a/apps/erp/app/modules/items/ui/Item/BoMExplorer.tsx
+++ b/apps/erp/app/modules/items/ui/Item/BoMExplorer.tsx
@@ -411,7 +411,7 @@ const BoMExplorer = ({
</VStack>
{importBomDisclosure.isOpen && (
<ImportCSVModal
- table={"methodMaterial"}
+ table={"bom"}
onClose={() => importBomDisclosure.onClose()}
/>
)}
diff --git a/apps/erp/app/modules/items/ui/Parts/PartsTable.tsx b/apps/erp/app/modules/items/ui/Parts/PartsTable.tsx
index 65719e1bb4..5c11cfbc93 100644
--- a/apps/erp/app/modules/items/ui/Parts/PartsTable.tsx
+++ b/apps/erp/app/modules/items/ui/Parts/PartsTable.tsx
@@ -570,6 +570,18 @@ const PartsTable = memo(({ data, tags, count }: PartsTableProps) => {
{
table: "part" as const,
label: t`Parts`
+ },
+ {
+ table: "bom" as const,
+ label: t`BOM`
+ },
+ {
+ table: "operations" as const,
+ label: t`Operations`
+ },
+ {
+ table: "partWithMethod" as const,
+ label: t`Parts with Methods`
}
]}
primaryAction={
diff --git a/apps/erp/app/modules/items/ui/Tools/ToolsTable.tsx b/apps/erp/app/modules/items/ui/Tools/ToolsTable.tsx
index 58835d161b..3614897198 100644
--- a/apps/erp/app/modules/items/ui/Tools/ToolsTable.tsx
+++ b/apps/erp/app/modules/items/ui/Tools/ToolsTable.tsx
@@ -558,6 +558,18 @@ const ToolsTable = memo(({ data, tags, count }: ToolsTableProps) => {
{
table: "tool",
label: t`Tools`
+ },
+ {
+ table: "bom" as const,
+ label: t`BOM`
+ },
+ {
+ table: "operations" as const,
+ label: t`Operations`
+ },
+ {
+ table: "partWithMethod" as const,
+ label: t`Parts with Methods`
}
]}
primaryAction={
diff --git a/apps/erp/app/modules/shared/imports.models.ts b/apps/erp/app/modules/shared/imports.models.ts
index 8e18fbe344..4ce2f1afac 100644
--- a/apps/erp/app/modules/shared/imports.models.ts
+++ b/apps/erp/app/modules/shared/imports.models.ts
@@ -1,7 +1,11 @@
import type { Database } from "@carbon/database";
import type { SupabaseClient } from "@supabase/supabase-js";
import { z } from "zod";
-import { incoterms } from "./shared.models";
+import {
+ incoterms,
+ procedureStepType,
+ standardFactorType
+} from "./shared.models";
// to avoid a circular dependency
const methodType = [
@@ -129,6 +133,376 @@ const itemPurchasingImportFields = {
}
} as const;
+// Method (BOM/BOP) import — one row-type-multiplexed format (ADR-0002). A single
+// CSV may carry six row kinds discriminated by `Row Type`; each non-PART row names
+// its parent part explicitly, so multi-level BOMs need no positional Level column.
+// The combined file is the union of every group below (wide, mostly-empty rows);
+// the focused BOM / Operations files carry a subset. Field-level `required` here is
+// kept loose because a column's necessity depends on the row kind — the authoritative
+// per-row validation lives in the import-csv edge function (ADR-0001).
+const methodRowTypes = ["PART", "BOM", "BOP", "STEP", "TOOL", "PARAM"] as const;
+
+const unitOfMeasureFetcher = async (
+ client: SupabaseClient<Database>,
+ companyId: string
+) => {
+ const { data, error } = await client
+ .from("unitOfMeasure")
+ .select("name, code")
+ .eq("companyId", companyId);
+ if (error) return { data: null, error };
+ return { data: data.map((u) => ({ name: u.name, id: u.code })) };
+};
+
+// Row-type discriminator + explicit parent key. Spread into every method entry.
+const methodParentKeyFields = {
+ rowType: {
+ label: "Row Type",
+ required: false,
+ type: "enum",
+ enumData: {
+ description:
+ "Which kind of row this is: PART, BOM, BOP, STEP, TOOL, or PARAM",
+ options: methodRowTypes
+ }
+ },
+ parentId: {
+ label: "Parent ID",
+ required: false,
+ type: "string"
+ },
+ parentRevision: {
+ label: "Parent Revision",
+ required: false,
+ type: "string",
+ default: "0"
+ },
+ makeMethodVersion: {
+ label: "Make Method Version",
+ required: false,
+ type: "string"
+ }
+} as const;
+
+// Correlation key for an operation, referenced by its STEP/TOOL/PARAM children.
+const methodOpNoField = {
+ opNo: {
+ label: "Op No",
+ required: false,
+ type: "string"
+ }
+} as const;
+
+// BOM line. methodType / sourcingType are intentionally absent — they are derived
+// from the component item, never read from the import (PRD / commit #903).
+const methodBomFields = {
+ componentId: {
+ label: "Component ID",
+ required: false,
+ type: "string"
+ },
+ componentRevision: {
+ label: "Component Revision",
+ required: false,
+ type: "string",
+ default: "0"
+ },
+ quantity: {
+ label: "Quantity",
+ required: false,
+ type: "number"
+ },
+ unitOfMeasureCode: {
+ label: "Unit of Measure",
+ required: false,
+ type: "enum",
+ enumData: {
+ description: "The unit of measure of the component (default EA)",
+ fetcher: unitOfMeasureFetcher,
+ default: "EA"
+ }
+ },
+ kit: {
+ label: "Kit",
+ required: false,
+ type: "boolean"
+ }
+} as const;
+
+// BOP operation. Inside operations require time units; Outside operations carry
+// costing and an optional supplier-process link — enforced in the edge function.
+const methodBopFields = {
+ operationType: {
+ label: "Operation Type",
+ required: false,
+ type: "enum",
+ enumData: {
+ description: "Whether the operation is performed in-house or outsourced",
+ options: ["Inside", "Outside"],
+ default: "Inside"
+ }
+ },
+ operationOrder: {
+ label: "Operation Order",
+ required: false,
+ type: "enum",
+ enumData: {
+ description:
+ "Whether the operation runs after the previous one or in parallel with it",
+ options: ["After Previous", "With Previous"],
+ default: "After Previous"
+ }
+ },
+ process: {
+ label: "Process",
+ required: false,
+ type: "string"
+ },
+ workCenter: {
+ label: "Work Center",
+ required: false,
+ type: "string"
+ },
+ operationDescription: {
+ label: "Operation Description",
+ required: false,
+ type: "string"
+ },
+ setupTime: {
+ label: "Setup Time",
+ required: false,
+ type: "number"
+ },
+ setupUnit: {
+ label: "Setup Unit",
+ required: false,
+ type: "enum",
+ enumData: {
+ description: "Time unit for setup (required for Inside operations)",
+ options: standardFactorType,
+ default: "Total Minutes"
+ }
+ },
+ laborTime: {
+ label: "Labor Time",
+ required: false,
+ type: "number"
+ },
+ laborUnit: {
+ label: "Labor Unit",
+ required: false,
+ type: "enum",
+ enumData: {
+ description: "Time unit for labor (required for Inside operations)",
+ options: standardFactorType,
+ default: "Minutes/Piece"
+ }
+ },
+ machineTime: {
+ label: "Machine Time",
+ required: false,
+ type: "number"
+ },
+ machineUnit: {
+ label: "Machine Unit",
+ required: false,
+ type: "enum",
+ enumData: {
+ description: "Time unit for machine (required for Inside operations)",
+ options: standardFactorType,
+ default: "Minutes/Piece"
+ }
+ },
+ operationUnitCost: {
+ label: "Unit Cost",
+ required: false,
+ type: "number"
+ },
+ operationMinimumCost: {
+ label: "Minimum Cost",
+ required: false,
+ type: "number"
+ },
+ operationLeadTime: {
+ label: "Lead Time",
+ required: false,
+ type: "number"
+ },
+ supplier: {
+ label: "Operation Supplier",
+ required: false,
+ type: "string"
+ },
+ supplierProcess: {
+ label: "Supplier Process",
+ required: false,
+ type: "string"
+ }
+} as const;
+
+// Procedure step under an operation. Measurement steps require a unit of measure;
+// List steps require pipe-delimited values — enforced in the edge function.
+const methodStepFields = {
+ stepName: {
+ label: "Step Name",
+ required: false,
+ type: "string"
+ },
+ stepDescription: {
+ label: "Step Description",
+ required: false,
+ type: "string"
+ },
+ stepType: {
+ label: "Step Type",
+ required: false,
+ type: "enum",
+ enumData: {
+ description: "The kind of procedure step",
+ options: procedureStepType,
+ default: "Task"
+ }
+ },
+ stepRequired: {
+ label: "Step Required",
+ required: false,
+ type: "boolean"
+ },
+ stepUnitOfMeasureCode: {
+ label: "Step Unit of Measure",
+ required: false,
+ type: "enum",
+ enumData: {
+ description: "Unit of measure for a Measurement step",
+ fetcher: unitOfMeasureFetcher
+ }
+ },
+ stepMinValue: {
+ label: "Step Min Value",
+ required: false,
+ type: "number"
+ },
+ stepMaxValue: {
+ label: "Step Max Value",
+ required: false,
+ type: "number"
+ },
+ stepListValues: {
+ label: "Step List Values",
+ required: false,
+ type: "string"
+ }
+} as const;
+
+// Tool required by an operation, referenced by readable id + revision.
+const methodToolFields = {
+ toolId: {
+ label: "Tool ID",
+ required: false,
+ type: "string"
+ },
+ toolRevision: {
+ label: "Tool Revision",
+ required: false,
+ type: "string",
+ default: "0"
+ },
+ toolQuantity: {
+ label: "Tool Quantity",
+ required: false,
+ type: "number"
+ }
+} as const;
+
+// Process parameter (key/value) on an operation.
+const methodParamFields = {
+ paramKey: {
+ label: "Parameter Key",
+ required: false,
+ type: "string"
+ },
+ paramValue: {
+ label: "Parameter Value",
+ required: false,
+ type: "string"
+ }
+} as const;
+
+// Part import fields, hoisted so the combined `partWithMethod` entry can reuse the
+// exact same columns the standalone `part` import uses.
+const partImportFields = {
+ id: {
+ label: "Unique ID",
+ required: true,
+ type: "string"
+ },
+ readableId: {
+ label: "Part Number",
+ required: true,
+ type: "string"
+ },
+ revision: {
+ label: "Revision",
+ required: true,
+ type: "string",
+ default: "0"
+ },
+ name: {
+ label: "Description",
+ required: true,
+ type: "string"
+ },
+ active: {
+ label: "Active",
+ required: false,
+ type: "boolean"
+ },
+ replenishmentSystem: {
+ label: "Replenishment System",
+ required: false,
+ type: "enum",
+ enumData: {
+ description:
+ "Whether demand for a part should be fulfilled by buying or making",
+ options: itemReplenishmentSystems,
+ default: "Buy and Make"
+ }
+ },
+ defaultMethodType: {
+ label: "Default Method",
+ required: false,
+ type: "enum",
+ enumData: {
+ description:
+ "How a part should be produced when it is required in production",
+ options: methodType,
+ default: "Make"
+ }
+ },
+ itemTrackingType: {
+ label: "Tracking Type",
+ required: false,
+ type: "enum",
+ enumData: {
+ description: "Whether a part is tracked as inventory or not",
+ options: itemTrackingTypes,
+ default: "Inventory"
+ }
+ },
+ unitOfMeasureCode: {
+ label: "Unit of Measure",
+ required: false,
+ type: "enum",
+ enumData: {
+ description: "The unit of measure of the part",
+ fetcher: unitOfMeasureFetcher,
+ default: "EA"
+ }
+ },
+ ...supplierPartImportFields,
+ ...itemPurchasingImportFields
+} as const;
+
// Shared address + payment + incoterm fields. Spread into supplier and
// customer entries — they write to side-tables (supplierLocation/address +
// supplierPayment + supplierShipping; same for customer) in the edge
@@ -543,95 +917,7 @@ export const fieldMappings = {
}
},
part: {
- id: {
- label: "Unique ID",
- required: true,
- type: "string"
- },
- readableId: {
- label: "Part Number",
- required: true,
- type: "string"
- },
- revision: {
- label: "Revision",
- required: true,
- type: "string",
- default: "0"
- },
- name: {
- label: "Description",
- required: true,
- type: "string"
- },
- active: {
- label: "Active",
- required: false,
- type: "boolean"
- },
- replenishmentSystem: {
- label: "Replenishment System",
- required: false,
- type: "enum",
- enumData: {
- description:
- "Whether demand for a part should be fulfilled by buying or making",
- options: itemReplenishmentSystems,
- default: "Buy and Make"
- }
- },
- defaultMethodType: {
- label: "Default Method",
- required: false,
- type: "enum",
- enumData: {
- description:
- "How a part should be produced when it is required in production",
- options: methodType,
- default: "Make"
- }
- },
- itemTrackingType: {
- label: "Tracking Type",
- required: false,
- type: "enum",
- enumData: {
- description: "Whether a part is tracked as inventory or not",
- options: itemTrackingTypes,
- default: "Inventory"
- }
- },
- unitOfMeasureCode: {
- label: "Unit of Measure",
- required: false,
- type: "enum",
- enumData: {
- description: "The unit of measure of the part",
- fetcher: async (
- client: SupabaseClient<Database>,
- companyId: string
- ) => {
- const { data, error } = await client
- .from("unitOfMeasure")
- .select("name, code")
- .eq("companyId", companyId);
-
- if (error) {
- return { data: null, error };
- }
-
- return {
- data: data.map((item) => ({
- name: item.name,
- id: item.code
- }))
- };
- },
- default: "EA"
- }
- },
- ...supplierPartImportFields,
- ...itemPurchasingImportFields
+ ...partImportFields
},
tool: {
id: {
@@ -1039,68 +1325,39 @@ export const fieldMappings = {
...supplierPartImportFields,
...itemPurchasingImportFields
},
- methodMaterial: {
- level: {
- label: "Level",
- required: false,
- type: "string"
- },
- partId: {
- label: "Part ID",
- required: true,
- type: "string"
- },
- description: {
- label: "Description",
- required: false,
- type: "string"
- },
- methodType: {
- label: "Method Type",
- required: true,
- type: "enum",
- enumData: {
- description:
- "The method type of the part, which describes whether it is bought or made",
- options: methodType,
- default: "Pull from Inventory"
- }
- },
- quantity: {
- label: "Quantity",
- required: true,
- type: "number"
- },
- unitOfMeasureCode: {
- label: "Unit of Measure",
- required: true,
- type: "enum",
- enumData: {
- description: "The unit of measure of the part",
- fetcher: async (
- client: SupabaseClient<Database>,
- companyId: string
- ) => {
- const { data, error } = await client
- .from("unitOfMeasure")
- .select("name, code")
- .eq("companyId", companyId);
-
- if (error) {
- return { data: null, error };
- }
-
- return {
- data: data.map((item) => ({
- name: item.name,
- id: item.code
- }))
- };
- },
- default: "EA"
- }
- },
- ...supplierPartImportFields
+ // Focused BOM file — BOM lines against parts that already exist. Every row is a
+ // BOM line (rowType defaults to BOM), keyed to its parent part.
+ bom: {
+ ...methodParentKeyFields,
+ parentId: { ...methodParentKeyFields.parentId, required: true },
+ ...methodBomFields,
+ componentId: { ...methodBomFields.componentId, required: true },
+ quantity: { ...methodBomFields.quantity, required: true }
+ },
+ // Focused Operations file — operations plus their steps/tools/parameters against
+ // parts that already exist. Carries every method row type except BOM and PART.
+ operations: {
+ ...methodParentKeyFields,
+ rowType: { ...methodParentKeyFields.rowType, required: true },
+ parentId: { ...methodParentKeyFields.parentId, required: true },
+ ...methodOpNoField,
+ ...methodBopFields,
+ ...methodStepFields,
+ ...methodToolFields,
+ ...methodParamFields
+ },
+ // Combined file — creates parts and their full BOM + BOP together. The union of
+ // every row type's columns, so most cells are blank on any given row.
+ partWithMethod: {
+ ...partImportFields,
+ ...methodParentKeyFields,
+ rowType: { ...methodParentKeyFields.rowType, required: true },
+ ...methodOpNoField,
+ ...methodBomFields,
+ ...methodBopFields,
+ ...methodStepFields,
+ ...methodToolFields,
+ ...methodParamFields
},
workCenter: {
id: {
@@ -1297,7 +1554,9 @@ export const importPermissions: Record<keyof typeof fieldMappings, string> = {
supplierContact: "purchasing",
part: "parts",
material: "parts",
- methodMaterial: "parts",
+ bom: "parts",
+ operations: "parts",
+ partWithMethod: "parts",
tool: "parts",
fixture: "parts",
consumable: "parts",
@@ -1306,6 +1565,73 @@ export const importPermissions: Record<keyof typeof fieldMappings, string> = {
fixedAsset: "accounting"
};
+// Zod fragments for the method imports. Every method cell is an optional string at
+// the mapping layer (a column's necessity depends on the row kind); the import-csv
+// edge function performs the authoritative per-row validation (ADR-0001).
+const methodParentKeySchema = {
+ rowType: z.string().optional(),
+ parentId: z.string().optional(),
+ parentRevision: z.string().optional(),
+ makeMethodVersion: z.string().optional()
+};
+const methodBomSchema = {
+ componentId: z.string().optional(),
+ componentRevision: z.string().optional(),
+ quantity: z.string().optional(),
+ unitOfMeasureCode: z.string().optional(),
+ kit: z.string().optional()
+};
+const methodOpSchema = {
+ opNo: z.string().optional(),
+ operationType: z.string().optional(),
+ operationOrder: z.string().optional(),
+ process: z.string().optional(),
+ workCenter: z.string().optional(),
+ operationDescription: z.string().optional(),
+ setupTime: z.string().optional(),
+ setupUnit: z.string().optional(),
+ laborTime: z.string().optional(),
+ laborUnit: z.string().optional(),
+ machineTime: z.string().optional(),
+ machineUnit: z.string().optional(),
+ operationUnitCost: z.string().optional(),
+ operationMinimumCost: z.string().optional(),
+ operationLeadTime: z.string().optional(),
+ supplier: z.string().optional(),
+ supplierProcess: z.string().optional(),
+ stepName: z.string().optional(),
+ stepDescription: z.string().optional(),
+ stepType: z.string().optional(),
+ stepRequired: z.string().optional(),
+ stepUnitOfMeasureCode: z.string().optional(),
+ stepMinValue: z.string().optional(),
+ stepMaxValue: z.string().optional(),
+ stepListValues: z.string().optional(),
+ toolId: z.string().optional(),
+ toolRevision: z.string().optional(),
+ toolQuantity: z.string().optional(),
+ paramKey: z.string().optional(),
+ paramValue: z.string().optional()
+};
+const methodPartSchema = {
+ id: z.string().optional(),
+ readableId: z.string().optional(),
+ revision: z.string().optional(),
+ name: z.string().optional(),
+ active: z.string().optional(),
+ replenishmentSystem: z.string().optional(),
+ defaultMethodType: z.string().optional(),
+ itemTrackingType: z.string().optional(),
+ supplierId: z.string().optional(),
+ supplierPartId: z.string().optional(),
+ supplierUnitOfMeasureCode: z.string().optional(),
+ minimumOrderQuantity: z.string().optional(),
+ orderMultiple: z.string().optional(),
+ conversionFactor: z.string().optional(),
+ unitPrice: z.string().optional(),
+ leadTime: z.string().optional()
+};
+
export const importSchemas: Record<
keyof typeof fieldMappings,
z.ZodObject<any>
@@ -1713,24 +2039,47 @@ export const importSchemas: Record<
unitPrice: z.string().optional(),
leadTime: z.string().optional()
}),
- methodMaterial: z.object({
- level: z.string().optional().describe("The level of the material"),
- partId: z
+ bom: z.object({
+ ...methodParentKeySchema,
+ parentId: z
.string()
- .min(1, { message: "Part ID is required" })
- .describe("The id of the part"),
- description: z.string().optional().describe("The description of the part"),
- quantity: z.string().describe("The quantity of the part"),
- methodType: z
+ .min(1, { message: "Parent ID is required" })
+ .describe("The readable id of the parent part this BOM line belongs to"),
+ ...methodBomSchema,
+ componentId: z
.string()
- .optional()
- .describe(
- "The method type of the part, which describes whether it is bought or made"
- ),
- unitOfMeasureCode: z
+ .min(1, { message: "Component ID is required" })
+ .describe("The readable id of the component consumed by this BOM line"),
+ quantity: z
.string()
- .optional()
- .describe("The unit of measure of the part")
+ .min(1, { message: "Quantity is required" })
+ .describe("The quantity of the component consumed")
+ }),
+ operations: z.object({
+ ...methodParentKeySchema,
+ rowType: z
+ .string()
+ .min(1, { message: "Row Type is required" })
+ .describe("BOP, STEP, TOOL, or PARAM"),
+ parentId: z
+ .string()
+ .min(1, { message: "Parent ID is required" })
+ .describe("The readable id of the parent part this row belongs to"),
+ ...methodOpSchema,
+ opNo: z
+ .string()
+ .min(1, { message: "Op No is required" })
+ .describe("The operation number, unique within the parent part")
+ }),
+ partWithMethod: z.object({
+ ...methodPartSchema,
+ ...methodParentKeySchema,
+ rowType: z
+ .string()
+ .min(1, { message: "Row Type is required" })
+ .describe("PART, BOM, BOP, STEP, TOOL, or PARAM"),
+ ...methodBomSchema,
+ ...methodOpSchema
}),
workCenter: z.object({
id: z
diff --git a/packages/database/supabase/functions/import-csv/index.ts b/packages/database/supabase/functions/import-csv/index.ts
index 21735b6731..a57c674b9e 100644
--- a/packages/database/supabase/functions/import-csv/index.ts
+++ b/packages/database/supabase/functions/import-csv/index.ts
@@ -9,6 +9,7 @@ import { requirePermissions } from "../lib/supabase.ts";
import { Database } from "../lib/types.ts";
import { getReadableIdWithRevision } from "../lib/utils.ts";
import { classifyImportRow } from "./classify-import-row.ts";
+import { importMethods } from "./method-import.ts";
const pool = getConnectionPool(1);
const db = getDatabaseClient<DB>(pool);
@@ -20,7 +21,9 @@ const importCsvValidator = z.object({
"customerContact",
"fixture",
"material",
- "methodMaterial",
+ "bom",
+ "operations",
+ "partWithMethod",
"part",
"supplier",
"supplierContact",
@@ -2128,8 +2131,17 @@ serve(async (req: Request) => {
});
break;
}
- case "methodMaterial": {
- throw new Error("Not implemented");
+ case "bom":
+ case "operations":
+ case "partWithMethod": {
+ await importMethods(db, {
+ table,
+ mappedRecords,
+ companyId,
+ userId,
+ summary,
+ });
+ break;
}
default: {
throw new Error(`Invalid table: ${table}`);
diff --git a/packages/database/supabase/functions/import-csv/method-import.ts b/packages/database/supabase/functions/import-csv/method-import.ts
new file mode 100644
index 0000000000..ab0815c89f
Binary files /dev/null and b/packages/database/supabase/functions/import-csv/method-import.ts differ
diff --git a/packages/locale/locales/de/erp.po b/packages/locale/locales/de/erp.po
index 52828632fa..a95fae456e 100644
--- a/packages/locale/locales/de/erp.po
+++ b/packages/locale/locales/de/erp.po
@@ -1132,6 +1132,9 @@ msgstr "Blockiert Speichern bis behoben"
msgid "BoM"
msgstr "BoM"
+msgid "BOM"
+msgstr ""
+
msgid "BoM + BoP"
msgstr "BoM + BoP"
@@ -5777,6 +5780,9 @@ msgstr "Partner"
msgid "Parts"
msgstr "Teile"
+msgid "Parts with Methods"
+msgstr ""
+
msgid "Pass"
msgstr "Bestanden"
diff --git a/packages/locale/locales/en/erp.po b/packages/locale/locales/en/erp.po
index 3b8c57d21e..db7c13e1b8 100644
--- a/packages/locale/locales/en/erp.po
+++ b/packages/locale/locales/en/erp.po
@@ -1132,6 +1132,9 @@ msgstr "Blocks save until resolved"
msgid "BoM"
msgstr "BoM"
+msgid "BOM"
+msgstr "BOM"
+
msgid "BoM + BoP"
msgstr "BoM + BoP"
@@ -5777,6 +5780,9 @@ msgstr "Partners"
msgid "Parts"
msgstr "Parts"
+msgid "Parts with Methods"
+msgstr "Parts with Methods"
+
msgid "Pass"
msgstr "Pass"
diff --git a/packages/locale/locales/es/erp.po b/packages/locale/locales/es/erp.po
index 643877a8c4..0b33870b59 100644
--- a/packages/locale/locales/es/erp.po
+++ b/packages/locale/locales/es/erp.po
@@ -1132,6 +1132,9 @@ msgstr "Bloquea guardar hasta que se resuelva"
msgid "BoM"
msgstr "BoM"
+msgid "BOM"
+msgstr ""
+
msgid "BoM + BoP"
msgstr "BoM + BoP"
@@ -5777,6 +5780,9 @@ msgstr "Socios"
msgid "Parts"
msgstr "Piezas"
+msgid "Parts with Methods"
+msgstr ""
+
msgid "Pass"
msgstr "Aprobar"
diff --git a/packages/locale/locales/fr/erp.po b/packages/locale/locales/fr/erp.po
index b5a90a5246..2315873ac6 100644
--- a/packages/locale/locales/fr/erp.po
+++ b/packages/locale/locales/fr/erp.po
@@ -1132,6 +1132,9 @@ msgstr "Bloque la sauvegarde jusqu'à résolution"
msgid "BoM"
msgstr "BoM"
+msgid "BOM"
+msgstr ""
+
msgid "BoM + BoP"
msgstr "BoM + BoP"
@@ -5777,6 +5780,9 @@ msgstr "Partenaires"
msgid "Parts"
msgstr "Pièces"
+msgid "Parts with Methods"
+msgstr ""
+
msgid "Pass"
msgstr "Réussir"
diff --git a/packages/locale/locales/hi/erp.po b/packages/locale/locales/hi/erp.po
index ecd1d895d2..d7d3584c0a 100644
--- a/packages/locale/locales/hi/erp.po
+++ b/packages/locale/locales/hi/erp.po
@@ -1132,6 +1132,9 @@ msgstr "सहेजने को तब तक ब्लॉक करता ह
msgid "BoM"
msgstr "BoM"
+msgid "BOM"
+msgstr ""
+
msgid "BoM + BoP"
msgstr "BoM + BoP"
@@ -5777,6 +5780,9 @@ msgstr "भागीदार"
msgid "Parts"
msgstr "पार्ट्स"
+msgid "Parts with Methods"
+msgstr ""
+
msgid "Pass"
msgstr "पास"
diff --git a/packages/locale/locales/it/erp.po b/packages/locale/locales/it/erp.po
index 93a6c121af..656b2186c4 100644
--- a/packages/locale/locales/it/erp.po
+++ b/packages/locale/locales/it/erp.po
@@ -1132,6 +1132,9 @@ msgstr "Blocca il salvataggio fino alla risoluzione"
msgid "BoM"
msgstr "BoM"
+msgid "BOM"
+msgstr ""
+
msgid "BoM + BoP"
msgstr "BoM + BoP"
@@ -5777,6 +5780,9 @@ msgstr "Partner"
msgid "Parts"
msgstr "Parti"
+msgid "Parts with Methods"
+msgstr ""
+
msgid "Pass"
msgstr "Passa"
diff --git a/packages/locale/locales/ja/erp.po b/packages/locale/locales/ja/erp.po
index de5a736578..952dbab885 100644
--- a/packages/locale/locales/ja/erp.po
+++ b/packages/locale/locales/ja/erp.po
@@ -1132,6 +1132,9 @@ msgstr "解決されるまで保存をブロックします"
msgid "BoM"
msgstr "BoM"
+msgid "BOM"
+msgstr ""
+
msgid "BoM + BoP"
msgstr "BoM + BoP"
@@ -5777,6 +5780,9 @@ msgstr "パートナー"
msgid "Parts"
msgstr "部品"
+msgid "Parts with Methods"
+msgstr ""
+
msgid "Pass"
msgstr "合格"
diff --git a/packages/locale/locales/pl/erp.po b/packages/locale/locales/pl/erp.po
index f122113eb5..febfcf7bd4 100644
--- a/packages/locale/locales/pl/erp.po
+++ b/packages/locale/locales/pl/erp.po
@@ -1132,6 +1132,9 @@ msgstr "Blokuje zapis do czasu rozwiązania"
msgid "BoM"
msgstr "BoM"
+msgid "BOM"
+msgstr ""
+
msgid "BoM + BoP"
msgstr "BoM + BoP"
@@ -5777,6 +5780,9 @@ msgstr "Partnerzy"
msgid "Parts"
msgstr "Części"
+msgid "Parts with Methods"
+msgstr ""
+
msgid "Pass"
msgstr "Zatwierdź"
diff --git a/packages/locale/locales/pt/erp.po b/packages/locale/locales/pt/erp.po
index ae3e2130d7..bf0434126b 100644
--- a/packages/locale/locales/pt/erp.po
+++ b/packages/locale/locales/pt/erp.po
@@ -1132,6 +1132,9 @@ msgstr "Bloqueia a gravação até ser resolvido"
msgid "BoM"
msgstr "BoM"
+msgid "BOM"
+msgstr ""
+
msgid "BoM + BoP"
msgstr "BoM + BoP"
@@ -5777,6 +5780,9 @@ msgstr "Parceiros"
msgid "Parts"
msgstr "Peças"
+msgid "Parts with Methods"
+msgstr ""
+
msgid "Pass"
msgstr "Passar"
diff --git a/packages/locale/locales/ru/erp.po b/packages/locale/locales/ru/erp.po
index 17387d4519..0af27c1e67 100644
--- a/packages/locale/locales/ru/erp.po
+++ b/packages/locale/locales/ru/erp.po
@@ -1132,6 +1132,9 @@ msgstr "Блокирует сохранение до разрешения"
msgid "BoM"
msgstr "BoM"
+msgid "BOM"
+msgstr ""
+
msgid "BoM + BoP"
msgstr "BoM + BoP"
@@ -5777,6 +5780,9 @@ msgstr "Партнеры"
msgid "Parts"
msgstr "Детали"
+msgid "Parts with Methods"
+msgstr ""
+
msgid "Pass"
msgstr "Пройти"
diff --git a/packages/locale/locales/zh/erp.po b/packages/locale/locales/zh/erp.po
index 423a8c794f..06f83a4149 100644
--- a/packages/locale/locales/zh/erp.po
+++ b/packages/locale/locales/zh/erp.po
@@ -1132,6 +1132,9 @@ msgstr "阻止保存直到解决"
msgid "BoM"
msgstr "物料清单"
+msgid "BOM"
+msgstr ""
+
msgid "BoM + BoP"
msgstr "BoM + BoP"
@@ -5777,6 +5780,9 @@ msgstr "合作伙伴"
msgid "Parts"
msgstr "零件"
+msgid "Parts with Methods"
+msgstr ""
+
msgid "Pass"
msgstr "通过"