Kaizen
Browse modulesPricingpricing/sharedFunctions

Function: resolvePerUnitQualification()

function resolvePerUnitQualification<TContext extends EvaluatePricingContext>(partitioned: PricingEvaluationResult<TContext>, options?: ResolvePerUnitQualificationOptions<TContext>): PricingEvaluationResult<TContext>;

Defined in: shared/pricing/qualify.ts:174

Attach qualification to each line-level MatchedPricingRule so calculatePrices can scale per-unit actions by the sub-units that actually satisfy the rule's condition_logic. Pure — depends only on its inputs.

Sub-units are enumerated per line (not per matched rule), using the union of every matched rule's date-range-declaring conditions as the line's effective span. Each matched rule's condition_logic tree is then walked per sub-unit:

  • Variable conditions (DATE_INCLUDES today) are re-evaluated against a narrowed line context — only the date fields the condition reads are overwritten to the sub-unit's window.
  • Whole-line conditions inherit the engine's match-time boolean (rule matched → those leaves are true).

Returns a shallow clone of the partitioned result with matchedByLineItem rebuilt; matchedByLevel.line, matchedByPhase.* line entries, and matched[] are updated to point at the same enhanced rule references. Order-level rules and non-line entries pass through untouched.

If conditionsTable is unset on the partitioned result, no qualification can be computed (there's no way to resolve condition_id leaves to their definitions) and the pass returns the result unchanged.

Type Parameters

Type Parameter
TContext extends EvaluatePricingContext

Parameters

ParameterType
partitionedPricingEvaluationResult<TContext>
optionsResolvePerUnitQualificationOptions<TContext>

Returns

PricingEvaluationResult<TContext>

On this page