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.

refactor: make paperless validators more forgiving

Brad Barbinbd6f525ccd1c
diff --git a/apps/erp/app/components/Table/Table.tsx b/apps/erp/app/components/Table/Table.tsx
index 6dc3d45f5c..0d59df8d4b 100644
--- a/apps/erp/app/components/Table/Table.tsx
+++ b/apps/erp/app/components/Table/Table.tsx
@@ -119,6 +119,13 @@ const Table = <T extends object>({
setInternalData(data);
}, [data]);
+ /* Clear row selection when data changes */
+ useEffect(() => {
+ if (withSelectableRows) {
+ setRowSelection({});
+ }
+ }, [data.length, withSelectableRows]);
+
/* Selectable Rows */
const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
diff --git a/packages/integrations/src/paperless-parts/lib/schemas.ts b/packages/integrations/src/paperless-parts/lib/schemas.ts
index de27973678..71111bcc39 100644
--- a/packages/integrations/src/paperless-parts/lib/schemas.ts
+++ b/packages/integrations/src/paperless-parts/lib/schemas.ts
@@ -11,8 +11,8 @@ export const AddressSchema = z.object({
city: z.string().optional(),
country: z.string().optional(),
facility_name: z.string().nullable().optional(),
- phone: z.string().optional(),
- phone_ext: z.string().optional(),
+ phone: z.string().optional().nullable(),
+ phone_ext: z.string().optional().nullable(),
postal_code: z.string().optional(),
state: z.string().optional(),
});
@@ -44,8 +44,8 @@ export const ContactSchema = z.object({
id: z.number().optional(),
last_name: z.string().optional(),
notes: z.string().optional(),
- phone: z.string().optional(),
- phone_ext: z.string().optional(),
+ phone: z.string().optional().nullable(),
+ phone_ext: z.string().optional().nullable(),
});
// Company schema for customer
@@ -55,8 +55,8 @@ export const CompanySchema = z.object({
id: z.number().nullable().optional(),
metrics: AccountMetricsSchema.optional(),
notes: z.string().nullable().optional(),
- phone: z.string().optional(),
- phone_ext: z.string().optional(),
+ phone: z.string().optional().nullable(),
+ phone_ext: z.string().optional().nullable(),
});
// Customer schema
@@ -67,8 +67,8 @@ export const CustomerSchema = z.object({
first_name: z.string().optional(),
last_name: z.string().optional(),
notes: z.string().optional(),
- phone: z.string().optional(),
- phone_ext: z.string().optional(),
+ phone: z.string().optional().nullable(),
+ phone_ext: z.string().optional().nullable(),
});
// Sales person schema
@@ -85,8 +85,8 @@ export const FacilitySchema = z.object({
name: z.string().optional(),
address: AddressSchema.optional(),
is_default: z.boolean().optional(),
- phone: z.string().optional(),
- phone_ext: z.string().optional(),
+ phone: z.string().optional().nullable(),
+ phone_ext: z.string().optional().nullable(),
url: z.string().optional(),
});
@@ -106,13 +106,13 @@ export const ComponentSchema = z.object({
obtain_method: z.string().optional(),
parent_ids: z.array(z.number()).optional(),
part_custom_attrs: z.array(z.unknown()).optional(),
- part_name: z.string().optional(),
- part_number: z.string().optional(),
+ part_name: z.string().optional().nullable(),
+ part_number: z.string().optional().nullable(),
part_url: z.string().url().optional(),
part_uuid: z.string().uuid().optional(),
process: z.unknown().nullable().optional(),
purchased_component: z.unknown().nullable().optional(),
- revision: z.string().optional(),
+ revision: z.string().optional().nullable(),
shop_operations: z.array(z.unknown()).optional(),
supporting_files: z.array(z.unknown()).optional(),
thumbnail_url: z.string().url().optional(),
@@ -187,7 +187,7 @@ export const OrderSchema = z.object({
contact: ContactSchema.optional(),
customer: CustomerSchema.optional(),
deliver_by: z.string().nullable().optional(),
- estimator: SalesPersonSchema.optional(),
+ estimator: SalesPersonSchema.optional().nullable(),
send_from_facility: FacilitySchema.optional(),
erp_code: z.string().nullable().optional(),
number: z.number().optional(),
@@ -198,8 +198,8 @@ export const OrderSchema = z.object({
quote_erp_code: z.string().nullable().optional(),
quote_number: z.number().optional(),
quote_revision_number: z.number().nullable().optional(),
- sales_person: SalesPersonSchema.optional(),
- salesperson: SalesPersonSchema.optional(),
+ sales_person: SalesPersonSchema.optional().nullable(),
+ salesperson: SalesPersonSchema.optional().nullable(),
shipments: ShipmentSchema.optional(),
shipping_info: AddressSchema.optional(),
shipping_option: ShippingOptionSchema.optional(),
@@ -214,7 +214,7 @@ export const OrderSchema = z.object({
"cancelled",
])
.optional(),
- quote_rfq_number: z.string().optional(),
+ quote_rfq_number: z.string().nullable().optional(),
});
// Export the inferred type
diff --git a/packages/integrations/src/paperless-parts/lib/utils.ts b/packages/integrations/src/paperless-parts/lib/utils.ts
index 2f168fbddd..6e3c06d16c 100644
--- a/packages/integrations/src/paperless-parts/lib/utils.ts
+++ b/packages/integrations/src/paperless-parts/lib/utils.ts
@@ -1,4 +1,5 @@
import type { Database } from "@carbon/database";
+import { textToTiptap } from "@carbon/utils";
import type { SupabaseClient } from "@supabase/supabase-js";
import { nanoid } from "nanoid";
import type z from "zod";
@@ -682,9 +683,11 @@ export async function createPartFromComponent(
): Promise<{ itemId: string; partId: string }> {
const { companyId, createdBy, component } = args;
+ console.log(component);
+
// Generate a readable ID for the part
const partId =
- component.part_number || component.part_uuid || `PP-${component.id}`;
+ component.part_number || component.part_name || `PP-${component.id}`;
const revision = component.revision || "0";
const name =
component.part_name || component.part_number || `Part ${component.id}`;
@@ -746,7 +749,7 @@ export async function createPartFromComponent(
}
// Create the part record
- const partInsert = await carbon.from("part").insert({
+ const partInsert = await carbon.from("part").upsert({
id: partId,
companyId,
createdBy,
@@ -869,9 +872,16 @@ export async function insertOrderLines(
addOnCost,
companyId,
createdBy,
+ quantitySent: component.deliver_quantity,
promisedDate: orderItem.ships_on
? new Date(orderItem.ships_on).toISOString()
: null,
+ internalNotes: orderItem.private_notes
+ ? textToTiptap(orderItem.private_notes)
+ : null,
+ externalNotes: orderItem.public_notes
+ ? textToTiptap(orderItem.public_notes)
+ : null,
};
linesToInsert.push(salesOrderLine);
diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts
index fc4e4853b6..ff0b059510 100644
--- a/packages/utils/src/index.ts
+++ b/packages/utils/src/index.ts
@@ -12,5 +12,6 @@ export * from "./labels";
export * from "./math";
export * from "./ssr";
export * from "./themes";
+export * from "./tiptap";
export * from "./types";
export * from "./url";
diff --git a/packages/utils/src/tiptap.ts b/packages/utils/src/tiptap.ts
new file mode 100644
index 0000000000..c3b9deb6d1
--- /dev/null
+++ b/packages/utils/src/tiptap.ts
@@ -0,0 +1,8 @@
+export const textToTiptap = (text: string) => {
+ const lines = text.split("\n");
+ const content = lines.map((line) => ({
+ type: "paragraph",
+ content: [{ type: "text", text: line }],
+ }));
+ return { type: "doc", content };
+};
diff --git a/scripts/paperless-test.ts b/scripts/paperless-test.ts
index 22093b8ade..d9140d8e66 100644
--- a/scripts/paperless-test.ts
+++ b/scripts/paperless-test.ts
@@ -13,8 +13,8 @@ import {
insertOrderLines,
} from "../packages/integrations/src/paperless-parts/lib/index";
import { OrderSchema } from "../packages/integrations/src/paperless-parts/lib/schemas";
-const orderNumber = 5;
-const apiKey = "3c82924535cc39a51cbb59c1350754f92fb65742";
+const orderNumber = 884;
+const apiKey = "7fb257095cc635004ecb149c0978c2010f44b99e";
const companyId = "SanLTzPk93kscfQ7oCnSSu";
dotenv.config();