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: use netUnitPrice when converting quote to sales order

Rob Carrington10fe8049da77
diff --git a/apps/carbon/app/modules/sales/sales.models.ts b/apps/carbon/app/modules/sales/sales.models.ts
index 6898441dbf..33b1d4cb9d 100644
--- a/apps/carbon/app/modules/sales/sales.models.ts
+++ b/apps/carbon/app/modules/sales/sales.models.ts
@@ -679,7 +679,7 @@ const selectedLineSchema = z.object({
addOn: z.number(),
leadTime: z.number(),
quantity: z.number(),
- unitPrice: z.number(),
+ netUnitPrice: z.number(),
});
export const selectedLinesValidator = z.record(z.string(), selectedLineSchema);
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteToOrderModal.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteToOrderModal.tsx
index 1c9f1a0463..42b0d961f2 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteToOrderModal.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteToOrderModal.tsx
@@ -80,7 +80,7 @@ const QuoteToOrderDrawer = ({
string,
{
quantity: number;
- unitPrice: number;
+ netUnitPrice: number;
addOn: number;
leadTime: number;
}
@@ -348,7 +348,7 @@ type LinePricingFormProps = {
string,
{
quantity: number;
- unitPrice: number;
+ netUnitPrice: number;
addOn: number;
leadTime: number;
}
@@ -428,7 +428,7 @@ type LinePricingOptionsProps = {
string,
{
quantity: number;
- unitPrice: number;
+ netUnitPrice: number;
addOn: number;
leadTime: number;
}
@@ -451,7 +451,7 @@ const LinePricingOptions = ({
quantity: 1,
leadTime: 0,
addOn: 0,
- unitPrice: 0,
+ netUnitPrice: 0,
});
useEffect(() => {
@@ -460,7 +460,7 @@ const LinePricingOptions = ({
...prev,
[line.id!]: {
quantity: overridePricing.quantity,
- unitPrice: overridePricing.unitPrice,
+ netUnitPrice: overridePricing.netUnitPrice,
addOn: overridePricing.addOn,
leadTime: overridePricing.leadTime,
},
@@ -497,7 +497,7 @@ const LinePricingOptions = ({
...prev,
[line.id!]: {
quantity: selectedOption.quantity,
- unitPrice: selectedOption.unitPrice,
+ netUnitPrice: selectedOption.netUnitPrice ?? 0,
addOn:
additionalChargesByQuantity[selectedOption.quantity] || 0,
leadTime: selectedOption.leadTime,
@@ -591,15 +591,15 @@ const LinePricingOptions = ({
<Td>
<NumberField
className="w-[120px]"
- value={overridePricing.unitPrice}
+ value={overridePricing.netUnitPrice}
formatOptions={{
style: "currency",
currency: quoteCurrency,
}}
- onChange={(unitPrice) =>
+ onChange={(netUnitPrice) =>
setOverridePricing((v) => ({
...v,
- unitPrice,
+ netUnitPrice,
}))
}
>
@@ -654,7 +654,7 @@ const LinePricingOptions = ({
</Td>
<Td>
{formatter.format(
- overridePricing.unitPrice * overridePricing.quantity +
+ overridePricing.netUnitPrice * overridePricing.quantity +
overridePricing.addOn
)}
</Td>
diff --git a/packages/database/supabase/functions/convert/index.ts b/packages/database/supabase/functions/convert/index.ts
index 6c575cb0dd..3e24a556a9 100644
--- a/packages/database/supabase/functions/convert/index.ts
+++ b/packages/database/supabase/functions/convert/index.ts
@@ -23,7 +23,7 @@ const payloadValidator = z
z.string(),
z.object({
quantity: z.number(),
- unitPrice: z.number(),
+ netUnitPrice: z.number(),
addOn: z.number(),
leadTime: z.number(),
})
@@ -59,12 +59,13 @@ serve(async (req: Request) => {
switch (type) {
case "quoteToSalesOrder": {
- const [quote, quoteLines, quotePayment, quoteShipping] =
+ const [quote, quoteLines, quotePayment, quoteShipping, company] =
await Promise.all([
client.from("quote").select("*").eq("id", id).single(),
client.from("quoteLine").select("*").eq("quoteId", id),
client.from("quotePayment").select("*").eq("id", id).single(),
client.from("quoteShipment").select("*").eq("id", id).single(),
+ client.from("company").select("*").eq("id", companyId).single(),
]);
if (quote.error) throw new Error(`Quote with id ${id} not found`);
@@ -99,7 +100,10 @@ serve(async (req: Request) => {
status: "Draft",
createdBy: userId,
companyId: companyId,
- currencyCode: quote.data.currencyCode ?? undefined,
+ currencyCode:
+ quote.data.currencyCode ??
+ company.data?.baseCurrencyCode ??
+ "USD",
},
])
.returning(["id"])
@@ -147,7 +151,7 @@ serve(async (req: Request) => {
saleQuantity: selectedLines![line.id!].quantity,
status: "Ordered",
unitOfMeasureCode: line.unitOfMeasureCode,
- unitPrice: selectedLines![line.id!].unitPrice,
+ unitPrice: selectedLines![line.id!].netUnitPrice,
promisedDate: format(
new Date(
Date.now() +
@@ -259,31 +263,28 @@ serve(async (req: Request) => {
throw new Error(`Sales RFQ Lines with id ${id} not found`);
}
- const [customerPayment, customerShipping, employee] = await Promise.all(
- [
- client
- .from("customerPayment")
- .select("*")
- .eq("customerId", salesRfq.data.customerId)
- .single(),
- client
- .from("customerShipping")
- .select("*")
- .eq("customerId", salesRfq.data.customerId)
- .single(),
- client
- .from("employeeJob")
- .select("*")
- .eq("employeeId", userId)
- .eq("companyId", companyId),
- ]
- );
+ const [customerPayment, customerShipping] = await Promise.all([
+ client
+ .from("customerPayment")
+ .select("*")
+ .eq("customerId", salesRfq.data.customerId)
+ .single(),
+ client
+ .from("customerShipping")
+ .select("*")
+ .eq("customerId", salesRfq.data.customerId)
+ .single(),
+ client
+ .from("employeeJob")
+ .select("*")
+ .eq("employeeId", userId)
+ .eq("companyId", companyId),
+ ]);
if (customerPayment.error) throw customerPayment.error;
if (customerShipping.error) throw customerShipping.error;
const {
- currencyCode,
paymentTermId,
invoiceCustomerId,
invoiceCustomerContactId,
@@ -341,7 +342,6 @@ serve(async (req: Request) => {
.insertInto("quotePayment")
.values({
id: quote.id,
- currencyCode: currencyCode ?? "USD",
invoiceCustomerId: invoiceCustomerId,
invoiceCustomerContactId: invoiceCustomerContactId,
invoiceCustomerLocationId: invoiceCustomerLocationId,