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.
Sales module fixes: implementation plan
Spec / source: .ai/specs/2026-10-01-sales-module-fixes.md
Branch: fix/sales-module (worktree /Users/aashu/work/carbon/carbon-fix-sales-module)
All commands run from the worktree root unless stated. Never commit: the user commits by hand. Every new user-facing string goes through Lingui (<Trans> or t`…` from useLingui()). Zod validator messages in *.models.ts are plain English strings across the codebase (e.g. sales.models.ts:86); follow that idiom.
Progress
- Task 1: Reject repeated quantity breaks in the quote line validator
- Task 2: Dedupe quantity breaks when reading (loader + pricing grid)
- Task 3: Add the shared
DisabledReasoncomponent andgetDisabledReasonhelper - Task 4: Fix the label column in the Costing and Pricing tables
- Task 5: Public quote page: "Remove this item", Removed badge, Accept gate
- Task 6: Server guards against empty quote acceptance
- Task 7: Rework the sales order job row
- Task 8: Disabled reasons on the quote header and the Convert drawer
- Task 9: Disabled reasons on the sales order header
- Task 10: Disabled reasons on the RFQ and return order headers
- Task 11: Extract and translate new strings
- Task 12: Full gates + browser verification
Dependencies
- Tasks 1, 2, 3, 4, 6 and 7 are independent of each other.
- Task 5 needs Task 3 (uses
DisabledReason). - Tasks 8, 9 and 10 need Task 3; they are independent of each other.
- Task 11 needs Tasks 1–10. Task 12 needs everything.
Task 1: Reject repeated quantity breaks in the quote line validator
Depends on: none Files:
- Modify:
apps/erp/app/modules/sales/sales.models.ts: thequantityfield ofquoteLineValidator(currently lines 493–495) - Modify:
apps/erp/app/modules/sales/sales.models.test.ts: add adescribe("quoteLineValidator quantity breaks")block - Copy from (precedent): the existing
vi.mock("@lingui/core/macro")+ dynamicawait import("./sales.models")setup at the top ofsales.models.test.ts
Steps:
- Replace the
quantityfield with:quantity: z .array( zfd.numeric(z.number().min(0.00001, { message: "Quantity is required" })) ) .refine((quantities) => new Set(quantities).size === quantities.length, { message: "Each quantity must be different" }), - In the test file, change the import line to
const { quoteValidator, quoteLineValidator } = await import("./sales.models");. Add two tests that callquoteLineValidator.shape.quantity.safeParse(...):[10, 10, 25]→success === false, anderror.issues[0].message === "Each quantity must be different".[10, 20, 25]→success === true.- If
quoteLineValidatoris not a plainz.object(no.shape), STOP and report; do not improvise.
- Confirm that
ArrayNumeric(packages/form/src/components/ArrayNumeric.tsx:58,104) shows the array-level error.useFieldArrayreturnserrorfor the field name. This is checked in the browser in Task 12.
Verify:
cd apps/erp && pnpm exec vitest run app/modules/sales/sales.models.test.ts
# Expected: all tests pass, including the 2 new quantity-break tests
Out of scope: the sales order line validator, CSV import code, database constraints.
Task 2: Dedupe quantity breaks when reading (loader + pricing grid)
Depends on: none Files:
- Modify:
apps/erp/app/routes/x+/quote+/$quoteId.$lineId.details.tsx: loader return, lines ~164–166 - Modify:
apps/erp/app/modules/sales/ui/Quotes/QuoteLinePricing.tsx: line 110
Steps:
- Loader: change
[...line.data.quantity].sort((a, b) => a - b)to[...new Set(line.data.quantity)].sort((a, b) => a - b). Extend the comment above it by one line:// Distinct: a line saved with a repeated break must not render twice (one price row per quantity). - Pricing grid line 110: change to
const quantities = [...new Set(line.quantity ?? [1])].sort((a, b) => a - b);. - Do not touch any write path.
Verify:
pnpm exec turbo run typecheck --filter=erp
# Expected: Tasks succeed, 0 errors
Out of scope: onRecalculate, rewriteQuoteLinePrices, the new-line route.
Task 3: Add the shared DisabledReason component and getDisabledReason helper
Depends on: none Files:
- Create:
packages/react/src/DisabledReason.tsx - Modify:
packages/react/src/index.tsx: import and exportDisabledReasonandgetDisabledReason, next to theTruncatedTooltipTextimport (line ~364) and export (line ~661) - Copy from (precedent):
apps/erp/app/modules/items/ui/ChangeNotice/ItemChangeNoticeLock.tsx:41-80
Steps:
- Create the file with the AGPL header used by every file in
packages/react/src(copy the 3 comment lines fromTruncatedTooltipText.tsx), then:import type { ReactNode } from "react"; import { Tooltip, TooltipContent, TooltipTrigger } from "./Tooltip"; import { cn } from "./utils/cn"; /** First reason whose condition holds, or undefined when nothing blocks. */ function getDisabledReason( checks: ReadonlyArray<readonly [blocked: boolean, reason: string]> ): string | undefined { return checks.find(([blocked]) => blocked)?.[1]; } type DisabledReasonProps = { reason?: ReactNode; className?: string; children: ReactNode; }; // A disabled <button> fires no pointer events, so the focusable span carries // the tooltip and gives keyboard users a tab stop to read it. function DisabledReason({ reason, className, children }: DisabledReasonProps) { if (!reason) return <>{children}</>; return ( <Tooltip> <TooltipTrigger asChild> <span tabIndex={0} className={cn("inline-flex", className)}> {children} </span> </TooltipTrigger> <TooltipContent>{reason}</TooltipContent> </Tooltip> ); } export { DisabledReason, getDisabledReason }; - Add both names to the barrel import and export lists, in alphabetical position.
Verify:
pnpm --filter @carbon/react typecheck && pnpm exec biome check packages/react/src/DisabledReason.tsx packages/react/src/index.tsx
# Expected: typecheck exits 0; biome reports no errors
Out of scope: changing Button's props; replacing existing local wrappers (ItemChangeNoticeLock, AssemblyBomTree).
Task 4: Fix the label column in the Costing and Pricing tables
Depends on: none Files:
- Create:
apps/erp/app/modules/sales/ui/Quotes/CostRowLabel.tsx - Modify:
apps/erp/app/modules/sales/ui/Quotes/QuoteLineCosting.tsx: headerTh(line 88) and every labelTd(lines 96, 133, 173, 203, 233, 263, 295, 322, 354, 382, 414, 443, 471, 500, 533) - Modify:
apps/erp/app/modules/sales/ui/Quotes/QuoteLinePricing.tsx: headerTh(line 888) and every labelTd(lines 896, 936, 973, 1019, 1045, 1087, 1114, 1140, 1158, 1194, 1222, 1260, 1350, 1388, 1408, 1436, 1464, 1482) - Copy from (precedent):
packages/react/src/TruncatedTooltipText.tsx(truncation + tooltip); flex-row rules fromapps/erp/app/modules/sales/ui/SalesOrder/SalesOrderSummary.tsx:409-413
Steps:
- Create
CostRowLabel.tsx(with the AGPL header):
Ifimport { cn, TruncatedTooltipText } from "@carbon/react"; import type { ReactNode } from "react"; type CostRowLabelProps = { label: ReactNode; /** Type marker shown before the label (icon or Enumerable badge). */ icon?: ReactNode; /** Inline help (e.g. an info tooltip) right after the label. */ info?: ReactNode; /** Trailing control pinned to the right (e.g. Predict lead time). */ action?: ReactNode; className?: string; }; export function CostRowLabel({ label, icon, info, action, className }: CostRowLabelProps) { return ( <div className={cn("flex w-full min-w-0 items-center gap-2", className)}> {icon && <span className="flex shrink-0 items-center">{icon}</span>} <TruncatedTooltipText tooltip={label} className="min-w-0 truncate"> {label} </TruncatedTooltipText> {info && <span className="flex shrink-0 items-center">{info}</span>} {action && <span className="ml-auto flex shrink-0 items-center">{action}</span>} </div> ); }cnorTruncatedTooltipTextis not exported from@carbon/react(checkpackages/react/src/index.tsx), STOP and report. - Sticky, stable label column. Define a module-level constant in each table file:
const labelCellClass = "sticky left-0 z-[1] bg-card min-w-[200px] w-[260px] max-w-[260px] border-r border-border";- Header: replace
<Th className="w-[300px]" />with<Th className={labelCellClass} />. - Every label
Td: replaceborder-r border-borderwith{labelCellClass}viacn(labelCellClass, <existing extra classes such as "pl-10" / "pl-14" / "pl-8" / "group-hover:bg-muted/50">). Keep the indent classes so the hierarchy still reads.
- Header: replace
- Replace each label cell's inner
HStack justify-betweenwithCostRowLabel:- Total rows (Costing):
icon={<Enumerable value="Material" />}(or Direct / Indirect / Outside, as the row has today) andlabel={<Trans>Total Material Cost</Trans>}. - Detail rows: move the existing
<MethodItemTypeIcon type=… />/<TimeTypeIcon type=… />/<LuClock />intoicon, rendered as a muted icon with noBadgewrapper (<span className="text-muted-foreground">…</span>). - Part Cost: keep its
LuInfotooltip, passed asinfo. - Pricing "Lead Time": move the Predict
IconButtonintoaction. - Pricing "Markup Percent": pass its
LuInfotooltip asinfo. - "Markup by Category" toggle
Button(Pricing ~1019–1035): keep the Button, but give itclassName="-ml-3 max-w-full"and wrap its text in<span className="truncate">. - "Total Estimated Cost" (Costing ~500):
<CostRowLabel label={<Trans>Total Estimated Cost</Trans>} className="font-medium" />. - Wrap every label string touched here in
<Trans>. Today they are bare English, e.g. "Lead Time" atQuoteLinePricing.tsx:898.
- Total rows (Costing):
- Remove now-unused imports (
Badge,HStack) only if nothing else in the file uses them. - If the
Tablewrapper (packages/react/src/Table.tsx:10-34) does not scroll horizontally (sticky needs the scroll container), STOP and report.
Verify:
pnpm exec turbo run typecheck --filter=erp && pnpm exec biome check apps/erp/app/modules/sales/ui/Quotes/
# Expected: 0 type errors; biome no errors
Visual check happens in Task 12.
Out of scope: the value cells, the cost maths, the Show Details switch.
Task 5: Public quote page: "Remove this item", Removed badge, Accept gate
Depends on: Task 3 Files:
- Modify:
apps/erp/app/routes/share+/quote.$id.tsx: Remove button (976–995), collapsed line header (476–500), Accept button (~1350–1358),@carbon/reactimport list (lines 9–42)
Steps:
- Remove button: change
<Trans>Remove</Trans>to<Trans>Remove this item</Trans>. Leave the behaviour unchanged. - Removed badge: in
LineItems, right after<Heading className="min-w-0">{line.itemReadableId}</Heading>, render:
Add{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> )}Badgeto the@carbon/reactimport if it is missing. If the Heading's parent flex row places the badge badly (e.g. after the price), put the Heading and Badge in<div className="flex min-w-0 items-center gap-2">. - Accept gate in the component that renders the Accept button (it has
selectedLinesandtotalin scope near line 1173):
Then wrap the Acceptconst hasSelectedItem = Object.values(selectedLines).some((l) => l.quantity > 0);Button:
Move<DisabledReason className="w-full" reason={hasSelectedItem ? undefined : t`Select at least one item to accept the quote`} > <Button … isDisabled={!hasSelectedItem} className="w-full mt-8 text-lg">mt-8onto theDisabledReasonclassName ("w-full mt-8") so spacing doesn't change. ImportDisabledReasonfrom@carbon/react. UsetfromuseLingui(), which is already imported at line 44; destructure it in that component if it isn't already.
Verify:
pnpm exec turbo run typecheck --filter=erp && pnpm exec biome check 'apps/erp/app/routes/share+/quote.$id.tsx'
# Expected: 0 errors
Out of scope: totals maths, the confirm modal, the reject flow.
Task 6: Server guards against empty quote acceptance
Depends on: none Files:
- Modify:
apps/erp/app/routes/api+/sales.digital-quote.$id.tsx: afterconst selectedLines = parseResult.data;(~line 93) - Modify:
packages/database/supabase/functions/convert/index.ts: right after theselectedQuoteLinesfilter (ends ~line 611)
Steps:
- In the route, insert:
if (!Object.values(selectedLines).some((line) => (line.quantity ?? 0) > 0)) { return { success: false, message: "Select at least one item to accept the quote." }; } - In the edge function, after
selectedQuoteLinesis defined, insert:
This runs inside theif (selectedQuoteLines.length === 0) { throw new Error("No quote lines selected to convert"); }trxtransaction, so the sequence draw above it rolls back. If the code at that point is not inside a transaction callback, STOP and report.
Verify:
pnpm exec turbo run typecheck --filter=erp && pnpm exec biome check 'apps/erp/app/routes/api+/sales.digital-quote.$id.tsx' packages/database/supabase/functions/convert/index.ts
# Expected: 0 errors
Out of scope: sales-rule evaluation, file upload handling, other convert cases.
Task 7: Rework the sales order job row
Depends on: none Files:
- Modify:
apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineJobs.tsx:SalesOrderJobItem(lines 288–387) - Modify:
apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderSummary.tsx: remove the@ts-expect-error TS2739at line 692 only if typecheck passes without it - Copy from (precedent): flex-row rules in
SalesOrderSummary.tsx:409-413; ID link styling fromapps/erp/app/components/Hyperlink.tsx:23-28(text-foreground font-medium)
Steps:
- Replace the
Hyperlinkwrapper with a plain React RouterLink:import { Link } from "react-router";(merge into the existingreact-routerimport),<Link to={path.to.job(job.id!)} prefetch="intent" className="text-sm font-medium text-foreground whitespace-nowrap hover:underline">{job.jobId}</Link>. Remove theHyperlinkimport if nothing else in the file uses it. - Restructure the top row (keep every existing prop, condition and handler):
Wrap the "Complete", "Shipped" and "Release" labels in<div className="@container w-full"> <div className="flex w-full flex-col gap-3 @xl:flex-row @xl:items-center"> {/* identity */} <div className="flex min-w-0 flex-1 flex-wrap items-center gap-2"> <Link …>{job.jobId}</Link> <JobStatus … /> {/* + Due Today / Overdue exactly as today */} </div> {/* facts + actions */} <div className="flex shrink-0 items-center gap-6"> <Assignee … /> <div className="w-20">Complete block (unchanged markup) + "tabular-nums" on the <p></div> <div className="w-20">Shipped block (unchanged markup) + "tabular-nums" on the <p></div> <div className="flex items-center gap-1">Release Button + chevron IconButton (unchanged)</div> </div> </div> </div><Trans>. Change the chevron'saria-labeltodisclosure.isOpen ? t`Collapse` : t`Expand`, withtfromuseLingui(). - Keep
{disclosure.isOpen && <JobDetails …/>}and the release modal below the row, unchanged. - If Tailwind container queries (
@container/@xl:) don't compile in apps/erp (checkapps/erp/app/components/Gantt/Gantt.tsxfor existing use), STOP and report.
Verify:
pnpm exec turbo run typecheck --filter=erp && pnpm exec biome check apps/erp/app/modules/sales/ui/SalesOrder/
# Expected: 0 errors
Out of scope: JobDetails, the Hyperlink component, the jobs tooltip list in SalesOrderSummary.tsx:495-552.
Task 8: Disabled reasons on the quote header and the Convert drawer
Depends on: Task 3 Files:
- Modify:
apps/erp/app/modules/sales/ui/Quotes/QuoteHeader.tsx: Finalize (245), Won (260), Lost (283), Cancel (311) - Modify:
apps/erp/app/modules/sales/ui/Quotes/QuoteToOrderDrawer.tsx: Next button (390), condition329)isNextButtonDisabled( - Copy from (precedent):
apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteToOrderDrawer.tsx:137-155
Steps:
- Import
DisabledReason, getDisabledReasonfrom@carbon/react.talready comes fromuseLingui()in QuoteHeader. - Compute the reasons before the JSX. Use
status = routeData?.quote?.statusandcanUpdate = permissions.can("update", "sales"):const finalizeReason = getDisabledReason([ [status !== "Draft", t`Only draft quotes can be finalized`], [!eligibleLines?.length, t`Add at least one line that can be quoted`], [!canUpdate, t`You don't have permission to update quotes`] ]); const wonReason = getDisabledReason([ [status !== "Sent", t`Only sent quotes can be marked as won`], [!canUpdate, t`You don't have permission to update quotes`] ]); const lostReason = getDisabledReason([ [status !== "Sent", t`Only sent quotes can be marked as lost`], [!canUpdate, t`You don't have permission to update quotes`] ]); const cancelReason = getDisabledReason([ [!canUpdate, t`You don't have permission to update quotes`] ]); - Wrap each
Buttonin<DisabledReason reason={xReason}>…</DisabledReason>. For Lost and Cancel, wrap theButtoninside thestatusFetcher.Form. Keep eachisDisabledexpression exactly as it is, including the fetcher-busy terms, so behaviour doesn't change. - Drawer: wrap the Next button with
<DisabledReason reason={isNextButtonDisabled ? tSelect at least one line to convert: undefined}>. - If any current
isDisabledexpression differs from what step 2 assumes, STOP and report the difference.
Verify:
pnpm exec turbo run typecheck --filter=erp && pnpm exec biome check apps/erp/app/modules/sales/ui/Quotes/QuoteHeader.tsx apps/erp/app/modules/sales/ui/Quotes/QuoteToOrderDrawer.tsx
# Expected: 0 errors
Out of scope: ⋯ menu items, Share/Preview, the modals' submit buttons.
Task 9: Disabled reasons on the sales order header
Depends on: Task 3 Files:
- Modify:
apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderHeader.tsx: Confirm (413), Cancel (432), Ship (526), Invoice (595)
Steps:
- Import
DisabledReason, getDisabledReasonfrom@carbon/react. Make suretis available fromuseLingui(); add it if not. - Reasons:
Use the local variable names the file already has for status, lines and permissions; read the surrounding code first.const confirmReason = getDisabledReason([ [!["Draft", "Needs Approval"].includes(status), t`Only draft orders can be confirmed`], [lines.length === 0, t`Add at least one line before confirming`], [!canUpdate, t`You don't have permission to update sales orders`] ]); const cancelReason = getDisabledReason([ [["Cancelled", "Closed", "Completed", "Invoiced"].includes(status), t`This order can no longer be cancelled`], [!canUpdate, t`You don't have permission to update sales orders`] ]); const shipReason = getDisabledReason([ [!["To Ship", "To Ship and Invoice"].includes(status), t`Confirm the order before shipping`] ]); const invoiceReason = getDisabledReason([ [!["To Invoice", "To Ship and Invoice"].includes(status), t`Confirm the order before invoicing`] ]); - Wrap each of the four Buttons in
DisabledReason. Leave theisDisabledexpressions unchanged. - If a condition differs from the above, STOP and report.
Verify:
pnpm exec turbo run typecheck --filter=erp && pnpm exec biome check apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderHeader.tsx
# Expected: 0 errors
Out of scope: ⋯ menu items (New Shipment, New Invoice, Convert Lines to Jobs, Reopen, Delete).
Task 10: Disabled reasons on the RFQ and return order headers
Depends on: Task 3 Files:
- Modify:
apps/erp/app/modules/sales/ui/SalesRFQ/SalesRFQHeader.tsx: Ready for Quote (two variants,151 and ~169), Quote (183), No Quote (~227) - Modify:
apps/erp/app/modules/sales/ui/SalesReturnOrders/SalesReturnOrderHeader.tsx: Confirm (182), Cancel (193), Receive (204), Ship (219), Issue Credit (235), Create Replacement (260)
Steps:
- Same imports and pattern as Task 9.
- RFQ reasons:
- Ready for Quote (customer variant):
[status !== "Draft", t\Only draft RFQs can be marked ready for quote`],[lines.length === 0, t`Add at least one line first`],[!canUpdate, t`You don't have permission to update RFQs`]`. - Ready for Quote (no-customer variant): use the actual status check in the code (
status !== "Ready for Quote"). Messaget\Only draft RFQs can be marked ready for quote``, plus the same lines and permission entries. - Quote:
[status !== "Ready for Quote", t\Mark the RFQ ready for quote first`],[lines.length === 0, t`Add at least one line first`],[!canCreate, t`You don't have permission to create quotes`]`. - No Quote:
[status !== "Ready for Quote", t\Mark the RFQ ready for quote first`],[!canUpdate, t`You don't have permission to update RFQs`]`.
- Ready for Quote (customer variant):
- Return order reasons:
- Confirm:
[lines.length === 0, t\Add at least one line before confirming`],[!canUpdate, t`You don't have permission to update return orders`]`. - Cancel:
[!canUpdate, …same…]. - Receive and Ship:
[!permissions.can("create","inventory"), t\You don't have permission to create inventory documents`]`. - Issue Credit:
[!permissions.can("create","invoicing"), t\You don't have permission to create credits`]`. - Create Replacement:
[!permissions.can("create","sales"), t\You don't have permission to create sales orders`]`. - Skip
isCreatingDocument/ fetcher-busy terms; they are loading states.
- Confirm:
- Leave the
isDisabledexpressions unchanged. If a condition differs, STOP and report.
Verify:
pnpm exec turbo run typecheck --filter=erp && pnpm exec biome check apps/erp/app/modules/sales/ui/SalesRFQ/SalesRFQHeader.tsx apps/erp/app/modules/sales/ui/SalesReturnOrders/SalesReturnOrderHeader.tsx
# Expected: 0 errors
Out of scope: ⋯ menu items.
Task 11: Extract and translate new strings
Depends on: Tasks 1–10 Steps:
pnpm lingui:extract, thenpnpm lingui:clean.- Run the repo's
translateskill to fill the emptymsgstrentries for the new strings.
Verify:
grep -c 'msgid "Select at least one item to accept the quote"' packages/locale/locales/es/erp.po
# Expected: 1
Out of scope: retranslating existing strings.
Task 12: Full gates + browser verification
Depends on: all Steps:
- Gates:
pnpm exec turbo run typecheck --filter=erp --filter=@carbon/react cd apps/erp && pnpm exec vitest run app/modules/sales pnpm exec biome check apps/erp/app/modules/sales 'apps/erp/app/routes/share+/quote.$id.tsx' 'apps/erp/app/routes/api+/sales.digital-quote.$id.tsx' packages/react/src/DisabledReason.tsx - Browser (needs
crbn upin this worktree; ask the user before booting the stack). Log in with theauthskill and walk through acceptance criteria 1–8 from the spec at 1440, 1024 and 390 px widths, taking screenshots into.ai/scratch/e2e/. - Write the carbon-design review summary (props audit, drift notes) in the final message.
Verify: every acceptance criterion is marked pass with screenshot evidence, or reported as failing with the output.