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: update quote line status enum in database

Rob Carrington58ee188e5b88
diff --git a/apps/carbon/app/modules/sales/sales.models.ts b/apps/carbon/app/modules/sales/sales.models.ts
index 685fa7608e..71656fc7fc 100644
--- a/apps/carbon/app/modules/sales/sales.models.ts
+++ b/apps/carbon/app/modules/sales/sales.models.ts
@@ -83,9 +83,10 @@ export const getMethodValidator = z.object({
});
export const quoteLineStatusType = [
- "Draft",
+ "Not Started",
"In Progress",
"Complete",
+ "No Quote",
] as const;
export const quoteStatusType = [
diff --git a/packages/database/src/swagger-docs-schema.ts b/packages/database/src/swagger-docs-schema.ts
index f9a3f6204c..1c2a77df7b 100644
--- a/packages/database/src/swagger-docs-schema.ts
+++ b/packages/database/src/swagger-docs-schema.ts
@@ -13047,6 +13047,9 @@ export default {
{
$ref: "#/parameters/rowFilter.quoteLines.additionalCharges",
},
+ {
+ $ref: "#/parameters/rowFilter.quoteLines.locationId",
+ },
{
$ref: "#/parameters/rowFilter.quoteLines.modelId",
},
@@ -41142,7 +41145,7 @@ export default {
type: "integer",
},
status: {
- enum: ["Draft", "In Progress", "Complete"],
+ enum: ["Not Started", "In Progress", "Complete", "No Quote"],
format: 'public."quoteLineStatus"',
type: "string",
},
@@ -41229,6 +41232,12 @@ export default {
additionalCharges: {
format: "jsonb",
},
+ locationId: {
+ description:
+ "Note:\nThis is a Foreign Key to `location.id`.<fk table='location' column='id'/>",
+ format: "text",
+ type: "string",
+ },
modelId: {
format: "text",
type: "string",
@@ -49129,8 +49138,8 @@ export default {
type: "integer",
},
status: {
- default: "Draft",
- enum: ["Draft", "In Progress", "Complete"],
+ default: "Not Started",
+ enum: ["Not Started", "In Progress", "Complete", "No Quote"],
format: 'public."quoteLineStatus"',
type: "string",
},
@@ -58329,6 +58338,13 @@ export default {
in: "query",
type: "string",
},
+ "rowFilter.quoteLines.locationId": {
+ name: "locationId",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
"rowFilter.quoteLines.modelId": {
name: "modelId",
required: false,
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index b7cb88e759..5797d027b6 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -24388,14 +24388,14 @@ export type Database = {
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["id"]
+ columns: ["supplierLocationId"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["supplierLocationId"]
+ columns: ["id"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
@@ -25592,6 +25592,7 @@ export type Database = {
itemId: string | null
itemReadableId: string | null
itemType: string | null
+ locationId: string | null
methodType: Database["public"]["Enums"]["methodType"] | null
modelId: string | null
modelName: string | null
@@ -25715,6 +25716,27 @@ export type Database = {
referencedRelation: "item"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "quoteLine_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "location"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteLine_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
+ {
+ foreignKeyName: "quoteLine_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "salesOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "quoteLine_quoteId_fkey"
columns: ["quoteId"]
@@ -26987,14 +27009,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["paymentCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["id"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["paymentCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["id"]
@@ -29505,7 +29527,7 @@ export type Database = {
| "Reject"
| "Request Approval"
purchaseOrderType: "Purchase" | "Return"
- quoteLineStatus: "Draft" | "In Progress" | "Complete"
+ quoteLineStatus: "Not Started" | "In Progress" | "Complete" | "No Quote"
quoteStatus:
| "Draft"
| "Sent"
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index b7cb88e759..5797d027b6 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -24388,14 +24388,14 @@ export type Database = {
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["id"]
+ columns: ["supplierLocationId"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["supplierLocationId"]
+ columns: ["id"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
@@ -25592,6 +25592,7 @@ export type Database = {
itemId: string | null
itemReadableId: string | null
itemType: string | null
+ locationId: string | null
methodType: Database["public"]["Enums"]["methodType"] | null
modelId: string | null
modelName: string | null
@@ -25715,6 +25716,27 @@ export type Database = {
referencedRelation: "item"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "quoteLine_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "location"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "quoteLine_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
+ {
+ foreignKeyName: "quoteLine_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "salesOrders"
+ referencedColumns: ["locationId"]
+ },
{
foreignKeyName: "quoteLine_quoteId_fkey"
columns: ["quoteId"]
@@ -26987,14 +27009,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["paymentCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["id"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["paymentCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["id"]
@@ -29505,7 +29527,7 @@ export type Database = {
| "Reject"
| "Request Approval"
purchaseOrderType: "Purchase" | "Return"
- quoteLineStatus: "Draft" | "In Progress" | "Complete"
+ quoteLineStatus: "Not Started" | "In Progress" | "Complete" | "No Quote"
quoteStatus:
| "Draft"
| "Sent"
diff --git a/packages/database/supabase/migrations/20240925203749_update-quote-line-status-enum.sql b/packages/database/supabase/migrations/20240925203749_update-quote-line-status-enum.sql
new file mode 100644
index 0000000000..99195669ea
--- /dev/null
+++ b/packages/database/supabase/migrations/20240925203749_update-quote-line-status-enum.sql
@@ -0,0 +1,86 @@
+-- Begin transaction
+BEGIN;
+
+-- Drop the view that depends on the quoteLine table
+DROP VIEW IF EXISTS "quoteLines";
+DROP VIEW IF EXISTS "quotes";
+
+-- Create a new enum type for the updated quote line status
+DROP TYPE IF EXISTS "newQuoteLineStatus";
+CREATE TYPE "newQuoteLineStatus" AS ENUM (
+ 'Not Started',
+ 'In Progress',
+ 'Complete',
+ 'No Quote'
+);
+
+-- Alter the quoteLine table to change status column to TEXT
+ALTER TABLE "quoteLine"
+ ALTER COLUMN "status" TYPE TEXT,
+ ALTER COLUMN "status" SET DEFAULT NULL;
+
+-- Drop the old enum type
+DROP TYPE IF EXISTS "quoteLineStatus";
+
+-- Update the status values in the quoteLine table
+UPDATE "quoteLine"
+SET "status" = CASE
+ WHEN "status" = 'Draft' THEN 'Not Started'
+ ELSE "status"
+END;
+
+-- Alter the quoteLine table to use the new enum type
+ALTER TABLE "quoteLine"
+ ALTER COLUMN "status" TYPE "newQuoteLineStatus" USING "status"::"newQuoteLineStatus";
+
+-- Rename the new enum type to the original name
+ALTER TYPE "newQuoteLineStatus" RENAME TO "quoteLineStatus";
+
+-- Set the default value for the status column
+ALTER TABLE "quoteLine"
+ ALTER COLUMN "status" SET DEFAULT 'Not Started';
+
+-- Recreate the quoteLines view
+CREATE OR REPLACE VIEW "quoteLines" WITH(SECURITY_INVOKER=true) AS (
+ SELECT
+ ql.*,
+ COALESCE(mu.id, imu.id) as "modelId",
+ COALESCE(mu."autodeskUrn", imu."autodeskUrn") as "autodeskUrn",
+ COALESCE(mu."modelPath", imu."modelPath") as "modelPath",
+ COALESCE(mu."thumbnailPath", imu."thumbnailPath") as "thumbnailPath",
+ COALESCE(mu."name", imu."name") as "modelName",
+ COALESCE(mu."size", imu."size") as "modelSize",
+ ic."unitCost" as "unitCost"
+ FROM "quoteLine" ql
+ LEFT JOIN "modelUpload" mu ON ql."modelUploadId" = mu."id"
+ INNER JOIN "item" i ON i.id = ql."itemId"
+ LEFT JOIN "itemCost" ic ON ic."itemId" = i.id
+ LEFT JOIN "modelUpload" imu ON imu.id = i."modelUploadId"
+);
+
+-- Recreate the quotes view if it exists
+CREATE OR REPLACE VIEW "quotes" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ q.*,
+ l."name" AS "locationName",
+ ql."lines",
+ ql."completedLines",
+ EXISTS(SELECT 1 FROM "quoteFavorite" pf WHERE pf."quoteId" = q.id AND pf."userId" = auth.uid()::text) AS favorite,
+ opp."salesRfqId",
+ opp."salesOrderId"
+ FROM "quote" q
+ LEFT JOIN (
+ SELECT
+ "quoteId",
+ COUNT("id") FILTER (WHERE "status" != 'No Quote') AS "lines",
+ COUNT("id") FILTER (WHERE "status" = 'Complete') AS "completedLines"
+ FROM "quoteLine"
+ GROUP BY "quoteId"
+ ) ql ON ql."quoteId" = q.id
+ LEFT JOIN "location" l
+ ON l.id = q."locationId"
+ LEFT JOIN "opportunity" opp
+ ON opp."quoteId" = q.id;
+
+-- Commit the transaction
+COMMIT;
\ No newline at end of file