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 <noreply@anthropic.com>
This commit is contained in:
@@ -299,15 +299,14 @@ public class PricingCalculationService : IPricingCalculationService
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Custom formula items (FixedRate mode): the wizard evaluated the NCalc formula server-side
|
// 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
|
// and stored the per-item result as ManualUnitPrice. Multiply by Quantity for the total,
|
||||||
// incorporates any quantity-like fields the user entered (e.g. numWheels, numParts). Do NOT
|
// exactly like every other item type that uses ManualUnitPrice.
|
||||||
// multiply by Quantity again; doing so double-counts when the formula itself accounts for qty.
|
|
||||||
// SurfaceAreaSqFt mode: ManualUnitPrice is null; the formula produced sqft which was stored
|
// 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.
|
// in SurfaceAreaSqFt, so the item falls through to the standard calculated path below.
|
||||||
if (item.IsCustomFormulaItem && item.ManualUnitPrice.HasValue)
|
if (item.IsCustomFormulaItem && item.ManualUnitPrice.HasValue)
|
||||||
{
|
{
|
||||||
var formulaTotal = item.ManualUnitPrice.Value;
|
var formulaUnitPrice = item.ManualUnitPrice.Value;
|
||||||
var formulaUnitPrice = item.Quantity > 0 ? formulaTotal / item.Quantity : formulaTotal;
|
var formulaTotal = formulaUnitPrice * item.Quantity;
|
||||||
return new QuoteItemPricingResult
|
return new QuoteItemPricingResult
|
||||||
{
|
{
|
||||||
MaterialCost = 0,
|
MaterialCost = 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user