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(inventory): gate stock imports in the edge function and fix batch labels
Rauld1946bce6474
diff --git a/.claude/rules/csv-import-system.md b/.claude/rules/csv-import-system.mdindex 044726b222..5b2cf99742 100644--- a/.claude/rules/csv-import-system.md+++ b/.claude/rules/csv-import-system.md@@ -267,6 +267,9 @@ edge function directly.Deno `serve` handler. Payload validated by `importCsvValidator` (table enum, `filePath`,`columnMappings`, optional `enumMappings`, `companyId`, `userId`).+- Re-checks the caller: `update` on `IMPORT_PERMISSIONS[table]`, plus `create` for tables in+ `IMPORT_REQUIRES_CREATE`. Both mirror `importPermissions` / `importRequiresCreate` in the+ models, so a new import type adds its table to both sides.- Downloads CSV: `client.storage.from("private").download(filePath)`.- Parses with Deno std `import { parse } from "https://deno.land/[email protected]/encoding/csv.ts"`(`skipFirstRow: true, lazyQuotes: true`), falling back to a custom `parsePermissiveCsv()`@@ -316,7 +319,7 @@ See `.claude/rules/accounting-sync-handlers.md` for the full `externalIntegratioThey are separate parsers — don't assume identical behavior.- `enumMappings` crosses the route boundary as a JSON string; the service/edge function expectthe parsed object.-- The edge function transaction uses Kysely and bypasses RLS — the route's `requirePermissions`- is the only authorization gate.+- The edge function transaction uses Kysely and bypasses RLS; authorization is the route's+ `requirePermissions` plus the edge function's own check on the same permissions.- Row-level failures are returned in `errors[]` with `{ row, reason }`; only a thrownexception produces a 500.diff --git a/packages/database/supabase/functions/import-csv/index.ts b/packages/database/supabase/functions/import-csv/index.tsindex b705471b91..83b2ed8113 100644--- a/packages/database/supabase/functions/import-csv/index.ts+++ b/packages/database/supabase/functions/import-csv/index.ts@@ -95,8 +95,19 @@ const IMPORT_PERMISSIONS: Record<ImportTable, string> = {materialGrade: "parts",materialType: "parts",materialDimension: "parts",+ inventoryQuantity: "inventory",+ batchQuantity: "inventory",+ serialQuantity: "inventory",};+// Imports that post new records also need `create`, as the ERP's import route+// demands (`importRequiresCreate` in `imports.models.ts`).+const IMPORT_REQUIRES_CREATE = new Set<ImportTable>([+ "inventoryQuantity",+ "batchQuantity",+ "serialQuantity",+]);+// The columns each importer may write from a CSV row. Kysely here runs as the// service role, so spreading a row into an INSERT/UPDATE would let a crafted// mapping write `id`, `createdBy`, `intercompanyCompanyId`, or any other@@ -1199,6 +1210,9 @@ serve(async (req: Request) => {const client = await requirePermissions(req, companyId, userId, {update: IMPORT_PERMISSIONS[table],+ ...(IMPORT_REQUIRES_CREATE.has(table)+ ? { create: IMPORT_PERMISSIONS[table] }+ : {}),});// The client is service-role and the legacy bucket is shared acrossdiff --git a/packages/locale/locales/es/erp.po b/packages/locale/locales/es/erp.poindex 6c59a778f7..db4109b8e5 100644--- a/packages/locale/locales/es/erp.po+++ b/packages/locale/locales/es/erp.po@@ -2977,7 +2977,7 @@ msgid "Batch Properties"msgstr "Propiedades de Lote"msgid "Batch Quantities"-msgstr "Cantidades de Lote de Producción"+msgstr "Cantidades de Lote"msgid "Batch Size"msgstr "Tamaño de Lote"diff --git a/packages/locale/locales/fr/erp.po b/packages/locale/locales/fr/erp.poindex 590b1b3d9b..ad91377f80 100644--- a/packages/locale/locales/fr/erp.po+++ b/packages/locale/locales/fr/erp.po@@ -2977,7 +2977,7 @@ msgid "Batch Properties"msgstr "Propriétés de lot"msgid "Batch Quantities"-msgstr "Quantités de lot de production"+msgstr "Quantités de lot"msgid "Batch Size"msgstr "Taille de lot"diff --git a/packages/locale/locales/it/erp.po b/packages/locale/locales/it/erp.poindex 70dae46aa4..f50ffa3f95 100644--- a/packages/locale/locales/it/erp.po+++ b/packages/locale/locales/it/erp.po@@ -2977,7 +2977,7 @@ msgid "Batch Properties"msgstr "Proprietà Batch"msgid "Batch Quantities"-msgstr "Quantità lotto di produzione"+msgstr "Quantità lotto"msgid "Batch Size"msgstr "Dimensione lotto"diff --git a/packages/locale/locales/pl/erp.po b/packages/locale/locales/pl/erp.poindex f37fe1b2ba..ae3ec3fbee 100644--- a/packages/locale/locales/pl/erp.po+++ b/packages/locale/locales/pl/erp.po@@ -2977,7 +2977,7 @@ msgid "Batch Properties"msgstr "Właściwości partii"msgid "Batch Quantities"-msgstr "Ilości partii produkcyjnych"+msgstr "Ilości partii"msgid "Batch Size"msgstr "Rozmiar partii"diff --git a/packages/locale/locales/pt/erp.po b/packages/locale/locales/pt/erp.poindex 0be3207991..ed02a2bd05 100644--- a/packages/locale/locales/pt/erp.po+++ b/packages/locale/locales/pt/erp.po@@ -2977,7 +2977,7 @@ msgid "Batch Properties"msgstr "Propriedades em Lote"msgid "Batch Quantities"-msgstr "Quantidades de Lotes de Produção"+msgstr "Quantidades de Lote"msgid "Batch Size"msgstr "Tamanho do Lote"diff --git a/packages/locale/locales/ru/erp.po b/packages/locale/locales/ru/erp.poindex a9a87cf8a0..06b993d28c 100644--- a/packages/locale/locales/ru/erp.po+++ b/packages/locale/locales/ru/erp.po@@ -2977,7 +2977,7 @@ msgid "Batch Properties"msgstr "Свойства партии"msgid "Batch Quantities"-msgstr "Количество по сериям"+msgstr "Количество по партиям"msgid "Batch Size"msgstr "Размер партии"diff --git a/packages/locale/locales/zh/erp.po b/packages/locale/locales/zh/erp.poindex 1590741163..20ec1c85cb 100644--- a/packages/locale/locales/zh/erp.po+++ b/packages/locale/locales/zh/erp.po@@ -2977,7 +2977,7 @@ msgid "Batch Properties"msgstr "批量属性"msgid "Batch Quantities"-msgstr "生产批次数量"+msgstr "批次数量"msgid "Batch Size"msgstr "批量大小"