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(csv-import): derive the service method instead of offering it as a column

Raul4952e34c9405
diff --git a/.claude/rules/csv-import-system.md b/.claude/rules/csv-import-system.md
index c1bea3237e..9d3c40d96a 100644
--- a/.claude/rules/csv-import-system.md
+++ b/.claude/rules/csv-import-system.md
@@ -73,9 +73,16 @@ Other exports: `creatableLookups`, and types `CreatableLookup`, `CreatableForm`.
`part`, `material`, `tool`, `fixture`, `consumable`, `service`, `bom`,
`operations`, `partWithMethod`, `materialSubstance`, `materialForm`, `materialFinish`,
`materialGrade`, `materialType`, `materialDimension`, `unitOfMeasure`,
-`itemPostingGroup`, `storageType` → `parts`;
+`storageType` → `parts`;
`workCenter`, `process`, `scrapReason` → `production`; `storageUnit` → `inventory`;
-`department` → `people`; `fixedAsset` → `accounting`.
+`department` → `people`; `itemPostingGroup`, `fixedAsset` → `accounting`.
+
+An import's permission is the one its table's **RLS INSERT policy** requires, not
+the one that opens its list page. The edge function writes through a service-role
+Kysely connection that bypasses RLS, so `importPermissions` is the only
+authorization on a bulk import — taking it from the page gate would let a user
+create rows the database itself would refuse. `itemPostingGroup` is where the two
+disagree: its page is parts-gated, its policies are `accounting_*`.
The edge function's own `table` enum (`import-csv/index.ts`) accepts: `consumable`,
`customer`, `customerContact`, `fixture`, `material`, `bom`, `operations`,
diff --git a/apps/erp/app/modules/shared/imports.models.ts b/apps/erp/app/modules/shared/imports.models.ts
index dec58155db..c3a261f7b1 100644
--- a/apps/erp/app/modules/shared/imports.models.ts
+++ b/apps/erp/app/modules/shared/imports.models.ts
@@ -1306,17 +1306,12 @@ export const fieldMappings = {
default: "Buy"
}
},
- defaultMethodType: {
- label: "Default Method",
- required: false,
- type: "enum",
- enumData: {
- description:
- "How the service is fulfilled when it is required in production",
- options: methodType,
- default: "Purchase to Order"
- }
- },
+ // No Default Method column: a service is Non-Inventory, so its method is
+ // fully determined by the replenishment system and "Pull from Inventory" is
+ // not a valid value for it. `ServiceForm` derives it and renders it hidden
+ // for the same reason; the edge function derives it identically. Offering
+ // the column would admit both an invalid method and one that contradicts
+ // the replenishment system on the same row.
unitOfMeasureCode: {
label: "Unit of Measure",
required: false,
@@ -2613,10 +2608,6 @@ export const importSchemas: Record<
.describe(
"Whether the service is bought from a supplier or performed in-house"
),
- defaultMethodType: z
- .string()
- .optional()
- .describe("How the service is fulfilled when required in production"),
unitOfMeasureCode: z
.string()
.optional()
diff --git a/packages/database/supabase/functions/import-csv/index.ts b/packages/database/supabase/functions/import-csv/index.ts
index 31e2ab643e..5693b57016 100644
--- a/packages/database/supabase/functions/import-csv/index.ts
+++ b/packages/database/supabase/functions/import-csv/index.ts
@@ -1447,12 +1447,20 @@ serve(async (req: Request) => {
return `${table}:${id}`;
};
- // A service can never be shipped, received or stocked, so the wizard
- // does not offer a Tracking Type column for it. The item validator
- // below requires one, and `upsertService` hard-codes the same value.
+ // A service can never be shipped, received or stocked. The wizard
+ // therefore offers neither a Tracking Type nor a Default Method column
+ // for one: the validator below requires a tracking type, and the method
+ // is fully determined by the replenishment system — "Pull from
+ // Inventory" is not valid for a Non-Inventory item, and an independent
+ // column could contradict the replenishment system on the same row.
+ // `ServiceForm` derives both the same way and hides the method field.
if (table === "service") {
for (const record of mappedRecords) {
record.itemTrackingType = "Non-Inventory";
+ record.defaultMethodType =
+ record.replenishmentSystem === "Make"
+ ? "Make to Order"
+ : "Purchase to Order";
}
}