Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ codeunit 7010 "Purch. Price Calc. Mgt."
BestPurchPrice: Record "Purchase Price";
BestPurchPriceFound: Boolean;
IsHandled: Boolean;
InMinQty: Boolean;
begin
IsHandled := false;
OnBeforeCalcBestDirectUnitCost(PurchPrice, BestPurchPrice, BestPurchPriceFound, IsHandled, SKU, Item);
Expand All @@ -307,30 +308,35 @@ codeunit 7010 "Purch. Price Calc. Mgt."
FoundPurchPrice := PurchPrice.Find('-');
if FoundPurchPrice then
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

if InMinQty then begin
OnCalcBestDirectUnitCostOnBeforeConvertPriceToVAT(PurchPrice);
ConvertPriceToVAT(
Vend."Prices Including VAT", Item."VAT Prod. Posting Group",
Vend."VAT Bus. Posting Group", PurchPrice."Direct Unit Cost");
ConvertPriceToUoM(PurchPrice."Unit of Measure Code", PurchPrice."Direct Unit Cost");
ConvertPriceLCYToFCY(PurchPrice."Currency Code", PurchPrice."Direct Unit Cost");

case true of
((BestPurchPrice."Currency Code" = '') and (PurchPrice."Currency Code" <> '')) or
((BestPurchPrice."Variant Code" = '') and (PurchPrice."Variant Code" <> '')):
begin
BestPurchPrice := PurchPrice;
BestPurchPriceFound := true;
end;
((BestPurchPrice."Currency Code" = '') or (PurchPrice."Currency Code" <> '')) and
((BestPurchPrice."Variant Code" = '') or (PurchPrice."Variant Code" <> '')):
if (BestPurchPrice."Direct Unit Cost" = 0) or
(CalcLineAmount(BestPurchPrice) > CalcLineAmount(PurchPrice))
then begin
BestPurchPrice := PurchPrice;
BestPurchPriceFound := true;
end;
end;
IsHandled := false;
OnCalcBestDirectUnitCostOnBeforeCaseStatement(PurchPrice, BestPurchPrice, BestPurchPriceFound, IsHandled, LineDiscPerCent);
if not IsHandled then
case true of
((BestPurchPrice."Currency Code" = '') and (PurchPrice."Currency Code" <> '')) or
((BestPurchPrice."Variant Code" = '') and (PurchPrice."Variant Code" <> '')):
begin
BestPurchPrice := PurchPrice;
BestPurchPriceFound := true;
end;
((BestPurchPrice."Currency Code" = '') or (PurchPrice."Currency Code" <> '')) and
((BestPurchPrice."Variant Code" = '') or (PurchPrice."Variant Code" <> '')):
if (BestPurchPrice."Direct Unit Cost" = 0) or
(CalcLineAmount(BestPurchPrice) > CalcLineAmount(PurchPrice))
then begin
BestPurchPrice := PurchPrice;
BestPurchPriceFound := true;
end;
end;
end;
until PurchPrice.Next() = 0;
IsHandled := false;
Expand All @@ -341,7 +347,7 @@ codeunit 7010 "Purch. Price Calc. Mgt."
// No price found in agreement
if not BestPurchPriceFound then begin
IsHandled := false;
OnCalcBestDirectUnitCostOnBeforeNoPriceFound(BestPurchPrice, Item, IsHandled);
OnCalcBestDirectUnitCostOnBeforeNoPriceFound(BestPurchPrice, Item, IsHandled, PriceInSKU, SKU);
if not IsHandled then begin
PriceInSKU := PriceInSKU and (SKU."Last Direct Cost" <> 0);
if PriceInSKU then
Expand Down Expand Up @@ -1120,7 +1126,17 @@ codeunit 7010 "Purch. Price Calc. Mgt."
end;

[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")
begin
end;

[IntegrationEvent(false, false)]
local procedure OnCalcBestDirectUnitCostOnAfterIsInMinQty(var PurchasePrice: Record "Purchase Price"; QtyPerUOM: Decimal; Qty: Decimal; var InMinQty: Boolean)
begin
end;

[IntegrationEvent(false, false)]
local procedure OnCalcBestDirectUnitCostOnBeforeCaseStatement(var PurchasePrice: Record "Purchase Price"; var BestPurchasePrice: Record "Purchase Price"; var BestPurchPriceFound: Boolean; var IsHandled: Boolean; LineDiscPerCent: Decimal)
begin
end;

Expand Down
Loading