-
Notifications
You must be signed in to change notification settings - Fork 692
[Extensibility Request] Codeunit 99000758 "Mfg. Cost Calculation Mgt." - OnBeforeCalcOutputQtyBaseOnPurchOrder #29893
Description
Why do you need this change?
A client of us wants to calculate subcontracts for firm planned prod. orders, as he has this functionality in his old NAV Version.
We were already able to migrate most of the changes for it.
But for one section we would need a change in how the existing IsHandled pattern is implemented, I believe it was not intended to be this way.
In Codeunit "99000758 "Mfg. Cost Calculation Mgt." in the method "CalcOutputQtyBaseOnPurchOrder" that is called when calculating subcontracts and the Output Quantity Base is calculated when subscribing to the event "OnBeforeCalcOutputQtyBaseOnPurchOrder" when setting "IsHandled" to true and modify the "OutstandingBaseQty" the calculated "OutstandingBaseQty" is not properly returned to the caller only the "IsHandled" is checked and then method just exits.
Right now we have a work around for this by not setting "IsHandled", setting the "OutstandingBaseQty" in our subscriber and then essentially just copy pasted the standard code calcuated the Quantity again and subtracted it from our own calculation results, and then letting the standard code calculate the quantity again to essentially get B - A + A, which essentially we will just end up with the result of our calculation (B).
However this involes a lot of unnecessary database calls because the standard code calculation essentially needs to be done 2 times for our work around, therefore I request this change.
procedure CalcOutputQtyBaseOnPurchOrder(ProdOrderLine: Record "Prod. Order Line"; ProdOrderRtngLine: Record "Prod. Order Routing Line"): Decimal
var
PurchLine: Record "Purchase Line";
Item: Record Item;
UOMMgt: Codeunit "Unit of Measure Management";
OutstandingBaseQty: Decimal;
IsHandled: Boolean;
begin
IsHandled := false;
OutstandingBaseQty := 0;
OnBeforeCalcOutputQtyBaseOnPurchOrder(ProdOrderLine, ProdOrderRtngLine, OutstandingBaseQty, IsHandled);
#if not CLEAN26
CostCalculationMgt.RunOnBeforeCalcOutputQtyBaseOnPurchOrder(ProdOrderLine, ProdOrderRtngLine,
OutstandingBaseQty, IsHandled);
#endif
// this is the location that is probably not intended it always just returns 0, when subscribers handle the method.
if IsHandled then
exit;
PurchLine.SetCurrentKey("Document Type", Type, "Prod. Order No.", "Prod. Order Line No.", "Routing No.", "Operation No.");
PurchLine.SetRange("Document Type", PurchLine."Document Type"::Order);
PurchLine.SetRange(Type, PurchLine.Type::Item);
PurchLine.SetRange("Prod. Order No.", ProdOrderLine."Prod. Order No.");
PurchLine.SetRange("Prod. Order Line No.", ProdOrderLine."Line No.");
PurchLine.SetRange("Routing No.", ProdOrderRtngLine."Routing No.");
PurchLine.SetRange("Operation No.", ProdOrderRtngLine."Operation No.");
if PurchLine.Find('-') then
repeat
if Item."No." <> PurchLine."No." then
Item.Get(PurchLine."No.");
OutstandingBaseQty :=
OutstandingBaseQty +
UOMMgt.GetQtyPerUnitOfMeasure(Item, PurchLine."Unit of Measure Code") * PurchLine."Outstanding
Quantity";
until PurchLine.Next() = 0;
exit(OutstandingBaseQty);
end;
Describe the request
Instead of just checking IsHandled and then returning 0, the actual value of "OutstandingBaseQty" should be returned to the caller, so it is possible to properly leverage the existing events and calculate the "OutstandingBaseQty" and returning the result of the calculation to the caller.
So instead it should be like this.
procedure CalcOutputQtyBaseOnPurchOrder(ProdOrderLine: Record "Prod. Order Line"; ProdOrderRtngLine: Record "Prod. Order Routing Line"): Decimal
var
PurchLine: Record "Purchase Line";
Item: Record Item;
UOMMgt: Codeunit "Unit of Measure Management";
OutstandingBaseQty: Decimal;
IsHandled: Boolean;
begin
IsHandled := false;
OutstandingBaseQty := 0;
OnBeforeCalcOutputQtyBaseOnPurchOrder(ProdOrderLine, ProdOrderRtngLine, OutstandingBaseQty, IsHandled);
#if not CLEAN26
CostCalculationMgt.RunOnBeforeCalcOutputQtyBaseOnPurchOrder(ProdOrderLine, ProdOrderRtngLine,
OutstandingBaseQty, IsHandled);
#endif
// REQUESTED CHANGE ----->
if IsHandled then
exit(OutstandingBaseQty);
// REQUESTED CHANGE <------
PurchLine.SetCurrentKey("Document Type", Type, "Prod. Order No.", "Prod. Order Line No.", "Routing No.", "Operation No.");
PurchLine.SetRange("Document Type", PurchLine."Document Type"::Order);
PurchLine.SetRange(Type, PurchLine.Type::Item);
PurchLine.SetRange("Prod. Order No.", ProdOrderLine."Prod. Order No.");
PurchLine.SetRange("Prod. Order Line No.", ProdOrderLine."Line No.");
PurchLine.SetRange("Routing No.", ProdOrderRtngLine."Routing No.");
PurchLine.SetRange("Operation No.", ProdOrderRtngLine."Operation No.");
if PurchLine.Find('-') then
repeat
if Item."No." <> PurchLine."No." then
Item.Get(PurchLine."No.");
OutstandingBaseQty :=
OutstandingBaseQty +
UOMMgt.GetQtyPerUnitOfMeasure(Item, PurchLine."Unit of Measure Code") * PurchLine."Outstanding
Quantity";
until PurchLine.Next() = 0;
exit(OutstandingBaseQty);
end;