Skip to content

[Bug]: A regression was introduced in codeunit 7002 "Price Calculation - V16" in procedure PickBestLine. #7209

@AlexCeg

Description

@AlexCeg

Describe the issue

A regression was introduced with BC27.5 in codeunit 7002 "Price Calculation - V16" in procedure PickBestLine.

With the recent change, the logic for AmountType::Discount no longer considers IsImprovedLine and IsDegradedLine, which previously ensured that more specific price list lines (e.g. with Variant Code or Currency Code) were preferred over less specific ones.

As a result, more specific discounts are no longer selected correctly.


🔁 Regression

Yes – this is a regression compared to the previous implementation.

Previous behavior

The selection logic applied both:

  • IsImprovedLine
  • IsDegradedLine
  • IsBetterLine

This ensured that:

  • More specific lines override generic ones
  • Best discount is chosen within the correct specificity level

Current behavior

For AmountType::Discount, only IsBetterLine is evaluated:

if AmountType = AmountType::Discount then begin
    if IsBetterLine(PriceListLine, AmountType, BestPriceListLine) then begin
        BestPriceListLine := PriceListLine;
        FoundBestLine := true;
    end;
end;

This skips specificity handling entirely.

Expected behavior

❗ Expected Behavior

More specific discount lines (e.g. with Variant Code, Currency Code, or other filters) should be prioritized over less specific ones, even if the discount percentage is equal or slightly lower.

❌ Actual Behavior

Generic discount lines can override more specific ones because specificity is no longer evaluated.

This leads to:

  • Incorrect discount selection
  • Loss of business logic consistency
  • Breaking changes for existing implementations relying on specificity

Steps to reproduce

🔬 Steps to Reproduce

  1. Create two price list lines:

    • Line A: Generic (no Variant Code), Discount = 10%
    • Line B: Specific (with Variant Code), Discount = 20% (or even slightly lower)
  2. Trigger price calculation

  3. Observe that:

    • Discount 20% is selected
    • The generic line is selected instead of the specific one

Additional context

We have extended the pricing logic by introducing additional custom fields that increase the specificity of price list lines.

Before this change, these fields worked correctly in combination with the standard specificity logic (IsImprovedLine / IsDegradedLine). After the change, this logic is bypassed for discounts, which means our extensions no longer behave as intended.

This issue therefore affects all of our customers, as the discount calculation no longer respects specificity across both standard and custom fields. The result is systematically incorrect discount determination in real business scenarios.

I will provide a fix for a bug

  • I will provide a fix for a bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    SCMGitHub request for SCM area

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions