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: remove unitCost from supplierProcess

Rob Carrington47897d6211a3
diff --git a/apps/carbon/app/components/Form/SupplierProcess.tsx b/apps/carbon/app/components/Form/SupplierProcess.tsx
index 32dd899b6b..c0848864bc 100644
--- a/apps/carbon/app/components/Form/SupplierProcess.tsx
+++ b/apps/carbon/app/components/Form/SupplierProcess.tsx
@@ -54,7 +54,6 @@ const SupplierProcess = ({
processId,
supplierId: "",
minimumCost: 0,
- unitCost: 0,
leadTime: 0,
}}
/>
diff --git a/apps/carbon/app/modules/purchasing/purchasing.models.ts b/apps/carbon/app/modules/purchasing/purchasing.models.ts
index 77885af620..7eb4437282 100644
--- a/apps/carbon/app/modules/purchasing/purchasing.models.ts
+++ b/apps/carbon/app/modules/purchasing/purchasing.models.ts
@@ -203,7 +203,6 @@ export const supplierProcessValidator = z.object({
supplierId: z.string().min(36, { message: "Supplier is required" }),
processId: z.string().min(1, { message: "Process is required" }),
minimumCost: zfd.numeric(z.number().min(0)),
- unitCost: zfd.numeric(z.number().min(0)),
leadTime: zfd.numeric(z.number().min(0)),
});
diff --git a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierProcessForm.tsx b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierProcessForm.tsx
index f9ddc4aeee..066c4eb23b 100644
--- a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierProcessForm.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierProcessForm.tsx
@@ -124,16 +124,10 @@ const SupplierProcessForm = ({
minValue={0}
/>
<Number
- name="unitCost"
- label="Unit Cost"
- formatOptions={{
- style: "currency",
- currency: baseCurrency,
- maximumFractionDigits: 4,
- }}
+ name="leadTime"
+ label="Standard Lead Time"
minValue={0}
/>
- <Number name="leadTime" label="Lead Time" minValue={0} />
<CustomFormFields table="supplierProcess" />
</VStack>
diff --git a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierProcesses.tsx b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierProcesses.tsx
index c28e4dfbff..694c98765d 100644
--- a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierProcesses.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierProcesses.tsx
@@ -120,11 +120,6 @@ const SupplierProccesses = ({ processes }: SupplierProccessesProps) => {
header: "Minimum Cost",
cell: ({ row }) => formatter.format(row.original.minimumCost ?? 0),
},
- {
- accessorKey: "unitCost",
- header: "Unit Cost",
- cell: ({ row }) => formatter.format(row.original.unitCost ?? 0),
- },
{
accessorKey: "leadTime",
header: "Lead Time",
@@ -143,13 +138,6 @@ const SupplierProccesses = ({ processes }: SupplierProccessesProps) => {
maximumFractionDigits: 4,
},
}),
- unitCost: EditableNumber(onCellEdit, {
- formatOptions: {
- style: "currency",
- currency: baseCurrency,
- maximumFractionDigits: 4,
- },
- }),
leadTime: EditableNumber(onCellEdit),
}),
[onCellEdit, baseCurrency]
diff --git a/apps/carbon/app/modules/resources/ui/Processes/ProcessForm.tsx b/apps/carbon/app/modules/resources/ui/Processes/ProcessForm.tsx
index 0f044e0deb..b0c5c365ff 100644
--- a/apps/carbon/app/modules/resources/ui/Processes/ProcessForm.tsx
+++ b/apps/carbon/app/modules/resources/ui/Processes/ProcessForm.tsx
@@ -230,7 +230,6 @@ function SupplierProcesses({ processId }: { processId?: string }) {
processId: processId,
supplierId: "",
minimumCost: 0,
- unitCost: 0,
leadTime: 0,
}}
/>
diff --git a/apps/carbon/app/routes/x+/supplier+/$supplierId.processes.$id.tsx b/apps/carbon/app/routes/x+/supplier+/$supplierId.processes.$id.tsx
index dbd2ab42c9..4632a83e5c 100644
--- a/apps/carbon/app/routes/x+/supplier+/$supplierId.processes.$id.tsx
+++ b/apps/carbon/app/routes/x+/supplier+/$supplierId.processes.$id.tsx
@@ -75,7 +75,6 @@ export default function SupplierProcessRoute() {
supplierId: process.supplierId ?? "",
processId: process.processId ?? "",
minimumCost: process.minimumCost ?? 0,
- unitCost: process.unitCost ?? 0,
leadTime: process.leadTime ?? 0,
};
diff --git a/apps/carbon/app/routes/x+/supplier+/$supplierId.processes.new.tsx b/apps/carbon/app/routes/x+/supplier+/$supplierId.processes.new.tsx
index a37166562e..1cef1852e4 100644
--- a/apps/carbon/app/routes/x+/supplier+/$supplierId.processes.new.tsx
+++ b/apps/carbon/app/routes/x+/supplier+/$supplierId.processes.new.tsx
@@ -67,7 +67,6 @@ export default function NewSupplierProcessRoute() {
supplierId: supplierId,
processId: "",
minimumCost: 0,
- unitCost: 0,
leadTime: 0,
};
diff --git a/packages/database/src/swagger-docs-schema.ts b/packages/database/src/swagger-docs-schema.ts
index 3bcab5cccb..dd5546c18d 100644
--- a/packages/database/src/swagger-docs-schema.ts
+++ b/packages/database/src/swagger-docs-schema.ts
@@ -11559,9 +11559,6 @@ export default {
{
$ref: "#/parameters/rowFilter.supplierProcesses.minimumCost",
},
- {
- $ref: "#/parameters/rowFilter.supplierProcesses.unitCost",
- },
{
$ref: "#/parameters/rowFilter.supplierProcesses.leadTime",
},
@@ -33006,9 +33003,6 @@ export default {
{
$ref: "#/parameters/rowFilter.supplierProcess.minimumCost",
},
- {
- $ref: "#/parameters/rowFilter.supplierProcess.unitCost",
- },
{
$ref: "#/parameters/rowFilter.supplierProcess.leadTime",
},
@@ -33101,9 +33095,6 @@ export default {
{
$ref: "#/parameters/rowFilter.supplierProcess.minimumCost",
},
- {
- $ref: "#/parameters/rowFilter.supplierProcess.unitCost",
- },
{
$ref: "#/parameters/rowFilter.supplierProcess.leadTime",
},
@@ -33150,9 +33141,6 @@ export default {
{
$ref: "#/parameters/rowFilter.supplierProcess.minimumCost",
},
- {
- $ref: "#/parameters/rowFilter.supplierProcess.unitCost",
- },
{
$ref: "#/parameters/rowFilter.supplierProcess.leadTime",
},
@@ -42450,10 +42438,6 @@ export default {
format: "numeric",
type: "number",
},
- unitCost: {
- format: "numeric",
- type: "number",
- },
leadTime: {
format: "numeric",
type: "number",
@@ -52529,7 +52513,6 @@ export default {
"supplierId",
"processId",
"minimumCost",
- "unitCost",
"leadTime",
"companyId",
"createdBy",
@@ -52559,11 +52542,6 @@ export default {
format: "numeric",
type: "number",
},
- unitCost: {
- default: 0,
- format: "numeric",
- type: "number",
- },
leadTime: {
default: 0,
format: "numeric",
@@ -60317,13 +60295,6 @@ export default {
in: "query",
type: "string",
},
- "rowFilter.supplierProcesses.unitCost": {
- name: "unitCost",
- required: false,
- format: "numeric",
- in: "query",
- type: "string",
- },
"rowFilter.supplierProcesses.leadTime": {
name: "leadTime",
required: false,
@@ -73569,13 +73540,6 @@ export default {
in: "query",
type: "string",
},
- "rowFilter.supplierProcess.unitCost": {
- name: "unitCost",
- required: false,
- format: "numeric",
- in: "query",
- type: "string",
- },
"rowFilter.supplierProcess.leadTime": {
name: "leadTime",
required: false,
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 698fee377d..da334a06c1 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -20152,7 +20152,6 @@ export type Database = {
minimumCost: number
processId: string
supplierId: string
- unitCost: number
updatedAt: string | null
updatedBy: string | null
}
@@ -20166,7 +20165,6 @@ export type Database = {
minimumCost?: number
processId: string
supplierId: string
- unitCost?: number
updatedAt?: string | null
updatedBy?: string | null
}
@@ -20180,7 +20178,6 @@ export type Database = {
minimumCost?: number
processId?: string
supplierId?: string
- unitCost?: number
updatedAt?: string | null
updatedBy?: string | null
}
@@ -25058,14 +25055,14 @@ export type Database = {
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["supplierLocationId"]
+ columns: ["id"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["id"]
+ columns: ["supplierLocationId"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
@@ -25934,14 +25931,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["supplierCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["supplierCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
@@ -27712,14 +27709,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["paymentCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["paymentCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
@@ -28800,7 +28797,6 @@ export type Database = {
processId: string | null
processName: string | null
supplierId: string | null
- unitCost: number | null
updatedAt: string | null
updatedBy: string | null
}
diff --git a/packages/database/supabase/functions/lib/methods.ts b/packages/database/supabase/functions/lib/methods.ts
index 202c4af1cd..f68c5157d5 100644
--- a/packages/database/supabase/functions/lib/methods.ts
+++ b/packages/database/supabase/functions/lib/methods.ts
@@ -245,13 +245,11 @@ export const getRatesFromSupplierProcesses =
supplierProcessId: string | null
): {
operationMinimumCost: number;
- operationUnitCost: number;
operationLeadTime: number;
} => {
if (!processes) {
return {
operationMinimumCost: 0,
- operationUnitCost: 0,
operationLeadTime: 0,
};
}
@@ -264,7 +262,6 @@ export const getRatesFromSupplierProcesses =
if (supplierProcess) {
return {
operationMinimumCost: supplierProcess.minimumCost,
- operationUnitCost: supplierProcess.unitCost,
operationLeadTime: supplierProcess.leadTime,
};
}
@@ -277,10 +274,6 @@ export const getRatesFromSupplierProcesses =
relatedProcesses.reduce((acc, process) => {
return (acc += process.minimumCost ?? 0);
}, 0) / relatedProcesses.length;
- const operationUnitCost =
- relatedProcesses.reduce((acc, process) => {
- return (acc += process.unitCost ?? 0);
- }, 0) / relatedProcesses.length;
const operationLeadTime =
relatedProcesses.reduce((acc, process) => {
return (acc += process.leadTime ?? 0);
@@ -288,14 +281,12 @@ export const getRatesFromSupplierProcesses =
return {
operationMinimumCost,
- operationUnitCost,
operationLeadTime,
};
}
return {
operationMinimumCost: 0,
- operationUnitCost: 0,
operationLeadTime: 0,
};
};
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 698fee377d..da334a06c1 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -20152,7 +20152,6 @@ export type Database = {
minimumCost: number
processId: string
supplierId: string
- unitCost: number
updatedAt: string | null
updatedBy: string | null
}
@@ -20166,7 +20165,6 @@ export type Database = {
minimumCost?: number
processId: string
supplierId: string
- unitCost?: number
updatedAt?: string | null
updatedBy?: string | null
}
@@ -20180,7 +20178,6 @@ export type Database = {
minimumCost?: number
processId?: string
supplierId?: string
- unitCost?: number
updatedAt?: string | null
updatedBy?: string | null
}
@@ -25058,14 +25055,14 @@ export type Database = {
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["supplierLocationId"]
+ columns: ["id"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["id"]
+ columns: ["supplierLocationId"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
@@ -25934,14 +25931,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["supplierCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["supplierCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
@@ -27712,14 +27709,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["paymentCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["paymentCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
@@ -28800,7 +28797,6 @@ export type Database = {
processId: string | null
processName: string | null
supplierId: string | null
- unitCost: number | null
updatedAt: string | null
updatedBy: string | null
}
diff --git a/packages/database/supabase/migrations/20241115011318_remove-supplier-process-unit-cost.sql b/packages/database/supabase/migrations/20241115011318_remove-supplier-process-unit-cost.sql
new file mode 100644
index 0000000000..ddea52c4ce
--- /dev/null
+++ b/packages/database/supabase/migrations/20241115011318_remove-supplier-process-unit-cost.sql
@@ -0,0 +1,10 @@
+DROP VIEW "supplierProcesses";
+
+ALTER TABLE "supplierProcess" DROP COLUMN "unitCost";
+
+CREATE VIEW "supplierProcesses" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ sp.*,
+ p.name as "processName"
+ FROM "supplierProcess" sp
+ INNER JOIN "process" p ON sp."processId" = p.id;
\ No newline at end of file