Skip to content

[W1][Codeunit][5812][Calculate Standard Cost] Add integration event OnCalcItemsOnBeforeProcessItems in CalcItems before item processing loop #30148

@mavohra

Description

@mavohra

Why do you need this change?

We need to replace the per-item processing loop in CalcItems in Codeunit 5812 "Calculate Standard Cost" with SKU-aware logic that calls CalcMfgSKU for each stockkeeping unit variant and location. The standard loop calls CalcMfgItem(Item2."No.", Item3, 0) which passes only the item number without location or variant code, preventing per-SKU cost calculation.

OnBeforeCalcItems(Item2) fires at the very start of the procedure before items are counted and the progress dialog is opened. A subscriber there would need to re-implement the counting, dialog, and full iteration logic rather than replacing only the per-item dispatch. No other event exists in CalcItems between the initial Item2 copy and the CalcMfgItem/CalcAssemblyItem dispatch inside the loop.

Describe the request

Add an integration event OnCalcItemsOnBeforeProcessItems in CalcItems in Codeunit 5812 "Calculate Standard Cost" after OnBeforeCalcItems(Item2) and before the item counting and processing loop.

    NewTempItem.DeleteAll();

    Item2.Copy(Item);
    OnBeforeCalcItems(Item2);

    IsHandled := false;
    OnCalcItemsOnBeforeProcessItems(Item2, NewTempItem, IsHandled); // <---- New Event
    if not IsHandled then begin
        NoOfRecords := Item.Count();
        if ShowDialog then
            Window.Open(Text002);

        if Item2.Find('-') then
            repeat
                LineCount := LineCount + 1;
                if ShowDialog then
                    Window.Update(1, Round(LineCount / NoOfRecords * 10000, 1));
                if UseAssemblyList then
                    CalcAssemblyItem(Item2."No.", Item3, 0, true)
                else
                    CalcMfgItem(Item2."No.", Item3, 0);
            until Item2.Next() = 0;

        TempItem.Reset();
        if TempItem.Find('-') then
            repeat
                NewTempItem := TempItem;
                NewTempItem.Insert();
            until TempItem.Next() = 0;

        if ShowDialog then
            Window.Close();
    end;

Event Signature:

[IntegrationEvent(false, false)]
local procedure OnCalcItemsOnBeforeProcessItems(var Item2: Record Item; var NewTempItem: Record Item; var IsHandled: Boolean)
begin
end;

Alternatives evaluated: OnBeforeCalcItems(Item2) fires at the very start of the procedure before items are counted, before the dialog is opened, and before the Find('-') loop. A subscriber there would need to re-derive the item count, manage the progress dialog manually, and replicate the entire loop structure. No other event in CalcItems provides an interception point after Item2 is initialized but before the main processing loop.

Metadata

Metadata

Assignees

No one assigned

    Labels

    missing-infoThe issue misses information that prevents it from completion.

    Type

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions