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): preserve quote line shipping cost on price rewrite

sidgaikwadfe710d02fbb4
diff --git a/.claude/rules/quote-discount-system.md b/.claude/rules/quote-discount-system.md
index 41b5ddf3cc..981060354e 100644
--- a/.claude/rules/quote-discount-system.md
+++ b/.claude/rules/quote-discount-system.md
@@ -68,7 +68,9 @@ Standalone rules, `id` default `id('pr')`, scoped to a company. Columns: `name`,
into `priceTrace`. The winning rule's id lands on `quoteLine.pricingRuleId`.
`upsertQuoteLinePrices` deletes and re-inserts rows, **preserving** the existing
-`discountPercent`, `leadTime`, and `categoryMarkups` per quantity when present.
+`discountPercent`, `leadTime`, `shippingCost`, and `categoryMarkups` per quantity
+when present. Any user-entered column added to `quoteLinePrice` has to be added
+to that carry-over list or the delete+reinsert silently resets it to its default.
## Types & UI
diff --git a/apps/erp/app/modules/sales/AGENTS.md b/apps/erp/app/modules/sales/AGENTS.md
index 09228af292..453d6145c7 100644
--- a/apps/erp/app/modules/sales/AGENTS.md
+++ b/apps/erp/app/modules/sales/AGENTS.md
@@ -27,7 +27,7 @@ Quotes (with cost rollup and pricing), sales orders, sales RFQs, customer manage
### Never
- Bypass the `convert` edge function for quote→order or RFQ→quote conversions.
-- Delete `quoteLinePrice` rows when *rewriting* a line's pricing — that must preserve `discountPercent`, `leadTime`, and `categoryMarkups` via `upsertQuoteLinePrices`. Deleting rows for a quantity break the line no longer offers is different and required: see `reconcileQuantityBreaks` (`sales.utils.ts`) and its use in `x+/quote+/$quoteId.$lineId.details.tsx`. Orphaned rows render as selectable options on the customer share page.
+- Delete `quoteLinePrice` rows when *rewriting* a line's pricing — that must preserve `discountPercent`, `leadTime`, `shippingCost`, and `categoryMarkups` via `upsertQuoteLinePrices`. Deleting rows for a quantity break the line no longer offers is different and required: see `reconcileQuantityBreaks` (`sales.utils.ts`) and its use in `x+/quote+/$quoteId.$lineId.details.tsx`. Orphaned rows render as selectable options on the customer share page.
- Store `discountPercent` as a whole number (e.g., 10 instead of 0.10).
## Validation Commands
diff --git a/apps/erp/app/modules/sales/sales.service.ts b/apps/erp/app/modules/sales/sales.service.ts
index 00f94f808e..799f9eecd7 100644
--- a/apps/erp/app/modules/sales/sales.service.ts
+++ b/apps/erp/app/modules/sales/sales.service.ts
@@ -3917,6 +3917,7 @@ export async function upsertQuoteLinePrices(
{
discountPercent: number;
leadTime: number;
+ shippingCost: number;
categoryMarkups: unknown;
priceSource: string;
}
@@ -3939,6 +3940,10 @@ export async function upsertQuoteLinePrices(
unitPrice: roundedUnitPrice,
discountPercent: existing?.discountPercent ?? p.discountPercent,
leadTime: existing?.leadTime ?? p.leadTime,
+ // Shipping is entered per quantity break and is independent of the price
+ // being rewritten — without this the delete+reinsert resets it to the
+ // column default of 0.
+ shippingCost: existing?.shippingCost ?? 0,
categoryMarkups: p.categoryMarkups ?? existing?.categoryMarkups ?? {},
// Explicit caller intent wins; otherwise keep the row's provenance so a
// delete+reinsert can never turn a manual price back into a system one.