microsoft / ALAppExtensions

Repository for collaboration on Microsoft AL application add-on and localization extensions for Microsoft Dynamics 365 Business Central.
MIT License
792 stars 622 forks source link

[Event Request] Codeunit 905 "Assembly Line Management".AddBOMLine #27674

Open fridrichovsky opened 4 days ago

fridrichovsky commented 4 days ago

Describe the request

Please add new event

procedure AddBOMLine(AssemblyHeader: Record "Assembly Header"; var AssemblyLine: Record "Assembly Line"; AsmLineRecordIsTemporary: Boolean; BOMComponent: Record "BOM Component"; ShowDueDateBeforeWorkDateMessage: Boolean; QtyPerUoM: Decimal)
    var
        DueDateBeforeWorkDateMsgShown: Boolean;
        SkipVerificationsThatChangeDatabase: Boolean;
    //----------------------------------------------------OnAddBOMLineOnBeforeValidateQuantity:BEGIN
    IsHandled: Boolean;
    //----------------------------------------------------OnAddBOMLineOnBeforeValidateQuantity:END
    begin
        SkipVerificationsThatChangeDatabase := AsmLineRecordIsTemporary;
        AssemblyLine.SetSkipVerificationsThatChangeDatabase(SkipVerificationsThatChangeDatabase);
        AssemblyLine.Validate(Type, BOMComponent.Type);
        AssemblyLine.Validate("No.", BOMComponent."No.");
        OnAddBOMLineOnAfterValidatedNo(AssemblyHeader, AssemblyLine, BOMComponent);
        if AssemblyLine.Type = AssemblyLine.Type::Resource then
            case BOMComponent."Resource Usage Type" of
                BOMComponent."Resource Usage Type"::Direct:
                    AssemblyLine.Validate("Resource Usage Type", AssemblyLine."Resource Usage Type"::Direct);
                BOMComponent."Resource Usage Type"::Fixed:
                    AssemblyLine.Validate("Resource Usage Type", AssemblyLine."Resource Usage Type"::Fixed);
            end;
        AssemblyLine.Validate("Unit of Measure Code", BOMComponent."Unit of Measure Code");
        OnAddBOMLineOnAfterValidateUOMCode(AssemblyLine, BOMComponent, AssemblyHeader);
        if AssemblyLine.Type <> AssemblyLine.Type::" " then
            AssemblyLine.Validate(
                "Quantity per",
                AssemblyLine.CalcBOMQuantity(
                BOMComponent.Type, BOMComponent."Quantity per", 1, QtyPerUoM, AssemblyLine."Resource Usage Type"));
    //----------------------------------------------------OnAddBOMLineOnBeforeValidateQuantity:BEGIN
        //OnAddBOMLineOnBeforeValidateQuantity(AssemblyHeader, AssemblyLine, BOMComponent);
      IsHandled := false;
      OnAddBOMLineOnBeforeValidateQuantity(AssemblyHeader, AssemblyLine, BOMComponent, IsHandled);
      if not IsHandled then begin
    //----------------------------------------------------OnAddBOMLineOnBeforeValidateQuantity:END
        AssemblyLine.Validate(
            Quantity,
            AssemblyLine.CalcBOMQuantity(
                BOMComponent.Type, BOMComponent."Quantity per", AssemblyHeader.Quantity, QtyPerUoM, AssemblyLine."Resource Usage Type"));
        AssemblyLine.Validate(
            "Quantity to Consume",
            AssemblyLine.CalcBOMQuantity(
                BOMComponent.Type, BOMComponent."Quantity per", AssemblyHeader."Quantity to Assemble", QtyPerUoM, AssemblyLine."Resource Usage Type"));
        //----------------------------------------------------OnAddBOMLineOnBeforeValidateQuantity:BEGIN
    end;
        //----------------------------------------------------OnAddBOMLineOnBeforeValidateQuantity:END
        AssemblyLine.ValidateDueDate(AssemblyHeader, AssemblyHeader."Starting Date", ShowDueDateBeforeWorkDateMessage);
        DueDateBeforeWorkDateMsgShown := (AssemblyLine."Due Date" < WorkDate()) and ShowDueDateBeforeWorkDateMessage;
        AssemblyLine.ValidateLeadTimeOffset(
            AssemblyHeader, BOMComponent."Lead-Time Offset", not DueDateBeforeWorkDateMsgShown and ShowDueDateBeforeWorkDateMessage);
        if AssemblyLine.Type = AssemblyLine.Type::Item then
            AssemblyLine.Validate("Variant Code", BOMComponent."Variant Code");
        AssemblyLine.Description := BOMComponent.Description;
        AssemblyLine.Position := BOMComponent.Position;
        AssemblyLine."Position 2" := BOMComponent."Position 2";
        AssemblyLine."Position 3" := BOMComponent."Position 3";
        UpdateAssemblyLineLocationCode(AssemblyHeader, AssemblyLine);
        AssemblyLine.Validate("Consumed Quantity", AssemblyHeader."Assembled Quantity");

        OnAfterTransferBOMComponent(AssemblyLine, BOMComponent, AssemblyHeader);

        AssemblyLine.Modify(true);
    end;

    //----------------------------------------------------OnAddBOMLineOnBeforeValidateQuantity:BEGIN
    [IntegrationEvent(false, false)]
    //local procedure OnAddBOMLineOnBeforeValidateQuantity(AssemblyHeader: Record "Assembly Header"; var AssemblyLine: Record "Assembly Line"; BOMComponent: Record "BOM Component")
    local procedure OnAddBOMLineOnBeforeValidateQuantity(AssemblyHeader: Record "Assembly Header"; var AssemblyLine: Record "Assembly Line"; BOMComponent: Record "BOM Component"; var IsHandled: Boolean)
    begin
    end;
    //----------------------------------------------------OnAddBOMLineOnBeforeValidateQuantity:END

Additional context

we need option skip validations Internal work item: AB#558499

BardurKnudsen commented 1 day ago

Looks like a valid extensibility enhancement.