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: bugs in paperless schema

Brad Barbincd90bb939010
diff --git a/apps/erp/vite.config.ts b/apps/erp/vite.config.ts
index 11cafaeeab..65a2eb5a51 100644
--- a/apps/erp/vite.config.ts
+++ b/apps/erp/vite.config.ts
@@ -33,7 +33,7 @@ export default defineConfig({
},
server: {
port: 3000,
- allowedHosts: ["6be9ee07664a.ngrok-free.app"],
+ allowedHosts: ["8d53c60dbab3.ngrok-free.app"],
},
plugins: [
remix({
diff --git a/packages/integrations/src/paperless-parts/lib/schemas.ts b/packages/integrations/src/paperless-parts/lib/schemas.ts
index 7f2436ad9b..dbfe7560b2 100644
--- a/packages/integrations/src/paperless-parts/lib/schemas.ts
+++ b/packages/integrations/src/paperless-parts/lib/schemas.ts
@@ -98,7 +98,7 @@ export const CostingVariableSchema = z.object({
.enum(["number", "currency", "boolean", "string", "table", "date"])
.nullable()
.optional(),
- value: z.number().nullable().optional(),
+ value: z.any().nullable().optional(),
row: z.record(z.string(), z.unknown()).nullable().optional(),
options: z.unknown().nullable().optional(),
type: z
diff --git a/packages/integrations/src/paperless-parts/lib/utils.ts b/packages/integrations/src/paperless-parts/lib/utils.ts
index 59bada4628..7c22205c8d 100644
--- a/packages/integrations/src/paperless-parts/lib/utils.ts
+++ b/packages/integrations/src/paperless-parts/lib/utils.ts
@@ -1053,29 +1053,36 @@ export async function createPartFromComponent(
operation,
] of component.shop_operations.entries()) {
if (operation.category === "operation") {
- const processId = await getOrCreateProcess(
+ const process = await getOrCreateProcess(
carbon,
operation,
companyId,
createdBy
);
- if (processId) {
+ if (process) {
operations.push({
order: operation.position ?? index + 1,
operationOrder: "After Previous",
- description: operation.operation_definition_name,
- processId: processId.id,
+ operationType:
+ process.processType === "Inside" ? "Inside" : "Outside",
+ description:
+ operation.operation_definition_name ??
+ operation.name ??
+ `Operation ${operation.position ?? index + 1}`,
+ processId: process.id,
companyId,
createdBy,
- setupTime: operation.setup_time,
+ setupTime: operation.setup_time ?? 0,
setupUnit: "Total Minutes",
- laborTime: operation.runtime,
+ laborTime: operation.runtime ?? 0,
laborUnit: "Minutes/Piece",
workInstruction: operation.notes
? textToTiptap(operation.notes)
: {},
});
}
+ } else {
+ console.error("operation.category is not operation", operation);
}
// if (operation.costing_variables) {
// operation.costing_variables.forEach((cv: any) => {
@@ -1173,17 +1180,21 @@ export async function createPartFromComponent(
console.error("Failed to create make method:", makeMethod.error);
}
- console.log({ makeMethod });
const makeMethodId = makeMethod.data?.id;
if (makeMethodId) {
- const result = await carbon.from("methodOperation").insert(
+ const operationInsert = await carbon.from("methodOperation").insert(
operations.map((operation) => ({
...operation,
makeMethodId,
}))
);
- console.log({ result });
+ if (operationInsert.error) {
+ console.error(
+ "Failed to create method operations:",
+ operationInsert.error
+ );
+ }
}
return { itemId, partId };
@@ -1229,16 +1240,22 @@ export async function getOrCreatePart(
return createPartFromComponent(carbon, args);
}
+let servicePrefix = "Service: ";
+
async function getOrCreateProcess(
carbon: SupabaseClient<Database>,
operation: any,
companyId: string,
createdBy: string
) {
+ let operationName = operation.name;
+ if (operation.name?.startsWith(servicePrefix)) {
+ operationName = operation.name.substring(servicePrefix.length);
+ }
const process = await carbon
.from("process")
.select("id, processType")
- .eq("name", operation.name)
+ .eq("name", operationName)
.eq("companyId", companyId)
.single();
if (process.data) {
@@ -1248,7 +1265,7 @@ async function getOrCreateProcess(
const processInsert = await carbon
.from("process")
.insert({
- name: operation.name,
+ name: operationName,
processType: operation.is_outside_service === true ? "Outside" : "Inside",
companyId,
createdBy,
diff --git a/scripts/paperless-test.ts b/scripts/paperless-test.ts
index 0a6c41868a..a007ddc5be 100644
--- a/scripts/paperless-test.ts
+++ b/scripts/paperless-test.ts
@@ -13,7 +13,7 @@ import {
insertOrderLines,
} from "../packages/integrations/src/paperless-parts/lib/index";
import { OrderSchema } from "../packages/integrations/src/paperless-parts/lib/schemas";
-const orderNumber = 879;
+const orderNumber = 695;
const apiKey = "7fb257095cc635004ecb149c0978c2010f44b99e";
const companyId = "XnwmVKtf9NGwjkco3NoSTu";