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(sales): a shared quote can't be accepted with no items; Remove only shows on multi-item quotes

aashu59fa18223e14
diff --git a/apps/erp/app/routes/api+/sales.digital-quote.$id.tsx b/apps/erp/app/routes/api+/sales.digital-quote.$id.tsx
index d772f0f597..f63bd48337 100644
--- a/apps/erp/app/routes/api+/sales.digital-quote.$id.tsx
+++ b/apps/erp/app/routes/api+/sales.digital-quote.$id.tsx
@@ -92,6 +92,15 @@ export async function action(args: ActionFunctionArgs) {
const selectedLines = parseResult.data;
+ if (
+ !Object.values(selectedLines).some((line) => (line.quantity ?? 0) > 0)
+ ) {
+ return {
+ success: false,
+ message: "Select at least one item to accept the quote."
+ };
+ }
+
// Unauthenticated endpoint: the name becomes a storage key segment.
const uploadFileName =
file instanceof File ? safeStorageFileName(file.name) : null;
diff --git a/apps/erp/app/routes/share+/quote.$id.tsx b/apps/erp/app/routes/share+/quote.$id.tsx
index 4d692efc6b..abcbff295d 100644
--- a/apps/erp/app/routes/share+/quote.$id.tsx
+++ b/apps/erp/app/routes/share+/quote.$id.tsx
@@ -14,6 +14,7 @@ import {
CardHeader,
CardTitle,
cn,
+ DisabledReason,
generateHTML,
Heading,
HStack,
@@ -475,7 +476,23 @@ const LineItems = ({
<div className="flex items-center gap-x-4 justify-between flex-grow min-w-0">
{/* min-w-0 so a long item id wraps inside the card
instead of shoving the price out of it. */}
- <Heading className="min-w-0">{line.itemReadableId}</Heading>
+ <div className="flex min-w-0 items-center gap-2">
+ <Heading className="min-w-0">
+ {line.itemReadableId}
+ </Heading>
+ {selectedLines[line.id!]?.quantity === 0 &&
+ (pricingByLine[line.id!]?.length ?? 0) > 0 &&
+ ![
+ "Ordered",
+ "Partial",
+ "Expired",
+ "Cancelled"
+ ].includes(quote.status) && (
+ <Badge variant="secondary" className="shrink-0">
+ <Trans>Removed</Trans>
+ </Badge>
+ )}
+ </div>
<HStack spacing={4} className="shrink-0">
<MotionMoney
value={
@@ -580,7 +597,10 @@ const LinePricingOptions = ({
// Settlement money at the document currency's configured decimals.
const currencyDecimals = useCurrencyDecimals(quoteCurrency);
const percentFormatter = usePercentFormatter();
- const { quote } = useLoaderData<typeof loader>().data!;
+ const { quote, quoteLines } = useLoaderData<typeof loader>().data!;
+ // Removing the only item would just empty the quote; Reject covers that.
+ const canRemoveLine =
+ (quoteLines?.filter((quoteLine) => !!quoteLine.id).length ?? 0) > 1;
const [selectedValue, setSelectedValue] = useState<string | null>(
selectedLine?.quantity?.toString() ?? null
@@ -973,7 +993,8 @@ const LinePricingOptions = ({
</div>
)}
- {selectedLine.quantity !== 0 &&
+ {canRemoveLine &&
+ selectedLine.quantity !== 0 &&
!["Ordered", "Partial", "Expired", "Cancelled"].includes(
quote.status
) && (
@@ -989,7 +1010,7 @@ const LinePricingOptions = ({
}));
}}
>
- <Trans>Remove</Trans>
+ <Trans>Remove this item</Trans>
</Button>
</HStack>
)}
@@ -1198,6 +1219,11 @@ const Quote = ({ data }: { data: QuoteData }) => {
const convertedShippingCost =
(quote.exchangeRate ?? 1) * (quoteShipment?.shippingCost ?? 0);
const total = subtotal + tax + convertedShippingCost;
+ // Gate on items, not money: quote-level shipping keeps the total above zero
+ // even after the customer removes every item.
+ const hasSelectedItem = Object.values(selectedLines).some(
+ (line) => line.quantity > 0
+ );
const termsHTML = generateHTML(terms as JSONContent);
@@ -1347,15 +1373,24 @@ const Quote = ({ data }: { data: QuoteData }) => {
{companySettings?.digitalQuoteEnabled &&
quote?.status === "Sent" && (
<>
- <Button
- onClick={confirmQuoteModal.onOpen}
- size="lg"
- variant="primary"
- isDisabled={total === 0}
- className="w-full mt-8 text-lg"
+ <DisabledReason
+ className="w-full mt-8"
+ reason={
+ hasSelectedItem
+ ? undefined
+ : t`Select at least one item to accept the quote`
+ }
>
- <Trans>Accept Quote</Trans>
- </Button>
+ <Button
+ onClick={confirmQuoteModal.onOpen}
+ size="lg"
+ variant="primary"
+ isDisabled={!hasSelectedItem}
+ className="w-full text-lg"
+ >
+ <Trans>Accept Quote</Trans>
+ </Button>
+ </DisabledReason>
<Button
onClick={rejectQuoteModal.onOpen}
size="lg"
diff --git a/packages/database/supabase/functions/convert/index.ts b/packages/database/supabase/functions/convert/index.ts
index 74252db614..70f5c98fc4 100644
--- a/packages/database/supabase/functions/convert/index.ts
+++ b/packages/database/supabase/functions/convert/index.ts
@@ -610,6 +610,12 @@ serve(async (req: Request) => {
selectedLines[line.id].quantity > 0
);
+ // Never create an empty order: the share page gates Accept, but this
+ // payload comes from an unauthenticated endpoint.
+ if (selectedQuoteLines.length === 0) {
+ throw new Error("No quote lines selected to convert");
+ }
+
// Services are never shipped — a service-only order goes straight to
// "To Invoice" so it isn't stuck waiting on a shipment that can't happen.
const hasShippableLine = selectedQuoteLines.some(