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.

feat: add tables for configurable options

Brad Barbina2e6014ec1c9
diff --git a/apps/carbon/app/modules/items/items.models.ts b/apps/carbon/app/modules/items/items.models.ts
index 1f0b7f3cb0..7d2c2f4f8f 100644
--- a/apps/carbon/app/modules/items/items.models.ts
+++ b/apps/carbon/app/modules/items/items.models.ts
@@ -403,8 +403,8 @@ export const partValidator = itemValidator.merge(
export const partManufacturingValidator = z.object({
itemId: z.string().min(1, { message: "Item ID is required" }),
- manufacturingBlocked: zfd.checkbox(),
- // requiresConfiguration: zfd.checkbox(),
+ // manufacturingBlocked: zfd.checkbox(),
+ requiresConfiguration: zfd.checkbox(),
lotSize: zfd.numeric(z.number().min(0)),
scrapPercentage: zfd.numeric(z.number().min(0)),
});
diff --git a/apps/carbon/app/modules/items/items.service.ts b/apps/carbon/app/modules/items/items.service.ts
index b9ab0d4d4c..1955e9b020 100644
--- a/apps/carbon/app/modules/items/items.service.ts
+++ b/apps/carbon/app/modules/items/items.service.ts
@@ -116,24 +116,15 @@ export async function deleteUnitOfMeasure(
return client.from("unitOfMeasure").delete().eq("id", id);
}
-export async function getSupplierParts(
+export async function getConfigurationOptions(
client: SupabaseClient<Database>,
- id: string,
+ itemId: string,
companyId: string
) {
return client
- .from("supplierPart")
- .select(
- `
- id, supplier(id, name),
- supplierPartId, supplierUnitOfMeasureCode,
- minimumOrderQuantity, conversionFactor,
- unitPrice,
- customFields
- `
- )
- .eq("active", true)
- .eq("itemId", id)
+ .from("configurationOption")
+ .select("*")
+ .eq("itemId", itemId)
.eq("companyId", companyId);
}
@@ -808,7 +799,7 @@ export async function getServices(
}
) {
let query = client
- .from("services")
+ .from("service")
.select("*", {
count: "exact",
})
@@ -853,7 +844,7 @@ export async function getService(
companyId: string
) {
return client
- .from("services")
+ .from("service")
.select("*")
.eq("itemId", itemId)
.eq("companyId", companyId)
@@ -875,6 +866,27 @@ export async function getServicesList(
return query;
}
+export async function getSupplierParts(
+ client: SupabaseClient<Database>,
+ id: string,
+ companyId: string
+) {
+ return client
+ .from("supplierPart")
+ .select(
+ `
+ id, supplier(id, name),
+ supplierPartId, supplierUnitOfMeasureCode,
+ minimumOrderQuantity, conversionFactor,
+ unitPrice,
+ customFields
+ `
+ )
+ .eq("active", true)
+ .eq("itemId", id)
+ .eq("companyId", companyId);
+}
+
export async function getTool(
client: SupabaseClient<Database>,
itemId: string,
diff --git a/apps/carbon/app/modules/items/types.ts b/apps/carbon/app/modules/items/types.ts
index 32801321c8..b904b07c21 100644
--- a/apps/carbon/app/modules/items/types.ts
+++ b/apps/carbon/app/modules/items/types.ts
@@ -1,8 +1,8 @@
import type { Database } from "@carbon/database";
import type {
+ getConfigurationOptions,
getConsumable,
getConsumables,
- getFixtures,
getItemCost,
getItemCustomerParts,
getItemFiles,
@@ -29,8 +29,8 @@ import type {
getUnitOfMeasuresList,
} from "./items.service";
-export type SupplierPart = NonNullable<
- Awaited<ReturnType<typeof getSupplierParts>>["data"]
+export type ConfigurationOption = NonNullable<
+ Awaited<ReturnType<typeof getConfigurationOptions>>["data"]
>[number];
export type Consumable = NonNullable<
@@ -49,10 +49,6 @@ export type Form = NonNullable<
Awaited<ReturnType<typeof getMaterialForms>>["data"]
>[number];
-export type Fixture = NonNullable<
- Awaited<ReturnType<typeof getFixtures>>["data"]
->[number];
-
export type InventoryItemType = Database["public"]["Enums"]["itemTrackingType"];
export type ItemCost = NonNullable<
@@ -138,6 +134,10 @@ export type Substance = NonNullable<
Awaited<ReturnType<typeof getMaterialSubstances>>["data"]
>[number];
+export type SupplierPart = NonNullable<
+ Awaited<ReturnType<typeof getSupplierParts>>["data"]
+>[number];
+
export type Tool = NonNullable<
Awaited<ReturnType<typeof getTools>>["data"]
>[number];
diff --git a/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx b/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx
index b29dd4e728..59d7c1e9b9 100644
--- a/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx
+++ b/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx
@@ -1332,7 +1332,7 @@ function ToolsForm({
isDisabled={isDisabled || fetcher.state !== "idle"}
isLoading={fetcher.state !== "idle"}
>
- Add New
+ Add Tool
</Submit>
</VStack>
</ValidatedForm>
diff --git a/apps/carbon/app/modules/items/ui/Parts/PartManufacturingForm.tsx b/apps/carbon/app/modules/items/ui/Parts/PartManufacturingForm.tsx
index 3cfb37ee0b..7bead76a16 100644
--- a/apps/carbon/app/modules/items/ui/Parts/PartManufacturingForm.tsx
+++ b/apps/carbon/app/modules/items/ui/Parts/PartManufacturingForm.tsx
@@ -53,14 +53,14 @@ const PartManufacturingForm = ({
style: "percent",
}}
/>
- <Boolean
+ {/* <Boolean
name="manufacturingBlocked"
label="Manufacturing Blocked"
- />
- {/* <Boolean
+ /> */}
+ <Boolean
name="requiresConfiguration"
label="Requires Configuration"
- /> */}
+ />
<CustomFormFields table="partReplenishment" />
</div>
</CardContent>
diff --git a/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.method.tsx b/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.method.tsx
index 2cb53bf33f..9b814a135d 100644
--- a/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.method.tsx
+++ b/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.method.tsx
@@ -1,13 +1,36 @@
import { assertIsPost, error, success } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
-import { validationError, validator } from "@carbon/form";
-import { VStack } from "@carbon/react";
-import { json, useLoaderData, useParams } from "@remix-run/react";
+import {
+ Hidden,
+ Input,
+ Select,
+ Submit,
+ ValidatedForm,
+ validationError,
+ validator,
+} from "@carbon/form";
+import {
+ Button,
+ Card,
+ CardAction,
+ CardContent,
+ CardHeader,
+ CardTitle,
+ HStack,
+ VStack,
+} from "@carbon/react";
+import { json, useFetcher, useLoaderData, useParams } from "@remix-run/react";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
import { redirect } from "@vercel/remix";
+import { LuPlusCircle } from "react-icons/lu";
import { useRouteData } from "~/hooks";
-import type { MakeMethod, Material, MethodOperation } from "~/modules/items";
+import type {
+ ConfigurationOption,
+ MakeMethod,
+ Material,
+ MethodOperation,
+} from "~/modules/items";
import {
getItemManufacturing,
partManufacturingValidator,
@@ -119,6 +142,10 @@ export default function MakeMethodRoute() {
key={itemId}
initialValues={manufacturingInitialValues}
/>
+ {partManufacturing.requiresConfiguration && (
+ <ConfigurationOptionsForm options={[]} />
+ )}
+
<BillOfProcess
key={`bop:${itemId}`}
makeMethodId={makeMethodId}
@@ -136,3 +163,75 @@ export default function MakeMethodRoute() {
</VStack>
);
}
+
+function ConfigurationOptionsForm({
+ options,
+}: {
+ options: ConfigurationOption[];
+}) {
+ const { itemId } = useParams();
+ if (!itemId) throw new Error("Could not find itemId");
+
+ const fetcher = useFetcher();
+ return (
+ <Card>
+ <HStack className="w-full justify-between">
+ <CardHeader>
+ <CardTitle>Options</CardTitle>
+ </CardHeader>
+ <CardAction>
+ <Button variant="secondary">Add Option</Button>
+ </CardAction>
+ </HStack>
+
+ <CardContent>
+ <div className="flex flex-col gap-6">
+ <div className="p-6 border rounded-lg">
+ <ValidatedForm
+ action={path.to.newConfigurationOption}
+ method="post"
+ validator={configurationOptionValidator}
+ fetcher={fetcher}
+ resetAfterSubmit
+ defaultValues={{
+ itemId: itemId,
+ key: "",
+ label: "",
+ dataType: "numeric",
+ listOptions: [],
+ configurationOptionGroupId: undefined,
+ }}
+ className="w-full"
+ >
+ <Hidden name="itemId" />
+ <VStack spacing={4}>
+ <div className="w-full grid grid-cols-1 lg:grid-cols-3 gap-4 items-start">
+ <Input name="key" label="Key" autoFocus />
+ <Input name="label" label="Label" />
+ <Select
+ name="dataType"
+ label="Data Type"
+ options={[
+ { label: "Text", value: "text" },
+ { label: "Numeric", value: "numeric" },
+ { label: "Boolean", value: "boolean" },
+ { label: "List", value: "list" },
+ ]}
+ />
+ </div>
+
+ <Submit
+ leftIcon={<LuPlusCircle />}
+ isDisabled={fetcher.state !== "idle"}
+ isLoading={fetcher.state !== "idle"}
+ >
+ Add Option
+ </Submit>
+ </VStack>
+ </ValidatedForm>
+ </div>
+ </div>
+ </CardContent>
+ </Card>
+ );
+}
diff --git a/packages/database/src/swagger-docs-schema.ts b/packages/database/src/swagger-docs-schema.ts
index 810e7891be..86d8f86499 100644
--- a/packages/database/src/swagger-docs-schema.ts
+++ b/packages/database/src/swagger-docs-schema.ts
@@ -15960,6 +15960,132 @@ export default {
tags: ["note"],
},
},
+ "/configurationOptionGroup": {
+ get: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.configurationOptionGroup.id",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOptionGroup.itemId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOptionGroup.name",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOptionGroup.companyId",
+ },
+ {
+ $ref: "#/parameters/select",
+ },
+ {
+ $ref: "#/parameters/order",
+ },
+ {
+ $ref: "#/parameters/range",
+ },
+ {
+ $ref: "#/parameters/rangeUnit",
+ },
+ {
+ $ref: "#/parameters/offset",
+ },
+ {
+ $ref: "#/parameters/limit",
+ },
+ {
+ $ref: "#/parameters/preferCount",
+ },
+ ],
+ responses: {
+ "200": {
+ description: "OK",
+ schema: {
+ items: {
+ $ref: "#/definitions/configurationOptionGroup",
+ },
+ type: "array",
+ },
+ },
+ "206": {
+ description: "Partial Content",
+ },
+ },
+ tags: ["configurationOptionGroup"],
+ },
+ post: {
+ parameters: [
+ {
+ $ref: "#/parameters/body.configurationOptionGroup",
+ },
+ {
+ $ref: "#/parameters/select",
+ },
+ {
+ $ref: "#/parameters/preferPost",
+ },
+ ],
+ responses: {
+ "201": {
+ description: "Created",
+ },
+ },
+ tags: ["configurationOptionGroup"],
+ },
+ delete: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.configurationOptionGroup.id",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOptionGroup.itemId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOptionGroup.name",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOptionGroup.companyId",
+ },
+ {
+ $ref: "#/parameters/preferReturn",
+ },
+ ],
+ responses: {
+ "204": {
+ description: "No Content",
+ },
+ },
+ tags: ["configurationOptionGroup"],
+ },
+ patch: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.configurationOptionGroup.id",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOptionGroup.itemId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOptionGroup.name",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOptionGroup.companyId",
+ },
+ {
+ $ref: "#/parameters/body.configurationOptionGroup",
+ },
+ {
+ $ref: "#/parameters/preferReturn",
+ },
+ ],
+ responses: {
+ "204": {
+ description: "No Content",
+ },
+ },
+ tags: ["configurationOptionGroup"],
+ },
+ },
"/workCenter": {
get: {
parameters: [
@@ -34329,6 +34455,9 @@ export default {
{
$ref: "#/parameters/rowFilter.customers.taxPercent",
},
+ {
+ $ref: "#/parameters/rowFilter.customers.tags",
+ },
{
$ref: "#/parameters/rowFilter.customers.type",
},
@@ -36300,6 +36429,204 @@ export default {
tags: ["supplierProcesses"],
},
},
+ "/configurationOption": {
+ get: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.itemId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.key",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.label",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.dataType",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.listOptions",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.configurationOptionGroupId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.sortOrder",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.companyId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.createdAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.createdBy",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.updatedAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.updatedBy",
+ },
+ {
+ $ref: "#/parameters/select",
+ },
+ {
+ $ref: "#/parameters/order",
+ },
+ {
+ $ref: "#/parameters/range",
+ },
+ {
+ $ref: "#/parameters/rangeUnit",
+ },
+ {
+ $ref: "#/parameters/offset",
+ },
+ {
+ $ref: "#/parameters/limit",
+ },
+ {
+ $ref: "#/parameters/preferCount",
+ },
+ ],
+ responses: {
+ "200": {
+ description: "OK",
+ schema: {
+ items: {
+ $ref: "#/definitions/configurationOption",
+ },
+ type: "array",
+ },
+ },
+ "206": {
+ description: "Partial Content",
+ },
+ },
+ tags: ["configurationOption"],
+ },
+ post: {
+ parameters: [
+ {
+ $ref: "#/parameters/body.configurationOption",
+ },
+ {
+ $ref: "#/parameters/select",
+ },
+ {
+ $ref: "#/parameters/preferPost",
+ },
+ ],
+ responses: {
+ "201": {
+ description: "Created",
+ },
+ },
+ tags: ["configurationOption"],
+ },
+ delete: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.itemId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.key",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.label",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.dataType",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.listOptions",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.configurationOptionGroupId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.sortOrder",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.companyId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.createdAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.createdBy",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.updatedAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.updatedBy",
+ },
+ {
+ $ref: "#/parameters/preferReturn",
+ },
+ ],
+ responses: {
+ "204": {
+ description: "No Content",
+ },
+ },
+ tags: ["configurationOption"],
+ },
+ patch: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.itemId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.key",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.label",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.dataType",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.listOptions",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.configurationOptionGroupId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.sortOrder",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.companyId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.createdAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.createdBy",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.updatedAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.configurationOption.updatedBy",
+ },
+ {
+ $ref: "#/parameters/body.configurationOption",
+ },
+ {
+ $ref: "#/parameters/preferReturn",
+ },
+ ],
+ responses: {
+ "204": {
+ description: "No Content",
+ },
+ },
+ tags: ["configurationOption"],
+ },
+ },
"/postingGroupInventory": {
get: {
parameters: [
@@ -48392,6 +48719,34 @@ export default {
},
type: "object",
},
+ configurationOptionGroup: {
+ required: ["id", "itemId", "name", "companyId"],
+ properties: {
+ id: {
+ default: "public.xid()",
+ description: "Note:\nThis is a Primary Key.<pk/>",
+ format: "text",
+ type: "string",
+ },
+ itemId: {
+ description:
+ "Note:\nThis is a Foreign Key to `item.id`.<fk table='item' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ name: {
+ format: "text",
+ type: "string",
+ },
+ companyId: {
+ description:
+ "Note:\nThis is a Foreign Key to `company.id`.<fk table='company' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ },
+ type: "object",
+ },
workCenter: {
required: [
"id",
@@ -56768,6 +57123,13 @@ export default {
format: "numeric",
type: "number",
},
+ tags: {
+ format: "text[]",
+ items: {
+ type: "string",
+ },
+ type: "array",
+ },
type: {
format: "text",
type: "string",
@@ -57645,6 +58007,87 @@ export default {
},
type: "object",
},
+ configurationOption: {
+ required: [
+ "itemId",
+ "key",
+ "label",
+ "dataType",
+ "configurationOptionGroupId",
+ "sortOrder",
+ "companyId",
+ "createdAt",
+ "createdBy",
+ ],
+ properties: {
+ itemId: {
+ description:
+ "Note:\nThis is a Primary Key.<pk/>\nThis is a Foreign Key to `item.id`.<fk table='item' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ key: {
+ description: "Note:\nThis is a Primary Key.<pk/>",
+ format: "text",
+ type: "string",
+ },
+ label: {
+ format: "text",
+ type: "string",
+ },
+ dataType: {
+ enum: ["text", "numeric", "boolean", "list"],
+ format: 'public."configurationOptionDataType"',
+ type: "string",
+ },
+ listOptions: {
+ format: "text[]",
+ items: {
+ type: "string",
+ },
+ type: "array",
+ },
+ configurationOptionGroupId: {
+ description:
+ "Note:\nThis is a Foreign Key to `configurationOptionGroup.id`.<fk table='configurationOptionGroup' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ sortOrder: {
+ default: 1,
+ format: "integer",
+ type: "integer",
+ },
+ companyId: {
+ description:
+ "Note:\nThis is a Foreign Key to `company.id`.<fk table='company' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ createdAt: {
+ default: "now()",
+ format: "timestamp with time zone",
+ type: "string",
+ },
+ createdBy: {
+ description:
+ "Note:\nThis is a Foreign Key to `user.id`.<fk table='user' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ updatedAt: {
+ format: "timestamp with time zone",
+ type: "string",
+ },
+ updatedBy: {
+ description:
+ "Note:\nThis is a Foreign Key to `user.id`.<fk table='user' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ },
+ type: "object",
+ },
postingGroupInventory: {
required: [
"id",
@@ -68624,6 +69067,43 @@ export default {
in: "query",
type: "string",
},
+ "body.configurationOptionGroup": {
+ name: "configurationOptionGroup",
+ description: "configurationOptionGroup",
+ required: false,
+ in: "body",
+ schema: {
+ $ref: "#/definitions/configurationOptionGroup",
+ },
+ },
+ "rowFilter.configurationOptionGroup.id": {
+ name: "id",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.configurationOptionGroup.itemId": {
+ name: "itemId",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.configurationOptionGroup.name": {
+ name: "name",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.configurationOptionGroup.companyId": {
+ name: "companyId",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
"body.workCenter": {
name: "workCenter",
description: "workCenter",
@@ -79546,6 +80026,13 @@ export default {
in: "query",
type: "string",
},
+ "rowFilter.customers.tags": {
+ name: "tags",
+ required: false,
+ format: "text[]",
+ in: "query",
+ type: "string",
+ },
"rowFilter.customers.type": {
name: "type",
required: false,
@@ -80686,6 +81173,99 @@ export default {
in: "query",
type: "string",
},
+ "body.configurationOption": {
+ name: "configurationOption",
+ description: "configurationOption",
+ required: false,
+ in: "body",
+ schema: {
+ $ref: "#/definitions/configurationOption",
+ },
+ },
+ "rowFilter.configurationOption.itemId": {
+ name: "itemId",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.configurationOption.key": {
+ name: "key",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.configurationOption.label": {
+ name: "label",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.configurationOption.dataType": {
+ name: "dataType",
+ required: false,
+ format: 'public."configurationOptionDataType"',
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.configurationOption.listOptions": {
+ name: "listOptions",
+ required: false,
+ format: "text[]",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.configurationOption.configurationOptionGroupId": {
+ name: "configurationOptionGroupId",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.configurationOption.sortOrder": {
+ name: "sortOrder",
+ required: false,
+ format: "integer",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.configurationOption.companyId": {
+ name: "companyId",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.configurationOption.createdAt": {
+ name: "createdAt",
+ required: false,
+ format: "timestamp with time zone",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.configurationOption.createdBy": {
+ name: "createdBy",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.configurationOption.updatedAt": {
+ name: "updatedAt",
+ required: false,
+ format: "timestamp with time zone",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.configurationOption.updatedBy": {
+ name: "updatedBy",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
"body.postingGroupInventory": {
name: "postingGroupInventory",
description: "postingGroupInventory",
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index c8ad699d7b..22dba9ccf2 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -1951,6 +1951,221 @@ export type Database = {
},
]
}
+ configurationOption: {
+ Row: {
+ companyId: string
+ configurationOptionGroupId: string
+ createdAt: string
+ createdBy: string
+ dataType: Database["public"]["Enums"]["configurationOptionDataType"]
+ itemId: string
+ key: string
+ label: string
+ listOptions: string[] | null
+ sortOrder: number
+ updatedAt: string | null
+ updatedBy: string | null
+ }
+ Insert: {
+ companyId: string
+ configurationOptionGroupId: string
+ createdAt?: string
+ createdBy: string
+ dataType: Database["public"]["Enums"]["configurationOptionDataType"]
+ itemId: string
+ key: string
+ label: string
+ listOptions?: string[] | null
+ sortOrder?: number
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Update: {
+ companyId?: string
+ configurationOptionGroupId?: string
+ createdAt?: string
+ createdBy?: string
+ dataType?: Database["public"]["Enums"]["configurationOptionDataType"]
+ itemId?: string
+ key?: string
+ label?: string
+ listOptions?: string[] | null
+ sortOrder?: number
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Relationships: [
+ {
+ foreignKeyName: "configurationOption_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "companies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOption_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "company"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOption_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "customFieldTables"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "configurationOption_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "integrations"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "configurationOption_configurationOptionGroupId_fkey"
+ columns: ["configurationOptionGroupId"]
+ isOneToOne: false
+ referencedRelation: "configurationOptionGroup"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOption_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOption_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOption_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOption_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOption_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "configurationOption_itemId_fkey"
+ columns: ["itemId"]
+ isOneToOne: false
+ referencedRelation: "item"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOption_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOption_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOption_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOption_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOption_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ ]
+ }
+ configurationOptionGroup: {
+ Row: {
+ companyId: string
+ id: string
+ itemId: string
+ name: string
+ }
+ Insert: {
+ companyId: string
+ id?: string
+ itemId: string
+ name: string
+ }
+ Update: {
+ companyId?: string
+ id?: string
+ itemId?: string
+ name?: string
+ }
+ Relationships: [
+ {
+ foreignKeyName: "configurationOptionGroup_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "companies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOptionGroup_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "company"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOptionGroup_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "customFieldTables"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "configurationOptionGroup_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "integrations"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "configurationOptionGroup_itemId_fkey"
+ columns: ["itemId"]
+ isOneToOne: false
+ referencedRelation: "item"
+ referencedColumns: ["id"]
+ },
+ ]
+ }
consumable: {
Row: {
approved: boolean
@@ -26780,14 +26995,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"]
@@ -27993,14 +28208,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["supplierCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["supplierCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
@@ -32178,6 +32393,7 @@ export type Database = {
}
Enums: {
accountingPeriodStatus: "Inactive" | "Active"
+ configurationOptionDataType: "text" | "numeric" | "boolean" | "list"
costLedgerType:
| "Direct Cost"
| "Revaluation"
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index c8ad699d7b..22dba9ccf2 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -1951,6 +1951,221 @@ export type Database = {
},
]
}
+ configurationOption: {
+ Row: {
+ companyId: string
+ configurationOptionGroupId: string
+ createdAt: string
+ createdBy: string
+ dataType: Database["public"]["Enums"]["configurationOptionDataType"]
+ itemId: string
+ key: string
+ label: string
+ listOptions: string[] | null
+ sortOrder: number
+ updatedAt: string | null
+ updatedBy: string | null
+ }
+ Insert: {
+ companyId: string
+ configurationOptionGroupId: string
+ createdAt?: string
+ createdBy: string
+ dataType: Database["public"]["Enums"]["configurationOptionDataType"]
+ itemId: string
+ key: string
+ label: string
+ listOptions?: string[] | null
+ sortOrder?: number
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Update: {
+ companyId?: string
+ configurationOptionGroupId?: string
+ createdAt?: string
+ createdBy?: string
+ dataType?: Database["public"]["Enums"]["configurationOptionDataType"]
+ itemId?: string
+ key?: string
+ label?: string
+ listOptions?: string[] | null
+ sortOrder?: number
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Relationships: [
+ {
+ foreignKeyName: "configurationOption_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "companies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOption_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "company"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOption_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "customFieldTables"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "configurationOption_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "integrations"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "configurationOption_configurationOptionGroupId_fkey"
+ columns: ["configurationOptionGroupId"]
+ isOneToOne: false
+ referencedRelation: "configurationOptionGroup"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOption_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOption_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOption_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOption_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOption_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "configurationOption_itemId_fkey"
+ columns: ["itemId"]
+ isOneToOne: false
+ referencedRelation: "item"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOption_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOption_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOption_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOption_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOption_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ ]
+ }
+ configurationOptionGroup: {
+ Row: {
+ companyId: string
+ id: string
+ itemId: string
+ name: string
+ }
+ Insert: {
+ companyId: string
+ id?: string
+ itemId: string
+ name: string
+ }
+ Update: {
+ companyId?: string
+ id?: string
+ itemId?: string
+ name?: string
+ }
+ Relationships: [
+ {
+ foreignKeyName: "configurationOptionGroup_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "companies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOptionGroup_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "company"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "configurationOptionGroup_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "customFieldTables"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "configurationOptionGroup_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "integrations"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "configurationOptionGroup_itemId_fkey"
+ columns: ["itemId"]
+ isOneToOne: false
+ referencedRelation: "item"
+ referencedColumns: ["id"]
+ },
+ ]
+ }
consumable: {
Row: {
approved: boolean
@@ -26780,14 +26995,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"]
@@ -27993,14 +28208,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["supplierCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["supplierCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
@@ -32178,6 +32393,7 @@ export type Database = {
}
Enums: {
accountingPeriodStatus: "Inactive" | "Active"
+ configurationOptionDataType: "text" | "numeric" | "boolean" | "list"
costLedgerType:
| "Direct Cost"
| "Revaluation"
diff --git a/packages/database/supabase/migrations/20241217184843_configuration-options.sql b/packages/database/supabase/migrations/20241217184843_configuration-options.sql
new file mode 100644
index 0000000000..88a0c96312
--- /dev/null
+++ b/packages/database/supabase/migrations/20241217184843_configuration-options.sql
@@ -0,0 +1,72 @@
+CREATE TABLE IF NOT EXISTS "configurationOptionGroup" (
+ "id" TEXT NOT NULL DEFAULT xid(),
+ "itemId" TEXT NOT NULL,
+ "name" TEXT NOT NULL,
+ "companyId" TEXT NOT NULL,
+ CONSTRAINT "configurationOptionGroup_pkey" PRIMARY KEY ("id"),
+ CONSTRAINT "configurationOptionGroup_itemId_fkey" FOREIGN KEY ("itemId") REFERENCES "item"("id"),
+ CONSTRAINT "configurationOptionGroup_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id")
+);
+
+CREATE TYPE "configurationOptionDataType" AS ENUM ('text', 'numeric', 'boolean', 'list');
+CREATE TABLE IF NOT EXISTS "configurationOption" (
+ "itemId" TEXT NOT NULL,
+ "key" TEXT NOT NULL,
+ "label" TEXT NOT NULL,
+ "dataType" "configurationOptionDataType" NOT NULL,
+ "listOptions" TEXT[],
+ "configurationOptionGroupId" TEXT NOT NULL,
+ "sortOrder" INTEGER NOT NULL DEFAULT 1,
+ "companyId" TEXT NOT NULL,
+ "createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,
+ "createdBy" TEXT NOT NULL,
+ "updatedAt" TIMESTAMP WITH TIME ZONE,
+ "updatedBy" TEXT,
+
+ CONSTRAINT "configurationOption_pkey" PRIMARY KEY ("itemId", "key"),
+ CONSTRAINT "configurationOption_itemId_label_key" UNIQUE ("itemId", "label"),
+ CONSTRAINT "configurationOption_itemId_fkey" FOREIGN KEY ("itemId") REFERENCES "item"("id") ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT "configurationOption_configurationOptionGroupId_fkey" FOREIGN KEY ("configurationOptionGroupId") REFERENCES "configurationOptionGroup"("id") ON DELETE SET NULL ON UPDATE CASCADE,
+ CONSTRAINT "configurationOption_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id") ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT "configurationOption_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user"("id") ON UPDATE CASCADE,
+ CONSTRAINT "configurationOption_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user"("id") ON UPDATE CASCADE
+);
+
+CREATE INDEX "configurationOption_itemId_idx" ON "configurationOption" ("itemId");
+CREATE INDEX "configurationOption_companyId_idx" ON "configurationOption" ("companyId");
+
+ALTER TABLE "configurationOption" ENABLE ROW LEVEL SECURITY;
+
+CREATE POLICY "Employees with parts_view can view configuration options" ON "configurationOption"
+ FOR SELECT
+ USING (
+ has_role('employee', "companyId") AND
+ has_company_permission('parts_view', "companyId")
+ );
+
+CREATE POLICY "Employees with parts_create can insert configuration options" ON "configurationOption"
+ FOR INSERT
+ WITH CHECK (
+ has_role('employee', "companyId") AND
+ has_company_permission('parts_create', "companyId")
+);
+
+CREATE POLICY "Employees with parts_update can update configuration options" ON "configurationOption"
+ FOR UPDATE
+ USING (
+ has_role('employee', "companyId") AND
+ has_company_permission('parts_update', "companyId")
+ );
+
+CREATE POLICY "Employees with parts_delete can delete configuration options" ON "configurationOption"
+ FOR DELETE
+ USING (
+ has_role('employee', "companyId") AND
+ has_company_permission('parts_delete', "companyId")
+ );
+
+CREATE POLICY "Requests with an API key can access configuration options" ON "configurationOption"
+FOR ALL USING (
+ has_valid_api_key_for_company("companyId")
+);
+