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: default items created in quotes and rfqs to inactive

Brad Barbinb5a195de86e1
diff --git a/apps/carbon/app/components/Form/Item.tsx b/apps/carbon/app/components/Form/Item.tsx
index 52be386bab..c3b50809e5 100644
--- a/apps/carbon/app/components/Form/Item.tsx
+++ b/apps/carbon/app/components/Form/Item.tsx
@@ -15,6 +15,7 @@ import CreatableCombobox from "./CreatableCombobox";
type ItemSelectProps = Omit<ComboboxProps, "options" | "type"> & {
type: Database["public"]["Enums"]["itemType"];
disabledItems?: string[];
+ includeInactive?: boolean;
replenishmentSystem?: string;
};
@@ -26,11 +27,12 @@ const Item = ({ type, ...props }: ItemSelectProps) => {
const options = useMemo(() => {
const results =
- (props?.replenishmentSystem
+ (props?.replenishmentSystem || props?.includeInactive !== true
? items.filter(
(item) =>
item.type === type &&
- item.replenishmentSystem === props.replenishmentSystem
+ item.replenishmentSystem === props.replenishmentSystem &&
+ (item.active === true || props?.includeInactive === true)
)
: items
)
@@ -47,7 +49,13 @@ const Item = ({ type, ...props }: ItemSelectProps) => {
}
return results;
- }, [items, props.disabledItems, props.replenishmentSystem, type]);
+ }, [
+ items,
+ props?.includeInactive,
+ props.disabledItems,
+ props.replenishmentSystem,
+ type,
+ ]);
return (
<>
@@ -77,7 +85,7 @@ const Item = ({ type, ...props }: ItemSelectProps) => {
replenishmentSystem: "Make",
unitOfMeasureCode: "EA",
defaultMethodType: "Make",
- active: true,
+ active: props?.includeInactive === undefined,
}}
/>
)}
@@ -97,7 +105,7 @@ const Item = ({ type, ...props }: ItemSelectProps) => {
unitOfMeasureCode: "EA",
replenishmentSystem: "Buy",
defaultMethodType: "Buy",
- active: true,
+ active: props?.includeInactive === undefined,
}}
/>
)}
@@ -117,7 +125,7 @@ const Item = ({ type, ...props }: ItemSelectProps) => {
unitOfMeasureCode: "EA",
replenishmentSystem: "Make",
defaultMethodType: "Buy",
- active: true,
+ active: props?.includeInactive === undefined,
}}
/>
)}
@@ -139,7 +147,7 @@ const Item = ({ type, ...props }: ItemSelectProps) => {
unitOfMeasureCode: "EA",
replenishmentSystem: "Buy",
defaultMethodType: "Buy",
- active: true,
+ active: props?.includeInactive === undefined,
}}
/>
)}
@@ -160,7 +168,7 @@ const Item = ({ type, ...props }: ItemSelectProps) => {
unitOfMeasureCode: "EA",
replenishmentSystem: "Buy",
defaultMethodType: "Buy",
- active: true,
+ active: props?.includeInactive === undefined,
}}
/>
)}
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx
index 47f1c91c08..e44f8c62ef 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx
@@ -540,7 +540,7 @@ function MaterialForm({
disabledItems={[params.itemId!]}
name="itemId"
label={itemType}
- // @ts-ignore
+ includeInactive
type={itemType}
onChange={(value) => {
onItemChange(value?.value as string);
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineCosting.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineCosting.tsx
index 4c5c36f103..5e671374a0 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineCosting.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineCosting.tsx
@@ -22,6 +22,7 @@ import {
import { useFetcher, useParams } from "@remix-run/react";
import { useCallback, useMemo } from "react";
import { LuPlus, LuTrash } from "react-icons/lu";
+import type { z } from "zod";
import type { Tree } from "~/components/TreeView";
import {
quoteLineAdditionalChargesValidator,
@@ -287,10 +288,23 @@ const QuoteLineCosting = ({
);
const additionalCharges = useMemo(() => {
+ if (fetcher.formAction === path.to.quoteLineCost(quoteId, lineId)) {
+ // get the optimistic update
+ return JSON.parse(
+ (fetcher.formData?.get("additionalCharges") as string) ?? "{}"
+ ) as z.infer<typeof quoteLineAdditionalChargesValidator>;
+ }
const parsedAdditionalCharges =
quoteLineAdditionalChargesValidator.safeParse(additionalChargesJson);
+
return parsedAdditionalCharges.success ? parsedAdditionalCharges.data : {};
- }, [additionalChargesJson]);
+ }, [
+ additionalChargesJson,
+ fetcher.formAction,
+ fetcher.formData,
+ lineId,
+ quoteId,
+ ]);
const additionalChargesByQuantity = quantities.map((quantity) => {
const charges = Object.values(additionalCharges).reduce((acc, charge) => {
@@ -353,7 +367,7 @@ const QuoteLineCosting = ({
<Table>
<Thead>
<Tr>
- <Th />
+ <Th className="w-[300px]" />
{quantities.map((quantity) => (
<Th key={quantity.toString()}>{quantity}</Th>
))}
@@ -560,7 +574,7 @@ const QuoteLineCosting = ({
<Tr className="font-bold">
<Td className="border-r border-border">
<HStack className="w-full justify-between ">
- <span>Total Cost</span>
+ <span>Total Estimated Cost</span>
<Enumerable value="Total" />
</HStack>
</Td>
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineForm.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineForm.tsx
index 17ae355813..ac91340fb4 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineForm.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineForm.tsx
@@ -200,6 +200,7 @@ const QuoteLineForm = ({
name="itemId"
type="Part"
label="Part"
+ includeInactive
onChange={(value) => {
onItemChange(value?.value as string);
}}
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteMaterialForm.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteMaterialForm.tsx
index 414840b562..b2d239fa24 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteMaterialForm.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteMaterialForm.tsx
@@ -207,6 +207,7 @@ const QuoteMaterialForm = ({
name="itemId"
label={itemType}
type={itemType}
+ includeInactive
onChange={(value) => {
onItemChange(value?.value as string);
}}
diff --git a/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQLines.tsx b/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQLines.tsx
index c3a0c0e891..df27d4dc56 100644
--- a/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQLines.tsx
+++ b/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQLines.tsx
@@ -728,6 +728,7 @@ function SalesRFQLineForm({
name="itemId"
label="Part"
type="Part"
+ includeInactive
onChange={(value) => {
onItemChange(value?.value as string);
}}
diff --git a/apps/carbon/app/modules/shared/ui/RealtimeDataProvider.tsx b/apps/carbon/app/modules/shared/ui/RealtimeDataProvider.tsx
index 51c66725a2..b01881587e 100644
--- a/apps/carbon/app/modules/shared/ui/RealtimeDataProvider.tsx
+++ b/apps/carbon/app/modules/shared/ui/RealtimeDataProvider.tsx
@@ -44,9 +44,8 @@ const RealtimeDataProvider = ({ children }: { children: React.ReactNode }) => {
const [items, suppliers, customers, people] = await Promise.all([
supabase
.from("item")
- .select("id, readableId, name, type, replenishmentSystem")
+ .select("id, readableId, name, type, replenishmentSystem, active")
.eq("companyId", companyId)
- .eq("active", true)
.order("name"),
supabase
.from("supplier")
@@ -109,24 +108,24 @@ const RealtimeDataProvider = ({ children }: { children: React.ReactNode }) => {
switch (payload.eventType) {
case "INSERT":
const { new: inserted } = payload;
- if (inserted.active) {
- setItems((items) =>
- [
- ...items,
- {
- id: inserted.id,
- name: inserted.name,
- readableId: inserted.readableId,
- replenishmentSystem: inserted.replenishmentSystem,
- type: inserted.type,
- },
- ].sort((a, b) => a.name.localeCompare(b.name))
- );
- }
+
+ setItems((items) =>
+ [
+ ...items,
+ {
+ id: inserted.id,
+ name: inserted.name,
+ readableId: inserted.readableId,
+ replenishmentSystem: inserted.replenishmentSystem,
+ type: inserted.type,
+ },
+ ].sort((a, b) => a.name.localeCompare(b.name))
+ );
+
break;
case "UPDATE":
const { new: updated } = payload;
- // TODO: handle active status changes
+
setItems((items) =>
items
.map((i) => {
diff --git a/apps/carbon/app/stores/items.ts b/apps/carbon/app/stores/items.ts
index d1070a402b..0c2cc54971 100644
--- a/apps/carbon/app/stores/items.ts
+++ b/apps/carbon/app/stores/items.ts
@@ -8,6 +8,7 @@ export type Item = ListItem & {
readableId: string;
type: Database["public"]["Enums"]["itemType"];
replenishmentSystem: Database["public"]["Enums"]["itemReplenishmentSystem"];
+ active: boolean;
};
const $itemsStore = atom<Item[]>([]);