Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Event Request] codeunit 5856 "TransferOrder-Post Transfer" - OnRunOnBeforeTestRequireReceive #27915

Open
apetotetra opened this issue Jan 9, 2025 · 0 comments

Comments

@apetotetra
Copy link

apetotetra commented Jan 9, 2025

Describe the request

Please add the event OnRunOnBeforeTestRequireReceive in Procedure RunWithCheck in Codeunit 5856 "TransferOrder-Post Transfer"

 procedure RunWithCheck(var TransferHeader2: Record "Transfer Header")
    var
        Item: Record Item;
        ItemVariant: Record "Item Variant";
        SourceCodeSetup: Record "Source Code Setup";
        InvtCommentLine: Record "Inventory Comment Line";
        UpdateAnalysisView: Codeunit "Update Analysis View";
        UpdateItemAnalysisView: Codeunit "Update Item Analysis View";
        RecordLinkManagement: Codeunit "Record Link Management";
        ReleaseTransferDocument: Codeunit "Release Transfer Document";
        Window: Dialog;
        LineCount: Integer;
        IsHandled: Boolean;
    begin
        if TransferHeader2.Status = TransferHeader2.Status::Open then begin
            ReleaseTransferDocument.Release(TransferHeader2);
            TransferHeader2.Status := TransferHeader2.Status::Open;
            TransferHeader2.Modify();
            if not (SuppressCommit or PreviewMode) then
                Commit();
            TransferHeader2.Status := TransferHeader2.Status::Released;
        end;
        TransHeader := TransferHeader2;
        TransHeader.SetHideValidationDialog(HideValidationDialog);

        OnRunOnAfterTransHeaderSetHideValidationDialog(TransHeader, TransferHeader2, HideValidationDialog);

        TransHeader.CheckBeforeTransferPost();
        CheckDim();

        WhseReference := TransHeader."Posting from Whse. Ref.";
        TransHeader."Posting from Whse. Ref." := 0;

        WhseShip := TempWhseShptHeader.FindFirst();
        InvtPickPutaway := WhseReference <> 0;

        TransLine.Reset();
        TransLine.SetRange("Document No.", TransHeader."No.");
        TransLine.SetRange("Derived From Line No.", 0);
        TransLine.SetFilter(Quantity, '<>%1', 0);
        OnRunOnAfterTransLineSetFiltersForCheckShipmentLines(TransLine, TransHeader, Location, WhseShip);
        if TransLine.FindSet() then
            repeat
                if not WhseShip then
                    TransLine.TestField("Qty. to Ship");
                TransLine.TestField("Quantity Shipped", 0);
                TransLine.TestField("Quantity Received", 0);
                TransLine.CheckDirectTransferQtyToShip()
            until TransLine.Next() = 0
        else
            Error(DocumentErrorsMgt.GetNothingToPostErrorMsg());

        GetLocation(TransHeader."Transfer-from Code");
        if Location."Bin Mandatory" and not (WhseShip or InvtPickPutaway) then
            WhsePosting := true;

        // Require Receipt is not supported here, only Bin Mandatory
        GetLocation(TransHeader."Transfer-to Code");
        //New event begin
        IsHandled := false;
        OnRunOnBeforeTestRequireReceive(Location, IsHandled);
        if not IsHandled then
        //New event end
           Location.TestField("Require Receive", false);
        if Location."Bin Mandatory" then
            WhseReceive := true;

        Window.Open('#1#################################\\' + PostingLinesMsg);

        Window.Update(1, StrSubstNo(PostingDocumentTxt, TransHeader."No."));

        SourceCodeSetup.Get();
        SourceCode := SourceCodeSetup.Transfer;
        InventorySetup.Get();
        InventorySetup.TestField("Posted Direct Trans. Nos.");

        if InventorySetup."Automatic Cost Posting" then begin
            GLEntry.LockTable();
            GLEntry.GetLastEntryNo();
        end;

        InsertDirectTransHeader(TransHeader, DirectTransHeader);
        if InventorySetup."Copy Comments Order to Shpt." then begin
            InvtCommentLine.CopyCommentLines(
                "Inventory Comment Document Type"::"Transfer Order", TransHeader."No.",
                "Inventory Comment Document Type"::"Posted Direct Transfer", DirectTransHeader."No.");
            RecordLinkManagement.CopyLinks(TransferHeader2, DirectTransHeader);
        end;

        if WhseShip then begin
            WhseShptHeader.Get(TempWhseShptHeader."No.");
            WhsePostShipment.CreatePostedShptHeader(PostedWhseShptHeader, WhseShptHeader, DirectTransHeader."No.", TransHeader."Posting Date");
        end;

        // Insert shipment lines
        LineCount := 0;
        if WhseShip then
            PostedWhseShptLine.LockTable();
        if InvtPickPutaway then
            WhseRqst.LockTable();
        DirectTransLine.LockTable();
        TransLine.SetRange(Quantity);
        OnRunOnAfterTransLineSetFiltersForInsertShipmentLines(TransLine, TransHeader, Location, WhseShip);
        if TransLine.FindSet() then
            repeat
                LineCount := LineCount + 1;
                Window.Update(2, LineCount);

                if TransLine."Item No." <> '' then begin
                    Item.Get(TransLine."Item No.");
                    Item.TestField(Blocked, false);

                    if TransLine."Variant Code" <> '' then begin
                        ItemVariant.Get(TransLine."Item No.", TransLine."Variant Code");
                        CheckItemVariantNotBlocked(ItemVariant);
                    end;
                end;

                InsertDirectTransLine(DirectTransHeader, TransLine);
            until TransLine.Next() = 0;

        MakeInventoryAdjustment();

        TransHeader.LockTable();
        if WhseShip then
            WhseShptLine.LockTable();

        if WhseShip then begin
            WhsePostShipment.PostUpdateWhseDocuments(WhseShptHeader);
            TempWhseShptHeader.Delete();
        end;

        TransHeader."Last Shipment No." := DirectTransHeader."No.";
        TransHeader."Last Receipt No." := DirectTransHeader."No.";
        TransHeader.Modify();

        TransLine.SetRange(Quantity);
        if not PreviewMode then
            TransHeader.DeleteOneTransferOrder(TransHeader, TransLine);
        Window.Close();

        UpdateAnalysisView.UpdateAll(0, true);
        UpdateItemAnalysisView.UpdateAll(0, true);
        TransferHeader2 := TransHeader;

        OnAfterTransferOrderPostTransfer(TransferHeader2, SuppressCommit, DirectTransHeader, InvtPickPutAway);
    end;
    [IntegrationEvent(false, false)]
    local procedure OnRunOnBeforeTestRequireReceive(var Location: Record Location; var IsHandled: Boolean)
    begin
    end;

Additional context

Our client would like to use Direct Transfer functionality when the Location is set for Require Receipt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant