From 6c07216c64834c2b2073795c290276abe034d15d Mon Sep 17 00:00:00 2001 From: Scott Pouliot Date: Tue, 2 Jun 2026 10:27:11 -0400 Subject: [PATCH] Fix custom formula item pricing: multiply by quantity, not divide ManualUnitPrice holds the per-item formula result. The previous code incorrectly treated it as the batch total and divided by Quantity, causing the unit price to shrink as quantity increased. Now follows the same pattern as every other ManualUnitPrice path in this method. Co-Authored-By: Claude Sonnet 4.6 --- .../Services/PricingCalculationService.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/PowderCoating.Application/Services/PricingCalculationService.cs b/src/PowderCoating.Application/Services/PricingCalculationService.cs index 5fbc1c6..8756c2a 100644 --- a/src/PowderCoating.Application/Services/PricingCalculationService.cs +++ b/src/PowderCoating.Application/Services/PricingCalculationService.cs @@ -299,15 +299,14 @@ public class PricingCalculationService : IPricingCalculationService } // Custom formula items (FixedRate mode): the wizard evaluated the NCalc formula server-side - // and stored the result as ManualUnitPrice. The formula result IS the total price — it already - // incorporates any quantity-like fields the user entered (e.g. numWheels, numParts). Do NOT - // multiply by Quantity again; doing so double-counts when the formula itself accounts for qty. + // and stored the per-item result as ManualUnitPrice. Multiply by Quantity for the total, + // exactly like every other item type that uses ManualUnitPrice. // SurfaceAreaSqFt mode: ManualUnitPrice is null; the formula produced sqft which was stored // in SurfaceAreaSqFt, so the item falls through to the standard calculated path below. if (item.IsCustomFormulaItem && item.ManualUnitPrice.HasValue) { - var formulaTotal = item.ManualUnitPrice.Value; - var formulaUnitPrice = item.Quantity > 0 ? formulaTotal / item.Quantity : formulaTotal; + var formulaUnitPrice = item.ManualUnitPrice.Value; + var formulaTotal = formulaUnitPrice * item.Quantity; return new QuoteItemPricingResult { MaterialCost = 0,