Skip to content

[W1][Report][5848][Cost Shares Breakdown] Add integration event OnBeforeUpdateCostShareBufFromInvAdjmtEntryOrder to override ShareOfCost #30137

Description

@mavohra

Why do you need this change?

We need to override the logic that calculates ShareOfCost inside procedure UpdateCostShareBufFromInvAdjmtEntryOrder of Report 5848 "Cost Shares Breakdown". The standard code uses:

ShareOfCost := ItemLedgEntry.GetCostingQty / OutputQty;

But custom costing scenarios require different logic to calculate the cost share correctly.

All subsequent updates to Capacity, "Capacity Overhead", "Material Overhead", and Subcontracted depend on ShareOfCost being calculated correctly at this point. There is no way to correct these values later without re-entering the procedure. No event currently exists before the ShareOfCost calculation that allows subscribers to override or skip the standard logic.

Describe the request

Add an integration event OnBeforeUpdateCostShareBufFromInvAdjmtEntryOrder in procedure UpdateCostShareBufFromInvAdjmtEntryOrder before the ShareOfCost assignment.

local procedure UpdateCostShareBufFromInvAdjmtEntryOrder(ItemLedgEntry: Record "Item Ledger Entry"; var CostShareBuffer: Record "Cost Share Buffer")
var
    InvtAdjmtEntryOrder: Record "Inventory Adjmt. Entry (Order)";
    CalcInvtAdjmtOrder: Codeunit "Calc. Inventory Adjmt. - Order";
    ShareOfCost: Decimal;
    OutputQty: Decimal;
    IsHandled: Boolean;
begin
    if not InvtAdjmtEntryOrder.Get(ItemLedgEntry."Order Type", ItemLedgEntry."Order No.", ItemLedgEntry."Order Line No.") then
        exit;

    OutputQty := CalcInvtAdjmtOrder.CalcOutputQty(InvtAdjmtEntryOrder, false);
    CalcInvtAdjmtOrder.CalcActualUsageCosts(InvtAdjmtEntryOrder, OutputQty, InvtAdjmtEntryOrder);

IsHandled := false;
OnBeforeUpdateCostShareBufFromInvAdjmtEntryOrder(ItemLedgEntry, CostShareBuffer, InvtAdjmtEntryOrder, OutputQty, ShareOfCost, IsHandled);
    if not IsHandled then
        if OutputQty <> 0 then begin
            ShareOfCost := ItemLedgEntry.Quantity / OutputQty;
            CostShareBuffer.Capacity *= ShareOfCost;
            CostShareBuffer."Capacity Overhead" *= ShareOfCost;
            CostShareBuffer."Material Overhead" *= ShareOfCost;
            CostShareBuffer.Subcontracted *= ShareOfCost;
        end;
end;

Event Signature:

[IntegrationEvent(false, false)]
local procedure OnBeforeUpdateCostShareBufFromInvAdjmtEntryOrder(
    ItemLedgEntry: Record "Item Ledger Entry";
    var CostShareBuffer: Record "Cost Share Buffer";
    var InvtAdjmtEntryOrder: Record "Inventory Adjmt. Entry (Order)";
    OutputQty: Decimal;
    var ShareOfCost: Decimal;
    var IsHandled: Boolean)
begin
end;

Alternatives evaluated:
The existing code always uses ShareOfCost := ItemLedgEntry.Quantity / OutputQty, so subscribers cannot replace the calculation with custom logic. No event currently exists before the ShareOfCost computation in UpdateCostShareBufFromInvAdjmtEntryOrder.
Internal work item: AB#639379

Metadata

Metadata

Assignees

No one assigned

    Labels

    SCMGitHub request for SCM areaevent-requestRequest for adding an eventext-ready-to-implementReviewed and ready to implement and create PR

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions