Skip to content

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

Open
AleksandricMarko wants to merge 1 commit into
mainfrom
ai-ext-fix/ext_issue-30264
Open

[Extensibility Request] issue 30264: add and extend events in CalcBestDirectUnitCost#9448
AleksandricMarko wants to merge 1 commit 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
repeat
if IsInMinQty(PurchPrice."Unit of Measure Code", PurchPrice."Minimum Quantity") then begin
InMinQty := IsInMinQty(PurchPrice."Unit of Measure Code", PurchPrice."Minimum Quantity");
OnCalcBestDirectUnitCostOnAfterIsInMinQty(PurchPrice, QtyPerUOM, Qty, InMinQty);

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} \quad \color{gray}{\texttt{\small Iteration\ 1}}$

The new OnCalcBestDirectUnitCostOnAfterIsInMinQty and OnCalcBestDirectUnitCostOnBeforeCaseStatement integration events are both raised inside the repeat...until loop that iterates over PurchPrice records (lines 310-341), so every subscriber now runs once per purchase price agreement row instead of once per call to CalcBestDirectUnitCost.

A subscriber doing non-trivial work multiplies its cost by the row count. Consider whether the per-row hook is genuinely required, or whether the extension point can be exposed once before/after the loop with enough context (a buffer or the full record set) for subscribers to act on.

Knowledge:

👍 useful · ❤️ especially valuable · 👎 wrong - reply with why

@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.

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.

1 participant