Skip to content

[W1][Codeunit][5812][Calculate Standard Cost] Add integration event OnCalcAssemblyItemOnBeforeProcessBOMItem in CalcAssemblyItem before BOM item processing #30149

@mavohra

Description

@mavohra

Why do you need this change?

We need to replace the CalcMfgItem call inside the BOMComp.Type::Item case of CalcAssemblyItem in Codeunit 5812 "Calculate Standard Cost" with SKU-aware logic that calls CalcMfgSKU for each stockkeeping unit and transfers costs from the SKU record to the component item record. The standard case block calls CalcMfgItem(BOMComp."No.", CompItem, Level + 1) which calculates manufacturing cost at the item level without location or variant context, then accumulates rolled-up costs from the component item directly into the parent item.

Describe the request

Add an integration event OnCalcAssemblyItemOnBeforeProcessBOMItem in CalcAssemblyItem in Codeunit 5812 "Calculate Standard Cost" at the start of the BOMComp.Type::Item case block, before GetItem and the component cost processing.

                case BOMComp.Type of
                    BOMComp.Type::Item:
                        begin
                            IsHandled := false;
                            OnCalcAssemblyItemOnBeforeProcessBOMItem( // <---- New Event
                              Item, BOMComp, CompItem, Level, CalcMfgItems, ComponentQuantity, IsHandled);
                            if not IsHandled then begin
                            GetItem(BOMComp."No.", CompItem);
                            ComponentQuantity :=
                              BOMComp."Quantity per" *
                              UOMMgt.GetQtyPerUnitOfMeasure(CompItem, BOMComp."Unit of Measure Code");
                            if CompItem.IsInventoriableType() then
                                if CompItem.IsAssemblyItem() or CompItem.IsMfgItem() then begin
                                    if CompItem.IsAssemblyItem() then
                                        CalcAssemblyItem(BOMComp."No.", CompItem, Level + 1, CalcMfgItems)
                                    else
                                        if CalcMfgItems then
                                            CalcMfgItem(BOMComp."No.", CompItem, Level + 1);
                                    Item."Rolled-up Material Cost" += ComponentQuantity * CompItem."Rolled-up Material Cost";
                                    Item."Rolled-up Capacity Cost" += ComponentQuantity * CompItem."Rolled-up Capacity Cost";
                                    Item."Rolled-up Cap. Overhead Cost" += ComponentQuantity * CompItem."Rolled-up Cap. Overhead Cost";
                                    Item."Rolled-up Mfg. Ovhd Cost" += ComponentQuantity * CompItem."Rolled-up Mfg. Ovhd Cost";
                                    Item."Rolled-up Subcontracted Cost" += ComponentQuantity * CompItem."Rolled-up Subcontracted Cost";
                                    Item."Single-Level Material Cost" += ComponentQuantity * CompItem."Standard Cost"
                                end else begin
                                    Item."Rolled-up Material Cost" += ComponentQuantity * CompItem."Unit Cost";
                                    Item."Single-Level Material Cost" += ComponentQuantity * CompItem."Unit Cost"
                                end;
                            OnCalcAssemblyItemOnAfterCalcItemCost(Item, CompItem, BOMComp, ComponentQuantity);
                            end;
                        end;

Event Signature:

[IntegrationEvent(false, false)]
local procedure OnCalcAssemblyItemOnBeforeProcessBOMItem(var Item: Record Item; var BOMComp: Record "BOM Component"; var CompItem: Record Item; Level: Integer; CalcMfgItems: Boolean; var ComponentQuantity: Decimal; var IsHandled: Boolean)
begin

end;

Alternatives evaluated: OnCalcAssemblyItemOnAfterCalcItemCost fires after all cost accumulation and CalcMfgItem have already executed for the component, too late to replace the manufacturing dispatch with CalcMfgSKU. OnCalcAssemblyItemOnAfterInitItemCost fires once before the BOM component loop begins, before any individual component is processed, and carries no BOMComp or CompItem context. No event fires at the start of the BOMComp.Type::Item case block to allow a subscriber to intercept and replace the standard component processing logic.

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