ALAppExtensions icon indicating copy to clipboard operation
ALAppExtensions copied to clipboard

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

Open mavohra opened this issue 6 months ago • 6 comments

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

mavohra avatar May 22 '26 11:05 mavohra

Hi @mavohra,

Thank you for your extensibility request. To help us process it efficiently, please update the issue to include the required information.

📚 Extensibility Guidelines

Missing Information:

  • Performance considerations: Describe the expected execution frequency of this IsHandled event and any anticipated performance impact.
  • Data sensitivity review: Confirm whether this event would expose any sensitive data, or explicitly state that it does not.
  • Multi-extension interaction considerations: Explain whether multiple subscribers could conflict when setting ShareOfCost or IsHandled, and how that risk should be handled.

Please update the issue with the missing details. We'll automatically re-analyze once updated.

[!NOTE] Automatically generated by the Triage Agent — advisory only. An engineer will review before any action is taken.

[!TIP] Not accurate? Reply with /not-accurate (optional: add a short explanation). Your feedback improves future responses.

github-actions[bot] avatar May 22 '26 13:05 github-actions[bot]

Performance considerations

The event fires once per item ledger entry during the Cost Shares Breakdown report, called from within the item ledger entry loop. It is [IntegrationEvent(false, false)] with six parameters. Overhead is negligible compared to the CalcActualUsageCosts call and cost buffer multiplication that follow in the same procedure.

Data sensitivity/security review

The event exposes only standard manufacturing costing fields: ItemLedgEntry (entry number, quantity, order references), CostShareBuffer (capacity and overhead cost decimals), InvtAdjmtEntryOrder (order-level costs), OutputQty, and ShareOfCost. No PII, no customer/vendor data, no financial dimensions. The event is [IntegrationEvent(false, false)]: no global context, no sender. Subscribers already need tableData permissions to the relevant tables to compile.

Multi-extension interaction assessment

Unlikely.

mavohra avatar Jun 01 '26 11:06 mavohra

Hi @mavohra,

Thank you for your extensibility request. To help us process it efficiently, please update the issue to include the required information.

📚 Extensibility Guidelines

Missing Information:

  • Implementation approach confirmation: Please confirm whether a refactoring-based implementation is acceptable here, where the 5-line ShareOfCost calculation/update block is first extracted into a separate procedure and then wrapped with an OnBeforeUpdateCostShareBufFromInvAdjmtEntryOrder(..., var IsHandled) event. This clarification is needed because the requested IsHandled pattern currently bypasses a cohesive multi-line calculation block.

Please update the issue with the missing details. We'll automatically re-analyze once updated.

[!NOTE] Automatically generated by the Triage Agent — advisory only. An engineer will review before any action is taken.

[!TIP] Not accurate? Reply with /not-accurate (optional: add a short explanation). Your feedback improves future responses.

github-actions[bot] avatar Jun 01 '26 20:06 github-actions[bot]

Yes, extracting the ShareOfCost calculation and buffer multiplication block into a dedicated local procedure with an IsHandled event before it is acceptable.

mavohra avatar Jun 17 '26 11:06 mavohra

✅ Analysis complete - ready for further processing


Implementation:

Extract the ShareOfCost calculation and cost-share buffer multiplication into a dedicated local procedure, and add a new IsHandled integration event before the standard logic is applied.

Location in UpdateCostShareBufFromInvAdjmtEntryOrder() procedure:

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

        CostShareBuffer.Capacity += InvtAdjmtEntryOrder."Single-Level Capacity Cost";
        CostShareBuffer."Capacity Overhead" += InvtAdjmtEntryOrder."Single-Level Cap. Ovhd Cost";
        CostShareBuffer."Material Overhead" += InvtAdjmtEntryOrder."Single-Level Mfg. Ovhd Cost";
        CostShareBuffer.Subcontracted += InvtAdjmtEntryOrder."Single-Level Subcontrd. Cost";

        ApplyShareOfCostToCostShareBuffer(ItemLedgEntry, CostShareBuffer, InvtAdjmtEntryOrder, OutputQty, ShareOfCost);
    end;

    local procedure ApplyShareOfCostToCostShareBuffer(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
        IsHandled := false;
        OnUpdateCostShareBufFromInvAdjmtEntryOrderOnBeforeApplyShareOfCost(
            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 Publisher (add at the end of the codeunit with other events):

[IntegrationEvent(false, false)]
local procedure OnUpdateCostShareBufFromInvAdjmtEntryOrderOnBeforeApplyShareOfCost(ItemLedgerEntry: Record "Item Ledger Entry"; var CostShareBuffer: Record "Cost Share Buffer"; var InventoryAdjmtEntryOrder: Record "Inventory Adjmt. Entry (Order)"; OutputQuantity: Decimal; var ShareOfCost: Decimal; var IsHandled: Boolean)
begin
end;

File: CostSharesBreakdown.Report.al

[!NOTE] Automatically generated by the Triage Agent — advisory only. An engineer will review before any action is taken.

[!TIP] Not accurate? Reply with /not-accurate (optional: add a short explanation). Your feedback improves future responses.

github-actions[bot] avatar Jun 17 '26 19:06 github-actions[bot]

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.

AleksandricMarko avatar Aug 17 '26 12:08 AleksandricMarko