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 tag filtering to inventory quantities page (#432)

Uday Jain617d19470a8a
diff --git a/apps/erp/app/modules/inventory/ui/Inventory/InventoryTable.tsx b/apps/erp/app/modules/inventory/ui/Inventory/InventoryTable.tsx
index 5722a89e34..d12670f63c 100644
--- a/apps/erp/app/modules/inventory/ui/Inventory/InventoryTable.tsx
+++ b/apps/erp/app/modules/inventory/ui/Inventory/InventoryTable.tsx
@@ -1,4 +1,5 @@
import {
+ Badge,
Button,
Checkbox,
Combobox,
@@ -29,7 +30,8 @@ import {
LuPuzzle,
LuRuler,
LuShapes,
- LuStar
+ LuStar,
+ LuTag
} from "react-icons/lu";
import { useFetcher } from "react-router";
import {
@@ -64,10 +66,18 @@ type InventoryTableProps = {
locationId: string;
forms: ListItem[];
substances: ListItem[];
+ tags: string[];
};
const InventoryTable = memo(
- ({ data, count, locationId, forms, substances }: InventoryTableProps) => {
+ ({
+ data,
+ count,
+ locationId,
+ forms,
+ substances,
+ tags
+ }: InventoryTableProps) => {
const [params] = useUrlParams();
const locations = useLocations();
@@ -402,6 +412,30 @@ const InventoryTable = memo(
icon: <LuBox />
}
},
+ {
+ accessorKey: "tags",
+ header: "Tags",
+ cell: ({ row }) => (
+ <HStack spacing={0} className="gap-1">
+ {(row.original.tags || []).map((tag) => (
+ <Badge key={tag} variant="secondary">
+ {tag}
+ </Badge>
+ ))}
+ </HStack>
+ ),
+ meta: {
+ filter: {
+ type: "static",
+ options: tags?.map((tag) => ({
+ value: tag,
+ label: <Badge variant="secondary">{tag}</Badge>
+ })),
+ isArray: true
+ },
+ icon: <LuTag />
+ }
+ },
{
accessorKey: "active",
header: "Active",
@@ -426,11 +460,13 @@ const InventoryTable = memo(
numberFormatter,
params,
substances,
+ tags,
unitOfMeasures
]);
const defaultColumnVisibility = {
active: false,
+ tags: false,
type: false,
finish: false,
grade: false,
diff --git a/apps/erp/app/routes/x+/inventory+/quantities.tsx b/apps/erp/app/routes/x+/inventory+/quantities.tsx
index b2293efe89..e43aacd429 100644
--- a/apps/erp/app/routes/x+/inventory+/quantities.tsx
+++ b/apps/erp/app/routes/x+/inventory+/quantities.tsx
@@ -12,6 +12,7 @@ import {
getMaterialSubstancesList
} from "~/modules/items";
import { getLocationsList } from "~/modules/resources";
+import { getTagsList } from "~/modules/shared";
import { getUserDefaults } from "~/modules/users/users.server";
import { path } from "~/utils/path";
import { getGenericQueryFilters } from "~/utils/query";
@@ -60,7 +61,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
locationId = locations.data?.[0].id as string;
}
- const [inventoryItems, forms, substances] = await Promise.all([
+ const [inventoryItems, forms, substances, tags] = await Promise.all([
getInventoryItems(client, locationId, companyId, {
search,
limit,
@@ -68,9 +69,9 @@ export async function loader({ request }: LoaderFunctionArgs) {
sorts,
filters
}),
-
getMaterialFormsList(client, companyId),
- getMaterialSubstancesList(client, companyId)
+ getMaterialSubstancesList(client, companyId),
+ getTagsList(client, companyId)
]);
if (inventoryItems.error) {
@@ -83,17 +84,21 @@ export async function loader({ request }: LoaderFunctionArgs) {
);
}
+ // Deduplicate tag names using Set
+ const uniqueTags = [...new Set((tags.data ?? []).map((t) => t.name))];
+
return {
count: inventoryItems.count ?? 0,
inventoryItems: (inventoryItems.data ?? []) as InventoryItem[],
locationId,
forms: forms.data ?? [],
- substances: substances.data ?? []
+ substances: substances.data ?? [],
+ tags: uniqueTags
};
}
export default function QuantitiesRoute() {
- const { count, inventoryItems, locationId, forms, substances } =
+ const { count, inventoryItems, locationId, forms, substances, tags } =
useLoaderData<typeof loader>();
return (
@@ -111,6 +116,7 @@ export default function QuantitiesRoute() {
locationId={locationId}
forms={forms}
substances={substances}
+ tags={tags}
/>
</ResizablePanel>
<Outlet />
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index d663b736e8..1efff9abc0 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -53136,6 +53136,7 @@ export type Database = {
reorderPoint: number
reorderQuantity: number
replenishmentSystem: Database["public"]["Enums"]["itemReplenishmentSystem"]
+ tags: string[]
thumbnailPath: string
type: Database["public"]["Enums"]["itemType"]
unitOfMeasureCode: string
diff --git a/packages/database/supabase/migrations/20260113122437_inventory-tags-filter.sql b/packages/database/supabase/migrations/20260113122437_inventory-tags-filter.sql
new file mode 100644
index 0000000000..a9a41b6eb9
--- /dev/null
+++ b/packages/database/supabase/migrations/20260113122437_inventory-tags-filter.sql
@@ -0,0 +1,214 @@
+-- Add tags to inventory quantities for filtering by item tags
+-- Supports tags from all item types: Material, Part, Tool, Consumable
+-- Note: These tables join via readableId = id (itemId was dropped in revisions migration)
+DROP FUNCTION IF EXISTS get_inventory_quantities;
+CREATE OR REPLACE FUNCTION get_inventory_quantities(company_id TEXT, location_id TEXT)
+ RETURNS TABLE (
+ "id" TEXT,
+ "readableId" TEXT,
+ "readableIdWithRevision" TEXT,
+ "name" TEXT,
+ "active" BOOLEAN,
+ "type" "itemType",
+ "itemTrackingType" "itemTrackingType",
+ "replenishmentSystem" "itemReplenishmentSystem",
+ "materialSubstanceId" TEXT,
+ "materialFormId" TEXT,
+ "dimensionId" TEXT,
+ "dimension" TEXT,
+ "finishId" TEXT,
+ "finish" TEXT,
+ "gradeId" TEXT,
+ "grade" TEXT,
+ "materialType" TEXT,
+ "materialTypeId" TEXT,
+ "thumbnailPath" TEXT,
+ "unitOfMeasureCode" TEXT,
+ "leadTime" INTEGER,
+ "lotSize" INTEGER,
+ "reorderingPolicy" "itemReorderingPolicy",
+ "demandAccumulationPeriod" INTEGER,
+ "demandAccumulationSafetyStock" NUMERIC,
+ "reorderPoint" INTEGER,
+ "reorderQuantity" INTEGER,
+ "minimumOrderQuantity" INTEGER,
+ "maximumOrderQuantity" INTEGER,
+ "maximumInventoryQuantity" NUMERIC,
+ "orderMultiple" INTEGER,
+ "quantityOnHand" NUMERIC,
+ "quantityOnSalesOrder" NUMERIC,
+ "quantityOnPurchaseOrder" NUMERIC,
+ "quantityOnProductionOrder" NUMERIC,
+ "quantityOnProductionDemand" NUMERIC,
+ "usageLast30Days" NUMERIC,
+ "usageLast90Days" NUMERIC,
+ "daysRemaining" NUMERIC,
+ "tags" TEXT[]
+ ) AS $$
+ BEGIN
+ RETURN QUERY
+
+WITH
+ open_purchase_orders AS (
+ SELECT
+ pol."itemId",
+ SUM(pol."quantityToReceive" * pol."conversionFactor") AS "quantityOnPurchaseOrder"
+ FROM
+ "purchaseOrder" po
+ INNER JOIN "purchaseOrderLine" pol
+ ON pol."purchaseOrderId" = po."id"
+ WHERE
+ po."status" IN (
+ 'Planned',
+ 'To Receive',
+ 'To Receive and Invoice'
+ )
+ AND po."companyId" = company_id
+ AND pol."locationId" = location_id
+ GROUP BY pol."itemId"
+ ),
+ open_sales_orders AS (
+ SELECT
+ sol."itemId",
+ SUM(sol."quantityToSend") AS "quantityOnSalesOrder"
+ FROM
+ "salesOrder" so
+ INNER JOIN "salesOrderLine" sol
+ ON sol."salesOrderId" = so."id"
+ WHERE
+ so."status" IN (
+ 'Confirmed',
+ 'To Ship and Invoice',
+ 'To Ship',
+ 'To Invoice',
+ 'In Progress'
+ )
+ AND so."companyId" = company_id
+ AND sol."locationId" = location_id
+ GROUP BY sol."itemId"
+ ),
+ open_job_requirements AS (
+ SELECT
+ jm."itemId",
+ SUM(jm."quantityToIssue") AS "quantityOnProductionDemand"
+ FROM "jobMaterial" jm
+ INNER JOIN "job" j ON jm."jobId" = j."id"
+ WHERE j."status" IN (
+ 'Planned',
+ 'Ready',
+ 'In Progress',
+ 'Paused'
+ )
+ AND jm."methodType" != 'Make'
+ AND j."companyId" = company_id
+ AND j."locationId" = location_id
+ GROUP BY jm."itemId"
+ ),
+ open_jobs AS (
+ SELECT
+ j."itemId",
+ SUM(j."productionQuantity" + j."scrapQuantity" - j."quantityReceivedToInventory" - j."quantityShipped") AS "quantityOnProductionOrder"
+ FROM job j
+ WHERE j."status" IN (
+ 'Planned',
+ 'Ready',
+ 'In Progress',
+ 'Paused'
+ )
+ AND j."companyId" = company_id
+ AND j."locationId" = location_id
+ GROUP BY j."itemId"
+ ),
+ item_ledgers AS (
+ SELECT
+ "itemId",
+ SUM("quantity") AS "quantityOnHand",
+ SUM(CASE
+ WHEN "entryType" IN ('Negative Adjmt.', 'Sale', 'Consumption', 'Assembly Consumption')
+ AND "createdAt" >= CURRENT_DATE - INTERVAL '30 days'
+ THEN -"quantity"
+ ELSE 0
+ END) / 30 AS "usageLast30Days",
+ SUM(CASE
+ WHEN "entryType" IN ('Negative Adjmt.', 'Sale', 'Consumption', 'Assembly Consumption')
+ AND "createdAt" >= CURRENT_DATE - INTERVAL '90 days'
+ THEN -"quantity"
+ ELSE 0
+ END) / 90 AS "usageLast90Days"
+ FROM "itemLedger"
+ WHERE "companyId" = company_id
+ AND "locationId" = location_id
+ GROUP BY "itemId"
+ )
+
+SELECT
+ i."id",
+ i."readableId",
+ i."readableIdWithRevision",
+ i."name",
+ i."active",
+ i."type",
+ i."itemTrackingType",
+ i."replenishmentSystem",
+ m."materialSubstanceId",
+ m."materialFormId",
+ m."dimensionId",
+ md."name" AS "dimension",
+ m."finishId",
+ mf."name" AS "finish",
+ m."gradeId",
+ mg."name" AS "grade",
+ mt."name" AS "materialType",
+ m."materialTypeId",
+ CASE
+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"
+ ELSE i."thumbnailPath"
+ END AS "thumbnailPath",
+ i."unitOfMeasureCode",
+ ir."leadTime",
+ ir."lotSize",
+ ip."reorderingPolicy",
+ ip."demandAccumulationPeriod",
+ ip."demandAccumulationSafetyStock",
+ ip."reorderPoint",
+ ip."reorderQuantity",
+ ip."minimumOrderQuantity",
+ ip."maximumOrderQuantity",
+ ip."maximumInventoryQuantity",
+ ip."orderMultiple",
+ COALESCE(il."quantityOnHand", 0) AS "quantityOnHand",
+ COALESCE(so."quantityOnSalesOrder", 0) AS "quantityOnSalesOrder",
+ COALESCE(purch."quantityOnPurchaseOrder", 0) AS "quantityOnPurchaseOrder",
+ COALESCE(jo."quantityOnProductionOrder", 0) AS "quantityOnProductionOrder",
+ COALESCE(jr."quantityOnProductionDemand", 0) AS "quantityOnProductionDemand",
+ COALESCE(il."usageLast30Days", 0) AS "usageLast30Days",
+ COALESCE(il."usageLast90Days", 0) AS "usageLast90Days",
+ CASE
+ WHEN COALESCE(il."usageLast30Days", 0) > 0
+ THEN ROUND(COALESCE(il."quantityOnHand", 0) / il."usageLast30Days", 2)
+ ELSE NULL
+ END AS "daysRemaining",
+ COALESCE(m."tags", p."tags", t."tags", c."tags") AS "tags"
+FROM
+ "item" i
+ LEFT JOIN item_ledgers il ON i."id" = il."itemId"
+ LEFT JOIN open_sales_orders so ON i."id" = so."itemId"
+ LEFT JOIN open_purchase_orders purch ON i."id" = purch."itemId"
+ LEFT JOIN open_jobs jo ON i."id" = jo."itemId"
+ LEFT JOIN open_job_requirements jr ON i."id" = jr."itemId"
+ LEFT JOIN material m ON i."readableId" = m."id"
+ AND (m."companyId" = company_id OR m."companyId" IS NULL)
+ LEFT JOIN part p ON i."readableId" = p."id" AND p."companyId" = company_id
+ LEFT JOIN tool t ON i."readableId" = t."id" AND t."companyId" = company_id
+ LEFT JOIN consumable c ON i."readableId" = c."id" AND c."companyId" = company_id
+ LEFT JOIN "modelUpload" mu ON mu.id = i."modelUploadId"
+ LEFT JOIN "materialDimension" md ON m."dimensionId" = md."id"
+ LEFT JOIN "materialFinish" mf ON m."finishId" = mf."id"
+ LEFT JOIN "materialGrade" mg ON m."gradeId" = mg."id"
+ LEFT JOIN "materialType" mt ON m."materialTypeId" = mt."id"
+ LEFT JOIN "itemReplenishment" ir ON i."id" = ir."itemId"
+ LEFT JOIN "itemPlanning" ip ON i."id" = ip."itemId" AND ip."locationId" = location_id
+WHERE
+ i."itemTrackingType" <> 'Non-Inventory' AND i."companyId" = company_id;
+ END;
+$$ LANGUAGE plpgsql SECURITY DEFINER;