[Event Request] Codeunit 5870 "Calculate BOM Tree" - Procedure CalcAvailability - OnBeforeCheckAvailability
Describe the request
Please add an event OnBeforeCheckAvailability in the procedure CalcAvailability in Codeunit 5870 "Calculate BOM Tree"
local procedure CalcAvailability(var BOMBuffer: Record "BOM Buffer"; Input: Decimal; IsTest: Boolean): Boolean
var
ParentBOMBuffer: Record "BOM Buffer";
ExpectedQty: Decimal;
AvailQty: Decimal;
MaxTime: Integer;
IsHandled: Boolean;
begin
if BOMBuffer.Indentation = 0 then begin
if IsTest then
if TempMemoizedResult.Get(Input) then
exit(TempMemoizedResult.Output);
ResetUpdatedAvailability();
end;
MaxTime := 0;
ParentBOMBuffer := BOMBuffer;
while (BOMBuffer.Next() <> 0) and (ParentBOMBuffer.Indentation < BOMBuffer.Indentation) do
if ParentBOMBuffer.Indentation + 1 = BOMBuffer.Indentation then begin
TempItemAvailByDate.SetRange("Item No.", BOMBuffer."No.");
TempItemAvailByDate.SetRange(Date, BOMBuffer."Needed by Date");
TempItemAvailByDate.SetRange("Variant Code", BOMBuffer."Variant Code");
if LocationSpecific then
TempItemAvailByDate.SetRange("Location Code", BOMBuffer."Location Code");
TempItemAvailByDate.FindFirst();
if BOMBuffer."Calculation Formula" = BOMBuffer."Calculation Formula"::"Fixed Quantity" then begin
ExpectedQty := Round(BOMBuffer."Qty. per Parent", UOMMgt.QtyRndPrecision());
AvailQty := TempItemAvailByDate."Available Qty"
end
else begin
ExpectedQty := Round(BOMBuffer."Qty. per Parent" * Input, UOMMgt.QtyRndPrecision());
AvailQty := TempItemAvailByDate."Updated Available Qty";
end;
OnBeforeCheckAvailability(BOMBuffer, AvailQty, ExpectedQty, IsHandled); // <--- New Event
if IsHandled then
exit;
if AvailQty < ExpectedQty then begin // <---- This needs to be AvailQty <= ExpectedQty
if BOMBuffer."Is Leaf" then begin
if MarkBottleneck then begin
BOMBuffer.Bottleneck := true;
BOMBuffer.Modify(true);
end;
BOMBuffer := ParentBOMBuffer;
if (BOMBuffer.Indentation = 0) and IsTest then
AddMemoizedResult(Input, false);
exit(false);
end;
if AvailQty <> 0 then
ReduceAvailability(BOMBuffer."No.", BOMBuffer."Variant Code", BOMBuffer."Location Code", BOMBuffer."Needed by Date", AvailQty, BOMBuffer."Calculation Formula");
if not IsTest then begin
BOMBuffer."Available Quantity" := AvailQty;
BOMBuffer.Modify();
end;
if not CalcAvailability(BOMBuffer, ExpectedQty - AvailQty, IsTest) then begin
if MarkBottleneck then begin
BOMBuffer.Bottleneck := true;
BOMBuffer.Modify(true);
end;
BOMBuffer := ParentBOMBuffer;
if (BOMBuffer.Indentation = 0) and IsTest then
AddMemoizedResult(Input, false);
exit(false);
end;
if not IsTest then
if MaxTime < (ParentBOMBuffer."Needed by Date" - BOMBuffer."Needed by Date") + BOMBuffer."Rolled-up Lead-Time Offset" then
MaxTime := (ParentBOMBuffer."Needed by Date" - BOMBuffer."Needed by Date") + BOMBuffer."Rolled-up Lead-Time Offset";
end else begin
if not IsTest then begin
if BOMBuffer."Calculation Formula" <> BOMBuffer."Calculation Formula"::"Fixed Quantity" then begin
BOMBuffer."Available Quantity" := ExpectedQty;
BOMBuffer.Modify();
end;
if MaxTime < (ParentBOMBuffer."Needed by Date" - BOMBuffer."Needed by Date") + BOMBuffer."Rolled-up Lead-Time Offset" then
MaxTime := (ParentBOMBuffer."Needed by Date" - BOMBuffer."Needed by Date") + BOMBuffer."Rolled-up Lead-Time Offset";
end;
ReduceAvailability(BOMBuffer."No.", BOMBuffer."Variant Code", BOMBuffer."Location Code", BOMBuffer."Needed by Date", ExpectedQty, BOMBuffer."Calculation Formula");
end;
end;
BOMBuffer := ParentBOMBuffer;
BOMBuffer."Rolled-up Lead-Time Offset" := MaxTime;
BOMBuffer.Modify(true);
if (BOMBuffer.Indentation = 0) and IsTest then
AddMemoizedResult(Input, true);
exit(true);
end;
[IntegrationEvent(false, false)]
local procedure OnBeforeCheckAvailability(var BOMBuffer: Record "BOM Buffer"; var AvailQty: Decimal; var ExpectedQty: Decimal; var IsHandled: Boolean)
begin
end;
Additional context
We need to replace the base logic if AvailQty < ExpectedQty with our custom logic if AvailQty <= ExpectedQty at line No. 802 in the procedure CalcAvailability.
Internal work item: AB#564681
Hello @mavohra If you need just change in the condition, we can set DoProcess := AvailQty < ExpectedQty OnBeforeProcess(BOMBuffer, AvailQty, ExpectedQty, VAR DoProcess) //<--------- you will be able to update DoProcess instead if AvailQty < ExpectedQty then begin // <---- This needs to be AvailQty <= ExpectedQty
And avoid "exit" in the middle of the while-do loop If this does not fit your need, I would suggest overriding whole procedure as it would be much cleaner
Hi @AleksandricMarko
Yes, we only need to modify the condition. The suggested event OnBeforeProcess(BOMBuffer, AvailQty, ExpectedQty, VAR DoProcess) should work for us.
Thanks for reporting this. We agree, and we’ll publish a fix asap, either in an update for the current version or in the next major release. Please do not reply to this, as we do not monitor closed issues. If you have follow-up questions or requests, please create a new issue where you reference this one.
Build ID: 31690.