Skip to content

[Extensibility Request] issue 30264: add and extend events in CalcBestDirectUnitCost#9448

Open
AleksandricMarko wants to merge 2 commits into
mainfrom
ai-ext-fix/ext_issue-30264
Open

[Extensibility Request] issue 30264: add and extend events in CalcBestDirectUnitCost#9448
AleksandricMarko wants to merge 2 commits into
mainfrom
ai-ext-fix/ext_issue-30264

Conversation

@AleksandricMarko

@AleksandricMarko AleksandricMarko commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Summary

The author needs to customize purchase price selection in CalcBestDirectUnitCost (codeunit 7010 "Purch. Price Calc. Mgt.") on a per-price-record basis - deciding which quantity the minimum-quantity check compares against, applying a different best-price selection rule, and intercepting the no-price fallback cost. The existing events do not expose the required in-scope state (the current Purchase Price record, the current best price, or PriceInSKU/SKU) at the right points, forcing subscribers to re-implement whole loops. This PR adds two new integration events inside the selection loop and extends one existing event so subscribers can override these decisions without duplicating internal logic.

Source issue repository: microsoft/AlAppExtensions; issue number: 30264

Changes Made

  • OnCalcBestDirectUnitCostOnAfterIsInMinQty - new integration event raised right after the IsInMinQty call in the loop, exposing the PurchasePrice record, QtyPerUOM, Qty, and the min-quantity var Boolean result so subscribers can override which quantity the minimum is checked against per price record. The IsInMinQty result is now stored in a new local InMinQty variable that drives the loop.
  • OnCalcBestDirectUnitCostOnBeforeCaseStatement - new integration event raised after the price conversions and before the case true of selection block, exposing PurchasePrice, BestPurchasePrice, BestPurchPriceFound, a var IsHandled skip flag, and LineDiscPerCent so subscribers can replace the best-price selection rule; the standard case block runs only when IsHandled is false.
  • OnCalcBestDirectUnitCostOnBeforeNoPriceFound - extended with var PriceInSKU: Boolean and var StockkeepingUnit: Record "Stockkeeping Unit" appended to the signature so subscribers can intercept the no-price fallback with full knowledge of the SKU state; the call site now passes PriceInSKU and SKU.

Fixes AB#641452

…of Purch. Price Calc. Mgt.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@AleksandricMarko AleksandricMarko added event-request SCM GitHub request for SCM area labels Jul 14, 2026
@github-actions github-actions Bot modified the milestone: Version 29.0 Jul 14, 2026
@AleksandricMarko
AleksandricMarko marked this pull request as ready for review July 15, 2026 18:40
@AleksandricMarko
AleksandricMarko requested a review from a team July 15, 2026 18:40
@github-actions

Copy link
Copy Markdown
Contributor

Copilot PR Review

Iteration 1 · Outcome: completed

Knowledge source: https://github.com/microsoft/BCQuality@186d8a131465475c79244d994acb872cd5c0d4bf

Findings by domain

Findings split into Knowledge-backed (cite a BCQuality article) and Agent (the agent's own judgement, no matching BCQuality rule).

Domain Findings Knowledge-backed Agent Inline Fallback
Events 1 1 0 1 0

Totals: 1 knowledge-backed · 0 agent findings.

Orchestrator pre-filter (2 file(s) excluded)

  • layer-disabled (knowledge) : 2 file(s)

Findings produced by the AL review agent v1.7.3. Reply 👎 on any inline comment to flag false positives.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Stale Status Check Deleted

The Pull Request Build workflow run for this PR was older than 72 hours and has been deleted.

📋 Why was it deleted?

Status checks that are too old may no longer reflect the current state of the target branch. To ensure this PR is validated against the latest code and passes up-to-date checks, a fresh build is required.


🔄 How to trigger a new status check:

  1. 📤 Push a new commit to the PR branch, or
  2. 🔁 Close and reopen the PR

This will automatically trigger a new Pull Request Build workflow run.

PredragMaricic
PredragMaricic previously approved these changes Jul 20, 2026
qasimikram
qasimikram previously approved these changes Jul 23, 2026

@qasimikram qasimikram left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The three publisher changes match the linked request and expose the required state at the intended decision points.

S1: Please add regression coverage for the new override paths. Include multiple candidate prices and verify default behavior, an overridden InMinQty result, and a handled selection that updates both BestPurchPrice and BestPurchPriceFound; also cover the extended no-price fallback context.

auto-merge was automatically disabled July 23, 2026 16:54

Pull request was closed

Comment thread src/Layers/W1/BaseApp/Purchases/Pricing/PurchPriceCalcMgt.Codeunit.al Outdated
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

[IntegrationEvent(false, false)]
local procedure OnCalcBestDirectUnitCostOnBeforeNoPriceFound(var PurchasePrice: Record "Purchase Price"; Item: Record Item; var IsHandled: Boolean)
local procedure OnCalcBestDirectUnitCostOnBeforeNoPriceFound(var PurchasePrice: Record "Purchase Price"; Item: Record Item; var IsHandled: Boolean; var PriceInSKU: Boolean; var StockkeepingUnit: Record "Stockkeeping Unit")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$\textbf{🟠\ High\ Severity\ —\ Breaking\ Changes}$

The existing published IntegrationEvent "OnCalcBestDirectUnitCostOnBeforeNoPriceFound" changed its shipped signature by adding the new var parameters "PriceInSKU" and "StockkeepingUnit". Extensions that already subscribe to the old 3-parameter event will no longer compile or bind correctly. Keep the existing event signature unchanged and introduce a new companion event for the extra context instead.

Knowledge:

👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.15.4


[IntegrationEvent(false, false)]
local procedure OnCalcBestDirectUnitCostOnBeforeNoPriceFound(var PurchasePrice: Record "Purchase Price"; Item: Record Item; var IsHandled: Boolean)
local procedure OnCalcBestDirectUnitCostOnBeforeNoPriceFound(var PurchasePrice: Record "Purchase Price"; Item: Record Item; var IsHandled: Boolean; var PriceInSKU: Boolean; var StockkeepingUnit: Record "Stockkeeping Unit")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$\textbf{🟡\ Medium\ Severity\ —\ Events}$

The new and changed event signatures introduce abbreviated subscriber-facing parameter names such as PriceInSKU, InMinQty, BestPurchPriceFound, and LineDiscPerCent. Event parameter names are part of the contract subscribers code against, so spell them out to make the publishers self-explanatory before this surface ships.

Knowledge:

👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.15.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

event-request SCM GitHub request for SCM area

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants