Skip to content

[W1][Codeunit][22][Item Jnl.-Post Line] Add integration event OnUpdateItemLedgEntryOnBeforeUpdateInvoicedQuantity in Procedure UpdateItemLedgEntry #30052

Description

@mavohra

Why do you need this change?

We need to intercept the invoiced quantity update block in UpdateItemLedgEntry to replace the standard ItemLedgEntry."Invoiced Quantity" := ItemLedgEntry."Invoiced Quantity" + ValueEntry."Invoiced Quantity" assignment with logic that updates alternate quantity fields on the item ledger entry alongside the standard invoiced quantity, and to replace the ItemJnlLine.Quantity = 0 gate condition with an alternate quantity check.

The standard code uses ItemJnlLine.Quantity = 0 to determine whether this posting is a pure invoice with no quantity movement, then unconditionally adds ValueEntry."Invoiced Quantity" to ItemLedgEntry."Invoiced Quantity". In scenarios where alternate quantity fields drive costing logic, the Quantity = 0 check produces an incorrect gate result, and the single-line invoiced quantity assignment does not update the corresponding alternate quantity field on the item ledger entry.

No event currently exists between the OnUpdateItemLedgerEntryOnAfterSetAppliedEntryToAdjust call and the outer if (ValueEntry."Entry Type" = "Direct Cost") and (ItemJnlLine."Item Charge No." = '') and (ItemJnlLine.Quantity = 0) block that allows a subscriber to take control of the gate condition evaluation and the invoiced quantity assignment.

Describe the request

Add an integration event OnUpdateItemLedgEntryOnBeforeUpdateInvoicedQuantity in UpdateItemLedgEntry in Codeunit 22 "Item Jnl.-Post Line" after the applied-entry-to-adjust block and before the invoiced quantity update condition, with IsHandled wrapping the entire outer invoiced quantity update block.

            then begin
                ItemLedgEntry."Applied Entry to Adjust" := true;
                ModifyEntry := true;
                OnUpdateItemLedgerEntryOnAfterSetAppliedEntryToAdjust(ItemLedgEntry);
            end;

            IsHandled := false;
            OnUpdateItemLedgEntryOnBeforeUpdateInvoicedQuantity(ItemJnlLine, ItemLedgEntry, ValueEntry, ModifyEntry, IsHandled); // <---- New Event
            if not IsHandled then
                if (ValueEntry."Entry Type" = ValueEntry."Entry Type"::"Direct Cost") and
                   (ItemJnlLine."Item Charge No." = '') and
                   (ItemJnlLine.Quantity = 0) and (ValueEntry."Invoiced Quantity" <> 0)
                then begin
                    if ValueEntry."Invoiced Quantity" <> 0 then begin
                        ItemLedgEntry."Invoiced Quantity" := ItemLedgEntry."Invoiced Quantity" + ValueEntry."Invoiced Quantity";
                        CheckInvoicedQuantity(ItemLedgEntry, ValueEntry, ModifyEntry);
                    end;

                    if (ItemLedgEntry."Entry Type" <> ItemLedgEntry."Entry Type"::Output) and
                       (ItemLedgEntry."Invoiced Quantity" = ItemLedgEntry.Quantity) and
                       not ItemLedgEntry."Completely Invoiced"
                    then begin
                        ItemLedgEntry."Completely Invoiced" := true;
                        ModifyEntry := true;
                    end;

                    if ItemLedgEntry."Last Invoice Date" < ValueEntry."Posting Date" then begin
                        ItemLedgEntry."Last Invoice Date" := ValueEntry."Posting Date";
                        ModifyEntry := true;
                    end;
                end;
         

Event Signature:

[IntegrationEvent(false, false)]
local procedure OnUpdateItemLedgEntryOnBeforeUpdateInvoicedQuantity(var ItemJnlLine: Record "Item Journal Line"; var ItemLedgEntry: Record "Item Ledger Entry"; ValueEntry: Record "Value Entry"; var ModifyEntry: Boolean; var IsHandled: Boolean)
begin
end;

Alternatives evaluated: OnUpdateItemLedgEntryOnBeforeUpdateAvgCostAdjmtBuffer fires at the top of the non-variance/rounding block but is scoped to the average cost adjustment buffer update and exposes no mechanism to skip the invoiced quantity condition. OnUpdateItemLedgerEntryOnAfterSetAppliedEntryToAdjust fires immediately before the invoiced quantity condition but does not expose the value entry or ModifyEntry, making it impossible to intercept the gate condition or the invoiced quantity assignment. OnUpdateItemLedgEntryOnBeforeUpdateOutboundItemLedgEntry fires after the invoiced quantity block is already complete, too late to replace the assignment. No event currently exists before the ItemJnlLine.Quantity = 0 gate that allows a subscriber to substitute an alternate quantity check and take over the invoiced quantity update logic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions