Skip to content

[EventRequest] Report 5754 "Create Pick" - procedure CreateTempLine() #29676

@nevenamark

Description

@nevenamark

Why do you need this change?

Since in procedure CreateTempLine() printing of picks is invoked through repeat until loop, picks get printed individually. We need an event to subscribe to beforehand in order to enable group printing of picks.

Alternatives Evaluated:

Tried subscribing to the OnBeforePrintPickList however since the filters remain for multiple picks (FirstSetPickNo and LastPickNo have different values), within the repeat until printing is invoked for each individual pick with filtering set to multiple picks so the user ends up being prompted with request page for each pick - printing all picks every time the Print action is invoked on each request page.

Justification for IsHandled:

We must bypass the standard printing pick by pick in order to enable group printing of picks. IsHandled parameter is needed in order to skip the repeat until loop where individual printing is implemented.

Performance Considerations:

Called once per pick group after filtering, minimal impact expected.

Data Sensitivity Review:

No significantly sensitive data would be exposed through this event. Its main purpose would be controlling filters and printing of the created picks.

Multi-Extension Interaction:

Subscribing within multiple extensions could impact the way picks ultimately get printed - in case of IsHandled set to false the standard printing would be executed (individually for each pick). In each case, the printing will occur, with the only question whether it will be a group print of picks or an individual print.

Describe the request

Could you please add an event prior to finding the pick headers so we can control their printing?

    var
        WarehouseShipmentLine: Record "Warehouse Shipment Line";
        PickWhseActivHeader: Record "Warehouse Activity Header";
        TempWhseItemTrkgLine: Record "Whse. Item Tracking Line" temporary;
        ItemTrackingMgt: Codeunit "Item Tracking Management";
        WarehouseDocumentPrint: Codeunit "Warehouse Document-Print";
        PickQty: Decimal;
        PickQtyBase: Decimal;
        OldFirstSetPickNo: Code[20];
        TotalQtyPickedBase: Decimal;
        PickListReportID: Integer;
        IsHandled: Boolean;
    begin
        PickWhseWkshLine.LockTable();
        repeat
            if Location."Bin Mandatory" and
               (not Location."Always Create Pick Line")
            then begin
                IsHandled := false;
                OnCreateTempLineOnBeforeCalcAvailableQtyBase(PickWhseWkshLine, IsHandled);
                if not IsHandled then
                    if PickWhseWkshLine.CalcAvailableQtyBase() < PickWhseWkshLine."Qty. to Handle (Base)" then
                        Error(
                          Text003,
                          PickWhseWkshLine.TableCaption(), PickWhseWkshLine.FieldCaption("Worksheet Template Name"),
                          PickWhseWkshLine."Worksheet Template Name", PickWhseWkshLine.FieldCaption(Name),
                          PickWhseWkshLine.Name, PickWhseWkshLine.FieldCaption("Location Code"),
                          PickWhseWkshLine."Location Code", PickWhseWkshLine.FieldCaption("Line No."),
                          PickWhseWkshLine."Line No.");
            end;

            PickWhseWkshLine.TestField("Qty. per Unit of Measure");
            CreatePick.SetWhseWkshLine(PickWhseWkshLine, TempNo);
            IsHandled := false;
            OnCreateTempLineOnBeforeSetTempWhseItemTrackingLine(PickWhseWkshLine, PickQty, PickQtyBase, IsHandled);
            if not IsHandled then begin
                case PickWhseWkshLine."Whse. Document Type" of
                    PickWhseWkshLine."Whse. Document Type"::Shipment:
                        begin
                            WarehouseShipmentLine.Get(PickWhseWkshLine."Whse. Document No.", PickWhseWkshLine."Whse. Document Line No.");
                            if not WarehouseShipmentLine."Assemble to Order" then
                                CreatePick.SetTempWhseItemTrkgLine(
                                  PickWhseWkshLine."Whse. Document No.", Database::"Warehouse Shipment Line", '', 0,
                                  PickWhseWkshLine."Whse. Document Line No.", PickWhseWkshLine."Location Code")
                            else
                                CreatePick.SetTempWhseItemTrkgLine(
                                  PickWhseWkshLine."Source No.", Database::"Assembly Line", '', 0,
                                  PickWhseWkshLine."Source Line No.", PickWhseWkshLine."Location Code");
                        end;
                    PickWhseWkshLine."Whse. Document Type"::Assembly:
                        CreatePick.SetTempWhseItemTrkgLine(
                          PickWhseWkshLine."Whse. Document No.", Database::"Assembly Line", '', 0,
                          PickWhseWkshLine."Whse. Document Line No.", PickWhseWkshLine."Location Code");
                    PickWhseWkshLine."Whse. Document Type"::"Internal Pick":
                        CreatePick.SetTempWhseItemTrkgLine(
                          PickWhseWkshLine."Whse. Document No.", Database::"Whse. Internal Pick Line", '', 0,
                          PickWhseWkshLine."Whse. Document Line No.", PickWhseWkshLine."Location Code");
                    PickWhseWkshLine."Whse. Document Type"::Production:
                        CreatePick.SetTempWhseItemTrkgLine(
                          PickWhseWkshLine."Source No.", PickWhseWkshLine."Source Type", '', PickWhseWkshLine."Source Line No.",
                          PickWhseWkshLine."Source Subline No.", PickWhseWkshLine."Location Code");
                    PickWhseWkshLine."Whse. Document Type"::Job:
                        CreatePick.SetTempWhseItemTrkgLine(
                          PickWhseWkshLine."Source No.", Database::"Job Planning Line", '', 0,
                          PickWhseWkshLine."Source Line No.", PickWhseWkshLine."Location Code");
                    else // Movement Worksheet Line
                        CreatePick.SetTempWhseItemTrkgLine(
                          PickWhseWkshLine.Name, Database::"Prod. Order Component", PickWhseWkshLine."Worksheet Template Name",
                          0, PickWhseWkshLine."Line No.", PickWhseWkshLine."Location Code");
                end;

                PickQty := PickWhseWkshLine."Qty. to Handle";
                PickQtyBase := PickWhseWkshLine."Qty. to Handle (Base)";
            end;
            OnAfterSetQuantityToPick(PickWhseWkshLine, PickQty, PickQtyBase);
            if (PickQty > 0) and
               (PickWhseWkshLine."Destination Type" = PickWhseWkshLine."Destination Type"::Customer)
            then begin
                PickWhseWkshLine.TestField("Destination No.");
                Cust.Get(PickWhseWkshLine."Destination No.");
                IsHandled := false;
                OnCreateTempLineOnBeforeCustCheckBlockedCustOnDocs(PickWhseWkshLine, IsHandled);
                if not IsHandled then
                    case PickWhseWkshLine."Source Document" of
                        PickWhseWkshLine."Source Document"::"Sales Order":
                            Cust.CheckBlockedCustOnDocs(Cust, "Sales Document Type"::Order, false, false);
                        PickWhseWkshLine."Source Document"::"Sales Return Order":
                            Cust.CheckBlockedCustOnDocs(Cust, "Sales Document Type"::"Return Order", false, false);
                    end;
            end;

            CreatePick.SetCalledFromWksh(true);

            IsHandled := false;
            OnCreateTempLineOnBeforeCreatePickCreateTempLine(PickWhseWkshLine, TempWhseItemTrkgLine, PickQty, PickQtyBase, TotalQtyPickedBase, IsHandled);
            if not IsHandled then
                CreatePick.CreateTempLine(
                    PickWhseWkshLine."Location Code", PickWhseWkshLine."Item No.", PickWhseWkshLine."Variant Code",
                    PickWhseWkshLine."Unit of Measure Code", '', PickWhseWkshLine."To Bin Code", PickWhseWkshLine."Qty. per Unit of Measure",
                    PickWhseWkshLine."Qty. Rounding Precision", PickWhseWkshLine."Qty. Rounding Precision (Base)", PickQty, PickQtyBase);

            TotalQtyPickedBase := CreatePick.GetActualQtyPickedBase();

            // Update/delete lines
            PickWhseWkshLine."Qty. to Handle (Base)" := PickWhseWkshLine.CalcBaseQty(PickWhseWkshLine."Qty. to Handle");
            IsHandled := false;
            OnCreateTempLineOnBeforeDeleteOrModifyPickWhseWorksheetLine(PickWhseWkshLine, TotalQtyPickedBase, PickQtyBase, IsHandled);
            if not IsHandled then
                if PickWhseWkshLine."Qty. (Base)" =
                   PickWhseWkshLine."Qty. Handled (Base)" + TotalQtyPickedBase
                then
                    PickWhseWkshLine.Delete(true)
                else begin
                    PickWhseWkshLine."Qty. Handled" := PickWhseWkshLine."Qty. Handled" + PickWhseWkshLine.CalcQty(TotalQtyPickedBase);
                    PickWhseWkshLine."Qty. Handled (Base)" := PickWhseWkshLine.CalcBaseQty(PickWhseWkshLine."Qty. Handled");
                    PickWhseWkshLine."Qty. Outstanding" := PickWhseWkshLine.Quantity - PickWhseWkshLine."Qty. Handled";
                    PickWhseWkshLine."Qty. Outstanding (Base)" := PickWhseWkshLine.CalcBaseQty(PickWhseWkshLine."Qty. Outstanding");
                    PickWhseWkshLine."Qty. to Handle" := 0;
                    PickWhseWkshLine."Qty. to Handle (Base)" := 0;
                    OnBeforePickWhseWkshLineModify(PickWhseWkshLine);
                    PickWhseWkshLine.Modify();
                end;
        until PickWhseWkshLine.Next() = 0;

        IsHandled := false;
        OnCreateTempLineOnBeforeSetOldFirstSetPickNo(PickWhseWkshLine, IsHandled);
        if not IsHandled then begin
            OldFirstSetPickNo := FirstSetPickNo;
            OnBeforeCreatePickWhseDocument(PickWhseWkshLine);
            CreatePick.CreateWhseDocument(FirstSetPickNo, LastPickNo, false);
            if FirstSetPickNo = OldFirstSetPickNo then
                exit;

            if FirstPickNo = '' then
                FirstPickNo := FirstSetPickNo;
            CreatePick.ReturnTempItemTrkgLines(TempWhseItemTrkgLine);
            ItemTrackingMgt.UpdateWhseItemTrkgLines(TempWhseItemTrkgLine);
            Commit();
        end;

        PickWhseActivHeader.SetRange(Type, PickWhseActivHeader.Type::Pick);
        PickWhseActivHeader.SetRange("No.", FirstSetPickNo, LastPickNo);
 //>>> New
        IsHandled := false;
        OnBeforeFindPickHeader(PickWhseActivHeader, PrintPick, IsHandled);
        if IsHandled then
            exit;
//<<< New
        PickWhseActivHeader.Find('-');

        repeat
            if SortActivity <> SortActivity::None then
                PickWhseActivHeader.SortWhseDoc();
            Commit();
            if PrintPick then begin
                PickListReportID := Report::"Picking List";
                OnBeforePrintPickList(PickWhseActivHeader, PickListReportID, IsHandled);
                if not IsHandled then
                    WarehouseDocumentPrint.PrintPickHeader(PickWhseActivHeader);
            end;
        until PickWhseActivHeader.Next() = 0;
    end;

 //>>> New
    [IntegrationEvent(false, false)]
    local procedure OnBeforeFindPickHeader(PickWhseActivHeader: Record "Warehouse Activity Header"; var PrintPick: Boolean; var IsHandled: Boolean)
    begin
    end;
//<<< New

Alternatives Evaluated: Please describe which existing events or patterns you tried and why they are insufficient for your needs.

Justification for IsHandled: Please explain why an IsHandled parameter is necessary. Why isn't a standard event sufficient? What specific logic needs to be bypassed or replaced? (Example: 'We must bypass the standard credit limit check because our vertical industry requires real-time insurance pre-authorization instead. The standard check would block orders that are actually covered by insurance.')

Performance Considerations: Please provide the expected execution frequency of this event and assess any potential performance impact (e.g., 'Called once per pick document during creation, minimal impact expected').

Data Sensitivity Review: Please confirm whether any sensitive data is exposed through this event, or provide rationale if sensitive data exposure is necessary.

Multi-Extension Interaction: Please describe potential risks if multiple extensions subscribe to this event with IsHandled, and how conflicts could be mitigated.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions