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.

fix: add ability to add unit price without recalculate button

Brad Barbin398c21544065
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLinePricing.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLinePricing.tsx
index 8b33601687..fa44055755 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLinePricing.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLinePricing.tsx
@@ -28,6 +28,7 @@ import { useFetcher, useParams } from "@remix-run/react";
import { useEffect, useMemo, useState } from "react";
import { LuChevronDown, LuInfo, LuRefreshCcw } from "react-icons/lu";
import type { z } from "zod";
+import { useUser } from "~/hooks";
import { useSupabase } from "~/lib/supabase";
import { path } from "~/utils/path";
import { quoteLineAdditionalChargesValidator } from "../../sales.models";
@@ -55,6 +56,7 @@ const QuoteLinePricing = ({
const { supabase } = useSupabase();
const fetcher = useFetcher<{ id: string }>();
+ const { id: userId } = useUser();
// TODO: factor in default currency or quote currency
const formatter = useMemo(
@@ -131,26 +133,42 @@ const QuoteLinePricing = ({
value: number
) => {
if (!supabase) return;
-
+ const hasPrice = prices[quantity];
const oldPrices = { ...prices };
const newPrices = { ...oldPrices };
- if (!newPrices[quantity]) {
+ if (!hasPrice) {
newPrices[quantity] = {
+ quoteId,
+ quoteLineId: lineId,
+ quantity,
leadTime: 0,
unitPrice: 0,
discountPercent: 0,
- } as QuotationPrice;
+ createdBy: userId,
+ } as unknown as QuotationPrice;
}
newPrices[quantity] = { ...newPrices[quantity], [key]: value };
+
setPrices(newPrices);
- const { error } = await supabase
- .from("quoteLinePrice")
- .update({ [key]: value })
- .eq("quoteLineId", lineId)
- .eq("quantity", quantity);
- if (error) {
- setPrices(oldPrices);
+ if (hasPrice) {
+ const { error } = await supabase
+ .from("quoteLinePrice")
+ .update({ [key]: value })
+ .eq("quoteLineId", lineId)
+ .eq("quantity", quantity);
+ if (error) {
+ setPrices(oldPrices);
+ }
+ } else {
+ const { error } = await supabase.from("quoteLinePrice").insert([
+ {
+ ...newPrices[quantity],
+ },
+ ]);
+ if (error) {
+ setPrices(oldPrices);
+ }
}
};