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 Change Request] PostUpdateInvoiceLine - OnAfterPostUpdateInvoiceLine - Codeunit Sales-Post #28190

Open
dannoe opened this issue Feb 20, 2025 · 0 comments

Comments

@dannoe
Copy link

dannoe commented Feb 20, 2025

Describe the request

Please add the TempSalesOrderHeader parameter to the OnAfterPostUpdateInvoiceLine event:

    local procedure PostUpdateInvoiceLine(var SalesHeader: Record "Sales Header")
    var
        SalesOrderLine: Record "Sales Line";
        SalesShptLine: Record "Sales Shipment Line";
        TempSalesLine: Record "Sales Line" temporary;
        TempSalesOrderHeader: Record "Sales Header" temporary;
        CRMSalesDocumentPostingMgt: Codeunit "CRM Sales Document Posting Mgt";
        IsHandled: Boolean;
    begin
        IsHandled := false;
        OnBeforePostUpdateInvoiceLine(TempSalesLineGlobal, IsHandled);
        if IsHandled then
            exit;

        ResetTempLines(TempSalesLine);
        TempSalesLine.SetFilter("Shipment No.", '<>%1', '');
        TempSalesLine.SetFilter(Type, '<>%1', TempSalesLine.Type::" ");
        if TempSalesLine.FindSet() then
            repeat
                SalesShptLine.Get(TempSalesLine."Shipment No.", TempSalesLine."Shipment Line No.");
                SalesOrderLine.Get(
                  SalesOrderLine."Document Type"::Order,
                  SalesShptLine."Order No.", SalesShptLine."Order Line No.");
                OnPostUpdateInvoiceLineOnAfterGetSalesOrderLine(TempSalesLine, SalesShptLine, SalesOrderLine);
                if TempSalesLine.Type = TempSalesLine.Type::"Charge (Item)" then
                    UpdateSalesOrderChargeAssgnt(TempSalesLine, SalesOrderLine);
                IsHandled := false;
                OnPostUpdateInvoiceLineOnBeforeCalcQuantityInvoiced(SalesOrderLine, TempSalesLine, IsHandled);
                if not IsHandled then begin
                    SalesOrderLine."Quantity Invoiced" += TempSalesLine."Qty. to Invoice";
                    SalesOrderLine."Qty. Invoiced (Base)" += TempSalesLine."Qty. to Invoice (Base)";
                end;
                CheckSalesLineInvoiceMoreThanShipped(SalesOrderLine, TempSalesLine, SalesShptLine);
                OnPostUpdateInvoiceLineOnBeforeInitQtyToInvoice(SalesOrderLine, TempSalesLine);
                SalesOrderLine.InitQtyToInvoice();
                if SalesOrderLine."Prepayment %" <> 0 then begin
                    SalesOrderLine."Prepmt Amt Deducted" += TempSalesLine."Prepmt Amt to Deduct";
                    SalesOrderLine."Prepmt VAT Diff. Deducted" += TempSalesLine."Prepmt VAT Diff. to Deduct";
                    DecrementPrepmtAmtInvLCY(
                      SalesHeader, TempSalesLine, SalesOrderLine."Prepmt. Amount Inv. (LCY)", SalesOrderLine."Prepmt. VAT Amount Inv. (LCY)");
                    SalesOrderLine."Prepmt Amt to Deduct" :=
                      SalesOrderLine."Prepmt. Amt. Inv." - SalesOrderLine."Prepmt Amt Deducted";
                    SalesOrderLine."Prepmt VAT Diff. to Deduct" := 0;
                end;
                IsHandled := false;
                OnPostUpdateInvoiceLineOnBeforeInitOutstanding(SalesOrderLine, IsHandled);
                if not IsHandled then
                    SalesOrderLine.InitOutstanding();
                OnPostUpdateInvoiceLineOnBeforeModifySalesOrderLine(SalesOrderLine, TempSalesLine);
                SalesOrderLine.Modify();
                OnPostUpdateInvoiceLineOnAfterModifySalesOrderLine(SalesOrderLine, TempSalesLine);

                if not TempSalesOrderHeader.Get(SalesOrderLine."Document Type", SalesOrderLine."Document No.") then begin
                    TempSalesOrderHeader."Document Type" := SalesOrderLine."Document Type";
                    TempSalesOrderHeader."No." := SalesOrderLine."Document No.";
                    TempSalesOrderHeader.Insert();
                end;
                OnPostUpdateInvoiceLineOnAfterInsertSalesOrderHeader(SalesOrderLine, TempSalesLine);
            until TempSalesLine.Next() = 0;
        CRMSalesDocumentPostingMgt.CheckShippedOrders(TempSalesOrderHeader);

-       OnAfterPostUpdateInvoiceLine(TempSalesLine, SalesHeader);
+       OnAfterPostUpdateInvoiceLine(TempSalesLine, SalesHeader, TempSalesOrderHeader); 
    end;
    [IntegrationEvent(true, false)]
-   local procedure OnAfterPostUpdateInvoiceLine(var TempSalesLine: Record "Sales Line" temporary; var SalesHeader: Record "Sales Header")
+   local procedure OnAfterPostUpdateInvoiceLine(var TempSalesLine: Record "Sales Line" temporary; var SalesHeader: Record "Sales Header"; var TempSalesOrderHeader: Record "Sales Header" temporary)
    begin
    end;

Additional context

We need to update every sales order that was (partially) posted.

PS: This change would make it possible for Microsoft to replace the CheckShippedOrders call with an event instead of calling CRMSalesDocumentPostingMgt.CheckShippedOrders. (Maybe one step further to modularizing CRM integration?)

@dannoe dannoe changed the title [Additional parameter in event] PostUpdateInvoiceLine - OnAfterPostUpdateInvoiceLine - Codeunit Sales-Post [Event Change Request] PostUpdateInvoiceLine - OnAfterPostUpdateInvoiceLine - Codeunit Sales-Post Feb 20, 2025
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