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: convert readableId to readableIdWithRevision

Brad Barbina3064168a156
diff --git a/apps/erp/app/modules/items/items.service.ts b/apps/erp/app/modules/items/items.service.ts
index 1d554035a8..20623abf06 100644
--- a/apps/erp/app/modules/items/items.service.ts
+++ b/apps/erp/app/modules/items/items.service.ts
@@ -284,7 +284,7 @@ export async function getConsumablesList(
) {
let query = client
.from("item")
- .select("id, name, readableId")
+ .select("id, name, readableIdWithRevision")
.eq("type", "Consumable")
.eq("companyId", companyId)
.eq("active", true);
@@ -302,7 +302,7 @@ export async function getItemCost(
) {
return client
.from("itemCost")
- .select("*, ...item(readableId)")
+ .select("*, ...item(readableIdWithRevision)")
.eq("itemId", itemId)
.eq("companyId", companyId)
.single();
@@ -510,7 +510,7 @@ export async function getMaterialUsedIn(
client
.from("methodMaterial")
.select(
- "id, methodType, ...makeMethod!makeMethodId(...item(documentReadableId:readableId, documentId:id, itemType:type))"
+ "id, methodType, ...makeMethod!makeMethodId(...item(documentReadableId:readableIdWithRevision, documentId:id, itemType:type))"
)
.eq("itemId", itemId)
.eq("companyId", companyId),
@@ -596,7 +596,7 @@ export async function getPartUsedIn(
client
.from("methodMaterial")
.select(
- "id, methodType, ...makeMethod!makeMethodId(...item(documentReadableId:readableId, documentId:id, itemType:type))"
+ "id, methodType, ...makeMethod!makeMethodId(...item(documentReadableId:readableIdWithRevision, documentId:id, itemType:type))"
)
.eq("itemId", itemId)
.eq("companyId", companyId),
@@ -736,7 +736,7 @@ export async function getMaterialsList(
) {
let query = client
.from("item")
- .select("id, name, readableId")
+ .select("id, name, readableIdWithRevision")
.eq("type", "Material")
.or(`companyId.eq.${companyId},companyId.is.null`)
.eq("active", true);
@@ -849,7 +849,7 @@ export async function getMethodMaterials(
let query = client
.from("methodMaterial")
.select(
- "*, item(name, readableId), makeMethod!makeMethodId(item(id, type, name, readableId))",
+ "*, item(name, readableIdWithRevision), makeMethod!makeMethodId(item(id, type, name, readableIdWithRevision))",
{
count: "exact",
}
@@ -885,9 +885,12 @@ export async function getMethodOperations(
) {
let query = client
.from("methodOperation")
- .select("*, makeMethod!makeMethodId(item(id, type, name, readableId))", {
- count: "exact",
- })
+ .select(
+ "*, makeMethod!makeMethodId(item(id, type, name, readableIdWithRevision))",
+ {
+ count: "exact",
+ }
+ )
.eq("companyId", companyId);
if (args?.search) {
@@ -1037,7 +1040,7 @@ export async function getPartsList(
) {
let query = client
.from("item")
- .select("id, name, readableId")
+ .select("id, name, readableIdWithRevision")
.eq("type", "Part")
.eq("companyId", companyId)
.eq("active", true);
@@ -1214,7 +1217,7 @@ export async function getToolsList(
) {
let query = client
.from("item")
- .select("id, name, readableId")
+ .select("id, name, readableIdWithRevision")
.eq("type", "Tool")
.eq("companyId", companyId)
.eq("active", true);
@@ -2089,7 +2092,13 @@ export async function upsertMaterial(
if (costUpdate.error) return costUpdate;
- return materialInsert;
+ const newMaterial = await client
+ .from("materials")
+ .select("*")
+ .eq("readableId", material.id)
+ .single();
+
+ return newMaterial;
}
const itemUpdate = {
@@ -2255,7 +2264,13 @@ export async function upsertService(
if (costUpdate.error) return costUpdate;
- return serviceInsert;
+ const newService = await client
+ .from("service")
+ .select("*")
+ .eq("readableId", service.id)
+ .single();
+
+ return newService;
}
const itemUpdate = {
id: service.id,
diff --git a/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx b/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx
index d5c0474531..1ef8e52d90 100644
--- a/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx
+++ b/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx
@@ -2683,7 +2683,9 @@ function ToolsListItem({
<LuHammer className="size-4" />
</div>
<VStack spacing={0}>
- <span className="text-sm font-medium">{tool.readableId}</span>
+ <span className="text-sm font-medium">
+ {tool.readableIdWithRevision}
+ </span>
<span className="text-xs text-muted-foreground">
{tool.name}
</span>
@@ -2727,8 +2729,8 @@ function ToolsListItem({
<ConfirmDelete
action={path.to.deleteMethodOperationTool(id)}
isOpen={deleteModalDisclosure.isOpen}
- name={tool.readableId}
- text={`Are you sure you want to delete ${tool.readableId} from this operation? This cannot be undone.`}
+ name={tool.readableIdWithRevision}
+ text={`Are you sure you want to delete ${tool.readableIdWithRevision} from this operation? This cannot be undone.`}
onCancel={() => {
deleteModalDisclosure.onClose();
}}
diff --git a/apps/erp/app/modules/items/ui/Methods/MethodMaterialsTable.tsx b/apps/erp/app/modules/items/ui/Methods/MethodMaterialsTable.tsx
index 2cb87026b5..44d08838e0 100644
--- a/apps/erp/app/modules/items/ui/Methods/MethodMaterialsTable.tsx
+++ b/apps/erp/app/modules/items/ui/Methods/MethodMaterialsTable.tsx
@@ -22,7 +22,7 @@ const MethodMaterialsTable = memo(
const columns = useMemo<ColumnDef<MethodMaterial>[]>(() => {
return [
{
- accessorKey: "makeMethod.item.readableId",
+ accessorKey: "makeMethod.item.readableIdWithRevision",
header: "Method Id",
cell: ({ row }) => (
<HStack className="py-1">
@@ -36,21 +36,21 @@ const MethodMaterialsTable = memo(
className="max-w-[260px] truncate"
>
{/* @ts-ignore */}
- {row.original.makeMethod?.item?.readableId}
+ {row.original.makeMethod?.item?.readableIdWithRevision}
</Hyperlink>
</HStack>
),
},
{
- accessorKey: "itemReadableId",
+ accessorKey: "itemReadableIdWithRevision",
header: "Material ID",
cell: (item) => item.getValue(),
meta: {
filter: {
type: "static",
options: items?.map((item) => ({
- value: item.readableId,
- label: item.readableId,
+ value: item.readableIdWithRevision,
+ label: item.readableIdWithRevision,
})),
},
},
diff --git a/apps/erp/app/modules/items/ui/Methods/MethodOperationsTable.tsx b/apps/erp/app/modules/items/ui/Methods/MethodOperationsTable.tsx
index a07db39372..aca87fcaa3 100644
--- a/apps/erp/app/modules/items/ui/Methods/MethodOperationsTable.tsx
+++ b/apps/erp/app/modules/items/ui/Methods/MethodOperationsTable.tsx
@@ -39,18 +39,18 @@ const MethodOperationsTable = memo(
),
},
{
- accessorKey: "makeMethod.item.readableId",
+ accessorKey: "makeMethod.item.readableIdWithRevision",
header: "Item ID",
cell: ({ row }) => {
// @ts-ignore
- return row.original.makeMethod?.item?.readableId;
+ return row.original.makeMethod?.item?.readableIdWithRevision;
},
meta: {
filter: {
type: "static",
options: items?.map((item) => ({
- value: item.readableId,
- label: item.readableId,
+ value: item.readableIdWithRevision,
+ label: item.readableIdWithRevision,
})),
},
},
diff --git a/apps/erp/app/modules/production/production.service.ts b/apps/erp/app/modules/production/production.service.ts
index 4751ebefc8..dbbd179ef5 100644
--- a/apps/erp/app/modules/production/production.service.ts
+++ b/apps/erp/app/modules/production/production.service.ts
@@ -412,9 +412,12 @@ export async function getJobOperations(
) {
let query = client
.from("jobOperation")
- .select("*, jobMakeMethod(parentMaterialId, item(readableId))", {
- count: "exact",
- })
+ .select(
+ "*, jobMakeMethod(parentMaterialId, item(readableIdWithRevision))",
+ {
+ count: "exact",
+ }
+ )
.eq("jobId", jobId);
if (args?.search) {
@@ -584,7 +587,7 @@ export async function getProductionEvents(
let query = client
.from("productionEvent")
.select(
- "*, jobOperation(description, jobMakeMethod(parentMaterialId, item(readableId)))",
+ "*, jobOperation(description, jobMakeMethod(parentMaterialId, item(readableIdWithRevision)))",
{
count: "exact",
}
@@ -645,7 +648,7 @@ export async function getProductionEventsByOperations(
return client
.from("productionEvent")
.select(
- "*, jobOperation(description, jobMakeMethod(parentMaterialId, item(readableId)))"
+ "*, jobOperation(description, jobMakeMethod(parentMaterialId, item(readableIdWithRevision)))"
)
.in("jobOperationId", jobOperationIds)
.order("startTime", { ascending: true });
@@ -670,7 +673,7 @@ export async function getProductionQuantities(
let query = client
.from("productionQuantity")
.select(
- "*, jobOperation(description, jobMakeMethod(parentMaterialId, item(readableId)))",
+ "*, jobOperation(description, jobMakeMethod(parentMaterialId, item(readableIdWithRevision)))",
{
count: "exact",
}
@@ -698,13 +701,13 @@ export async function getProductionDataByOperations(
client
.from("productionQuantity")
.select(
- "*, jobOperation(description, jobMakeMethod(parentMaterialId, item(readableId)))"
+ "*, jobOperation(description, jobMakeMethod(parentMaterialId, item(readableIdWithRevision)))"
)
.in("jobOperationId", jobOperationIds),
client
.from("productionEvent")
.select(
- "*, jobOperation(description, jobMakeMethod(parentMaterialId, item(readableId)))"
+ "*, jobOperation(description, jobMakeMethod(parentMaterialId, item(readableIdWithRevision)))"
)
.in("jobOperationId", jobOperationIds),
client
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx b/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx
index f22dc17b95..e109f8f34d 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx
@@ -2773,7 +2773,9 @@ function ToolsListItem({
<LuHammer className="size-4" />
</div>
<VStack spacing={0}>
- <span className="text-sm font-medium">{tool.readableId}</span>
+ <span className="text-sm font-medium">
+ {tool.readableIdWithRevision}
+ </span>
<span className="text-xs text-muted-foreground">
{tool.name}
</span>
@@ -2817,8 +2819,8 @@ function ToolsListItem({
<ConfirmDelete
action={path.to.deleteJobOperationTool(id)}
isOpen={deleteModalDisclosure.isOpen}
- name={tool.readableId}
- text={`Are you sure you want to delete ${tool.readableId} from this operation? This cannot be undone.`}
+ name={tool.readableIdWithRevision}
+ text={`Are you sure you want to delete ${tool.readableIdWithRevision} from this operation? This cannot be undone.`}
onCancel={() => {
deleteModalDisclosure.onClose();
}}
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobMaterialsTable.tsx b/apps/erp/app/modules/production/ui/Jobs/JobMaterialsTable.tsx
index cb4b06b30d..56756fea3b 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobMaterialsTable.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobMaterialsTable.tsx
@@ -81,8 +81,8 @@ const JobMaterialsTable = memo(({ data, count }: JobMaterialsTableProps) => {
filter: {
type: "static",
options: items.map((item) => ({
- value: item.readableId,
- label: item.readableId,
+ value: item.readableIdWithRevision,
+ label: item.readableIdWithRevision,
})),
},
},
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobOperationsTable.tsx b/apps/erp/app/modules/production/ui/Jobs/JobOperationsTable.tsx
index e935f06a03..7da4ee568c 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobOperationsTable.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobOperationsTable.tsx
@@ -131,7 +131,7 @@ const JobOperationsTable = memo(({ data, count }: JobOperationsTableProps) => {
id: "item",
header: "Item",
cell: ({ row }) => {
- return row.original.jobMakeMethod?.item?.readableId;
+ return row.original.jobMakeMethod?.item?.readableIdWithRevision;
},
meta: {
icon: <AiOutlinePartition />,
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobsTable.tsx b/apps/erp/app/modules/production/ui/Jobs/JobsTable.tsx
index 32c43a7365..4b586298fa 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobsTable.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobsTable.tsx
@@ -110,15 +110,15 @@ const JobsTable = memo(({ data, count, tags }: JobsTableProps) => {
},
},
{
- accessorKey: "itemReadableId",
+ accessorKey: "itemReadableIdWithRevision",
header: "Item",
cell: (item) => item.getValue(),
meta: {
filter: {
type: "static",
options: items?.map((item) => ({
- value: item.readableId,
- label: item.readableId,
+ value: item.readableIdWithRevision,
+ label: item.readableIdWithRevision,
})),
},
icon: <AiOutlinePartition />,
diff --git a/apps/erp/app/modules/production/ui/Jobs/ProductionEventsTable.tsx b/apps/erp/app/modules/production/ui/Jobs/ProductionEventsTable.tsx
index b52ab37255..9643bdc6f1 100644
--- a/apps/erp/app/modules/production/ui/Jobs/ProductionEventsTable.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/ProductionEventsTable.tsx
@@ -56,7 +56,8 @@ const ProductionEventsTable = memo(
id: "item",
header: "Item",
cell: ({ row }) => {
- return row.original.jobOperation?.jobMakeMethod?.item?.readableId;
+ return row.original.jobOperation?.jobMakeMethod?.item
+ ?.readableIdWithRevision;
},
},
{
diff --git a/apps/erp/app/modules/production/ui/Jobs/ProductionQuantitiesTable.tsx b/apps/erp/app/modules/production/ui/Jobs/ProductionQuantitiesTable.tsx
index f40d127180..83b8965805 100644
--- a/apps/erp/app/modules/production/ui/Jobs/ProductionQuantitiesTable.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/ProductionQuantitiesTable.tsx
@@ -53,7 +53,8 @@ const ProductionQuantitiesTable = memo(
id: "item",
header: "Item",
cell: ({ row }) => {
- return row.original.jobOperation?.jobMakeMethod?.item?.readableId;
+ return row.original.jobOperation?.jobMakeMethod?.item
+ ?.readableIdWithRevision;
},
},
{
diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx
index ed851cca66..a166c8d9b2 100644
--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx
+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx
@@ -2395,7 +2395,9 @@ function ToolsListItem({
<LuHammer className="size-4" />
</div>
<VStack spacing={0}>
- <span className="text-sm font-medium">{tool.readableId}</span>
+ <span className="text-sm font-medium">
+ {tool.readableIdWithRevision}
+ </span>
<span className="text-xs text-muted-foreground">
{tool.name}
</span>
@@ -2439,8 +2441,8 @@ function ToolsListItem({
<ConfirmDelete
action={path.to.deleteQuoteOperationTool(id)}
isOpen={deleteModalDisclosure.isOpen}
- name={tool.readableId}
- text={`Are you sure you want to delete ${tool.readableId} from this operation? This cannot be undone.`}
+ name={tool.readableIdWithRevision}
+ text={`Are you sure you want to delete ${tool.readableIdWithRevision} from this operation? This cannot be undone.`}
onCancel={() => {
deleteModalDisclosure.onClose();
}}
diff --git a/apps/erp/app/routes/x+/consumable+/$itemId.costing.tsx b/apps/erp/app/routes/x+/consumable+/$itemId.costing.tsx
index 3713e8477e..005025827e 100644
--- a/apps/erp/app/routes/x+/consumable+/$itemId.costing.tsx
+++ b/apps/erp/app/routes/x+/consumable+/$itemId.costing.tsx
@@ -97,7 +97,7 @@ export default function ConsumableCostingRoute() {
}}
/>
<ItemCostHistoryChart
- readableId={itemCost.readableId}
+ readableId={itemCost.readableIdWithRevision ?? ""}
itemCostHistory={itemCostHistory}
/>
</VStack>
diff --git a/apps/erp/app/routes/x+/material+/$itemId.costing.tsx b/apps/erp/app/routes/x+/material+/$itemId.costing.tsx
index 9322a7b665..632ec8cad4 100644
--- a/apps/erp/app/routes/x+/material+/$itemId.costing.tsx
+++ b/apps/erp/app/routes/x+/material+/$itemId.costing.tsx
@@ -97,7 +97,7 @@ export default function MaterialCostingRoute() {
}}
/>
<ItemCostHistoryChart
- readableId={itemCost.readableId}
+ readableId={itemCost.readableIdWithRevision ?? ""}
itemCostHistory={itemCostHistory}
/>
</VStack>
diff --git a/apps/erp/app/routes/x+/part+/$itemId.costing.tsx b/apps/erp/app/routes/x+/part+/$itemId.costing.tsx
index 7d0c481dfd..e22ef2d548 100644
--- a/apps/erp/app/routes/x+/part+/$itemId.costing.tsx
+++ b/apps/erp/app/routes/x+/part+/$itemId.costing.tsx
@@ -94,7 +94,7 @@ export default function PartCostingRoute() {
}}
/>
<ItemCostHistoryChart
- readableId={itemCost.readableId}
+ readableId={itemCost.readableIdWithRevision ?? ""}
itemCostHistory={itemCostHistory}
/>
</VStack>
diff --git a/apps/erp/app/routes/x+/tool+/$itemId.costing.tsx b/apps/erp/app/routes/x+/tool+/$itemId.costing.tsx
index 00f30194f7..87fdf16162 100644
--- a/apps/erp/app/routes/x+/tool+/$itemId.costing.tsx
+++ b/apps/erp/app/routes/x+/tool+/$itemId.costing.tsx
@@ -94,7 +94,7 @@ export default function ToolCostingRoute() {
}}
/>
<ItemCostHistoryChart
- readableId={itemCost.readableId}
+ readableId={itemCost.readableIdWithRevision ?? ""}
itemCostHistory={itemCostHistory}
/>
</VStack>
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 9da6808d68..60c9e64e51 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -35960,7 +35960,7 @@ export type Database = {
estimatedTime: number | null
id: string | null
itemId: string | null
- itemReadableId: string | null
+ itemReadableIdWithRevision: string | null
itemTrackingType:
| Database["public"]["Enums"]["itemTrackingType"]
| null
@@ -37910,14 +37910,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"]
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 9da6808d68..60c9e64e51 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -35960,7 +35960,7 @@ export type Database = {
estimatedTime: number | null
id: string | null
itemId: string | null
- itemReadableId: string | null
+ itemReadableIdWithRevision: string | null
itemTrackingType:
| Database["public"]["Enums"]["itemTrackingType"]
| null
@@ -37910,14 +37910,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"]
diff --git a/packages/database/supabase/migrations/20250519122022_revisions.sql b/packages/database/supabase/migrations/20250519122022_revisions.sql
index f37b4a05b1..6fab8c8538 100644
--- a/packages/database/supabase/migrations/20250519122022_revisions.sql
+++ b/packages/database/supabase/migrations/20250519122022_revisions.sql
@@ -879,3 +879,46 @@ LEFT JOIN (
GROUP BY "itemId"
) ps ON ps."itemId" = li."id"
LEFT JOIN "unitOfMeasure" uom ON uom.code = li."unitOfMeasureCode" AND uom."companyId" = li."companyId";
+
+DROP VIEW IF EXISTS "jobs";
+CREATE OR REPLACE VIEW "jobs" WITH(SECURITY_INVOKER=true) AS
+WITH job_model AS (
+ SELECT
+ j.id AS job_id,
+ COALESCE(j."modelUploadId", i."modelUploadId") AS model_upload_id
+ FROM "job" j
+ INNER JOIN "item" i ON j."itemId" = i."id"
+)
+SELECT
+ j.*,
+ CASE
+ WHEN j.status = 'Completed' THEN 'Completed'
+ WHEN j."status" = 'Cancelled' THEN 'Cancelled'
+ WHEN j."dueDate" IS NOT NULL AND j."dueDate" < CURRENT_DATE THEN 'Overdue'
+ WHEN j."dueDate" IS NOT NULL AND j."dueDate" = CURRENT_DATE THEN 'Due Today'
+ ELSE j."status"
+ END as "statusWithDueDate",
+ i.name,
+ i."readableIdWithRevision" as "itemReadableIdWithRevision",
+ i.type as "itemType",
+ i.name as "description",
+ i."itemTrackingType",
+ i.active,
+ i."replenishmentSystem",
+ mu.id as "modelId",
+ mu."autodeskUrn",
+ mu."modelPath",
+ CASE
+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"
+ ELSE i."thumbnailPath"
+ END as "thumbnailPath",
+ mu."name" as "modelName",
+ mu."size" as "modelSize",
+ so."salesOrderId" as "salesOrderReadableId",
+ qo."quoteId" as "quoteReadableId"
+FROM "job" j
+INNER JOIN "item" i ON j."itemId" = i."id"
+LEFT JOIN job_model jm ON j.id = jm.job_id
+LEFT JOIN "modelUpload" mu ON mu.id = jm.model_upload_id
+LEFT JOIN "salesOrder" so on j."salesOrderId" = so.id
+LEFT JOIN "quote" qo ON j."quoteId" = qo.id;
\ No newline at end of file