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: add account manager enum to csv import for suppliers and customers

Brad Barbincd3127fa44e9
diff --git a/apps/carbon/app/modules/shared/imports.models.ts b/apps/carbon/app/modules/shared/imports.models.ts
index 527054d8e6..a9c320de08 100644
--- a/apps/carbon/app/modules/shared/imports.models.ts
+++ b/apps/carbon/app/modules/shared/imports.models.ts
@@ -18,10 +18,23 @@ export const fieldMappings = {
required: true,
type: "string",
},
- phone: {
- label: "Phone",
+ accountManagerId: {
+ label: "Account Manager",
required: false,
- type: "string",
+ type: "enum",
+ enumData: {
+ description: "The account manager of the customer",
+ fetcher: async (
+ client: SupabaseClient<Database>,
+ companyId: string
+ ) => {
+ return client
+ .from("employees")
+ .select("id, name, avatarUrl")
+ .eq("companyId", companyId)
+ .order("name");
+ },
+ },
},
fax: {
label: "Fax",
@@ -55,6 +68,24 @@ export const fieldMappings = {
required: true,
type: "string",
},
+ accountManagerId: {
+ label: "Account Manager",
+ required: false,
+ type: "enum",
+ enumData: {
+ description: "The account manager of the customer",
+ fetcher: async (
+ client: SupabaseClient<Database>,
+ companyId: string
+ ) => {
+ return client
+ .from("employees")
+ .select("id, name, avatarUrl")
+ .eq("companyId", companyId)
+ .order("name");
+ },
+ },
+ },
phone: {
label: "Phone",
required: false,
@@ -592,22 +623,38 @@ export const importSchemas: Record<
.describe(
"The name of the customer. Sometimes contains Inc or LLC. Usually a proper noun."
),
- phone: z.string().optional().describe("The phone number of the customer"),
- fax: z.string().optional().describe("The fax number of the customer"),
+ accountManagerId: z
+ .string()
+ .optional()
+ .describe("The id of the account manager of the customer")
+ .nullable(),
+ phone: z
+ .string()
+ .optional()
+ .describe("The phone number of the customer")
+ .nullable(),
+ fax: z
+ .string()
+ .optional()
+ .describe("The fax number of the customer")
+ .nullable(),
taxId: z
.string()
.optional()
.describe(
"The tax identification number of the customer. Usually numeric."
- ),
+ )
+ .nullable(),
currencyCode: z
.string()
.optional()
- .describe("The currency code of the customer. Usually a 3-letter code."),
+ .describe("The currency code of the customer. Usually a 3-letter code.")
+ .nullable(),
website: z
.string()
.optional()
- .describe("The website url. Usually begins with http:// or https://"),
+ .describe("The website url. Usually begins with http:// or https://")
+ .nullable(),
}),
supplier: z.object({
id: z
@@ -622,22 +669,38 @@ export const importSchemas: Record<
.describe(
"The name of the supplier. Sometimes contains Inc or LLC. Usually a proper noun."
),
- phone: z.string().optional().describe("The phone number of the supplier"),
- fax: z.string().optional().describe("The fax number of the supplier"),
+ accountManagerId: z
+ .string()
+ .optional()
+ .describe("The id of the account manager of the supplier")
+ .nullable(),
+ phone: z
+ .string()
+ .optional()
+ .describe("The phone number of the supplier")
+ .nullable(),
+ fax: z
+ .string()
+ .optional()
+ .describe("The fax number of the supplier")
+ .nullable(),
taxId: z
.string()
.optional()
.describe(
"The tax identification number of the supplier. Usually numeric."
- ),
+ )
+ .nullable(),
currencyCode: z
.string()
.optional()
- .describe("The currency code of the supplier. Usually a 3-letter code."),
+ .describe("The currency code of the supplier. Usually a 3-letter code.")
+ .nullable(),
website: z
.string()
.optional()
- .describe("The website url. Usually begins with http:// or https://"),
+ .describe("The website url. Usually begins with http:// or https://")
+ .nullable(),
}),
part: z.object({
id: z
diff --git a/apps/carbon/app/routes/api+/ai+/csv+/$table.columns.tsx b/apps/carbon/app/routes/api+/ai+/csv+/$table.columns.tsx
index 900d206d04..0fba373464 100644
--- a/apps/carbon/app/routes/api+/ai+/csv+/$table.columns.tsx
+++ b/apps/carbon/app/routes/api+/ai+/csv+/$table.columns.tsx
@@ -36,24 +36,28 @@ export async function action({ request, params }: ActionFunctionArgs) {
throw notFound("Table not found in the list of supported tables");
}
- const { object } = await generateObject<Record<string, string>>({
- model: openai("gpt-4o-mini"),
- schema,
- prompt: `
- The following columns are the headings from a CSV import file for importing a ${table}.
- Map these column names to the correct fields in our database (${[
- ...Object.keys(getZodSchemaFieldsShallow(schema)),
- ].join(", ")}) by providing the matching column name for each field.
-
- If you are not sure or there is no matching column, omit the value.
-
- Columns:
- ${fileColumns.join(",")}
+ try {
+ const { object } = await generateObject<Record<string, string>>({
+ model: openai("gpt-4o-mini"),
+ schema,
+ prompt: `
+ The following columns are the headings from a CSV import file for importing a ${table}.
+ Map these column names to the correct fields in our database (${[
+ ...Object.keys(getZodSchemaFieldsShallow(schema)),
+ ].join(", ")}) by providing the matching column name for each field.
+
+ If you are not sure or there is no matching column.
+
+ Columns:
+ ${fileColumns.join(",")}
`,
- temperature: 0.2,
- });
+ temperature: 0.2,
+ });
- return json(object);
+ return json(object);
+ } catch (error) {
+ return json({});
+ }
}
export function getZodSchemaFieldsShallow(schema: ZodSchema) {