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: line price effects

Brad Barbine45e738c7ffd
diff --git a/apps/carbon/app/modules/sales/ui/Quotation/QuotationLineQuantities.tsx b/apps/carbon/app/modules/sales/ui/Quotation/QuotationLineQuantities.tsx
index 57c7753404..b54530b6aa 100644
--- a/apps/carbon/app/modules/sales/ui/Quotation/QuotationLineQuantities.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotation/QuotationLineQuantities.tsx
@@ -26,7 +26,6 @@ import {
type QuotationLineQuantity,
} from "~/modules/sales";
import { path } from "~/utils/path";
-import { useQuotationLinePriceEffects } from "./useQuotation";
type QuotationLineQuantitiesProps = {
quotationLine: QuotationLine;
@@ -44,8 +43,6 @@ const QuotationLineQuantities = ({
const navigate = useNavigate();
const [quotation] = useQuotation();
- const lineEffects = useQuotationLinePriceEffects();
- console.log({ lineEffects });
// TODO: use the currency of the quote
const formatter = new Intl.NumberFormat("en-US", {
diff --git a/apps/carbon/app/modules/sales/ui/Quotation/QuotationMaterialLines.tsx b/apps/carbon/app/modules/sales/ui/Quotation/QuotationMaterialLines.tsx
index 154fc32228..7bd4a2422d 100644
--- a/apps/carbon/app/modules/sales/ui/Quotation/QuotationMaterialLines.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotation/QuotationMaterialLines.tsx
@@ -38,7 +38,7 @@ const QuotationMaterialLines = ({
if (!lineId) throw new Error("lineId not found");
if (!operationId) throw new Error("operationId not found");
- const [, setQuotation] = useQuotation();
+ const [, setQuote] = useQuotation();
const { id: userId } = useUser();
const { supabase } = useSupabase();
@@ -155,7 +155,7 @@ const QuotationMaterialLines = ({
editableComponents={editableComponents}
onNewRow={() => navigate("material/new")}
onDataChange={(data) =>
- setQuotation((prev) => ({
+ setQuote((prev) => ({
...prev,
materials: prev.materials
.filter((m) => m.quoteOperationId !== operationId)
diff --git a/apps/carbon/app/modules/sales/ui/Quotation/useQuotation.tsx b/apps/carbon/app/modules/sales/ui/Quotation/useQuotation.tsx
index 306052e6c6..eec5db6cfe 100644
--- a/apps/carbon/app/modules/sales/ui/Quotation/useQuotation.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotation/useQuotation.tsx
@@ -1,4 +1,5 @@
-import { useStore as useValue } from "@nanostores/react";
+import type { Database } from "@carbon/database";
+import type { SupabaseClient } from "@supabase/supabase-js";
import { atom, computed } from "nanostores";
import { useNanoStore } from "~/hooks";
import type {
@@ -9,7 +10,8 @@ import type {
QuotationOperation,
} from "~/modules/sales";
-type Quote = {
+type QuoteStore = {
+ client?: SupabaseClient<Database>;
quote?: Quotation;
lines: QuotationLine[];
assemblies: QuotationAssembly[];
@@ -27,7 +29,8 @@ type LinePriceEffects = {
productionHours: Effect[];
};
-const $quotationStore = atom<Quote>({
+const $quotationStore = atom<QuoteStore>({
+ client: undefined,
quote: undefined,
lines: [],
assemblies: [],
@@ -35,17 +38,9 @@ const $quotationStore = atom<Quote>({
materials: [],
});
-const defaultEffects: LinePriceEffects = {
- materialCost: [],
- laborCost: [],
- overheadCost: [],
- setupHours: [],
- productionHours: [],
-};
-
-const $quotationLinePriceEffects = computed($quotationStore, (store: Quote) => {
- // vroom vroom
- if (!store.quote) return [];
+const $quotationLinePriceEffects = computed($quotationStore, (store) => {
+ if (!store.quote || !store.client)
+ return {} as Record<string, LinePriceEffects>;
const assembliesByLineId = store.assemblies?.reduce<
Record<string, QuotationAssembly[]>
@@ -80,7 +75,13 @@ const $quotationLinePriceEffects = computed($quotationStore, (store: Quote) => {
const linePriceEffects = store?.lines?.reduce<
Record<string, LinePriceEffects>
>((effects, line) => {
- effects[line.id] = { ...defaultEffects };
+ effects[line.id] = {
+ materialCost: [],
+ laborCost: [],
+ overheadCost: [],
+ setupHours: [],
+ productionHours: [],
+ };
let assembliesById = assembliesByLineId[line.id]?.reduce<
Record<string, QuotationAssembly>
@@ -250,6 +251,4 @@ const $quotationLinePriceEffects = computed($quotationStore, (store: Quote) => {
return linePriceEffects;
});
-export const useQuotation = () => useNanoStore<Quote>($quotationStore);
-export const useQuotationLinePriceEffects = () =>
- useValue($quotationLinePriceEffects);
+export const useQuotation = () => useNanoStore<QuoteStore>($quotationStore);
diff --git a/apps/carbon/app/routes/x+/quote+/$id.tsx b/apps/carbon/app/routes/x+/quote+/$id.tsx
index 869fc7df7d..39d9434407 100644
--- a/apps/carbon/app/routes/x+/quote+/$id.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$id.tsx
@@ -21,6 +21,7 @@ import {
import { useEffect } from "react";
import { IoMdAdd } from "react-icons/io";
import { CollapsibleSidebar } from "~/components/Layout";
+import { useSupabase } from "~/lib/supabase";
import { getLocationsList } from "~/modules/resources";
import {
QuotationExplorer,
@@ -101,6 +102,7 @@ export async function action({ request }: ActionFunctionArgs) {
}
export default function QuotationRoute() {
+ const { supabase } = useSupabase();
const {
quotation,
quotationLines,
@@ -112,6 +114,7 @@ export default function QuotationRoute() {
useEffect(() => {
setQuote({
+ client: supabase,
quote: quotation,
lines: quotationLines,
assemblies: quotationAssemblies,
@@ -125,6 +128,7 @@ export default function QuotationRoute() {
quotationOperations,
setQuote,
quotation,
+ supabase,
]);
const navigate = useNavigate();