Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2157,6 +2157,24 @@ codeunit 12 "Gen. Jnl.-Post Line"
SequenceNoMgt.ValidateSeqNo(TableNo);
end;

/// <summary>
/// Invalidates the transaction-scoped caches in this codeunit so the next call to RunWithCheck
/// is forced through StartPosting (which re-takes the G/L Entry table lock and re-reads the
/// last entry number from disk) instead of taking the ContinuePosting fast path with a stale
/// NextEntryNo.
/// </summary>
procedure ResetTransactionState()
begin
NextEntryNo := 0;
NextTransactionNo := 0;
NextVATEntryNo := 0;
FirstEntryNo := 0;
FirstNewVATEntryNo := 0;
IsGLRegInserted := false;
TempGLEntryBuf.Reset();
TempGLEntryBuf.DeleteAll();
end;

/// <summary>
/// Checks if transaction is balanced for both local and additional currencies, inserts all G/L Entries that were created for the Gen. Journal Line.
/// If posting is performed for application purpose, original Customer and Vendor Ledger Entries are updated to reflect that.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ codeunit 5895 "Inventory Adjustment" implements "Inventory Adjustment", "Cost Ad
AdjustTillDate: Date;
StartDateTime: DateTime;
MaxDuration: Duration;
ItemsSinceLastCommit: Integer;
AutomaticCostAdjustmentTok: Label 'Automatic cost adjustment', Locked = true;
AutomaticCostAdjustmentEnabledTok: Label 'Automatic cost adjustment was used.', Locked = true;
CostAdjustmentReachedMaxDurationErr: Label 'The cost adjustment process has reached the maximum duration of %1.', Comment = '%1=Max Duration';
CostAdjmtCommitFeatureNameTok: Label 'Cost Adjustment Item-by-Item Commit', Locked = true;
CostAdjmtCommitEventNameTok: Label 'CheckAndCommit invoked', Locked = true;
#pragma warning disable AA0074
Text009: Label 'WIP';
Text010: Label 'Assembly';
Expand Down Expand Up @@ -189,6 +192,8 @@ codeunit 5895 "Inventory Adjustment" implements "Inventory Adjustment", "Cost Ad
Clear(ItemJnlPostLine);
ItemJnlPostLine.SetCalledFromAdjustment(true, PostToGL);

ItemsSinceLastCommit := 0;

InvtSetup.SetLoadFields("Automatic Cost Adjustment");
InvtSetup.Get();
if InvtSetup.AutomaticCostAdjmtRequired() then
Expand Down Expand Up @@ -2971,13 +2976,30 @@ codeunit 5895 "Inventory Adjustment" implements "Inventory Adjustment", "Cost Ad

local procedure CheckAndCommit()
begin
if ItemsBeingAdjusted.Count() = 0 then begin
if CommitAdjustedItems then
Commit();
ItemsSinceLastCommit += 1;
if ItemsBeingAdjusted.Count() > 0 then
exit;

ItemApplicationTrace.Reset();
ItemApplicationTrace.DeleteAll();
if CommitAdjustedItems then begin
Commit();
ItemJnlPostLine.ResetGLPostingState();

@ChethanT ChethanT Jul 1, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be before Commit() to ensure other transaction do not read state between Commit() and ResetGLPostingState call?

EmitCheckAndCommitTelemetry();
ItemsSinceLastCommit := 0;
end;

ItemApplicationTrace.Reset();
ItemApplicationTrace.DeleteAll();
end;

local procedure EmitCheckAndCommitTelemetry()
var
TelemetryDimensions: Dictionary of [Text, Text];
begin
TelemetryDimensions.Add('ItemsSinceLastCommit', Format(ItemsSinceLastCommit));
TelemetryDimensions.Add('IsOnlineAdjmt', Format(IsOnlineAdjmt, 0, 9));
TelemetryDimensions.Add('PostToGL', Format(PostToGL, 0, 9));
TelemetryDimensions.Add('ItemByItemCommit', Format(CommitAdjustedItems, 0, 9));
FeatureTelemetry.LogUsage('0000MEQ', CostAdjmtCommitFeatureNameTok, CostAdjmtCommitEventNameTok, TelemetryDimensions);
end;

local procedure FindLastDate(DateFilter: Text): Date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4977,6 +4977,20 @@ codeunit 22 "Item Jnl.-Post Line"
PostToGL := NewPostToGL;
end;

/// <summary>
/// Resets the transaction-scoped state of the downstream G/L posting codeunits
/// (Codeunit "Inventory Posting To G/L" -> Codeunit "Gen. Jnl.-Post Line") so the
/// next G/L posting call re-takes the G/L Entry table lock and re-reads the last
/// entry number from disk. Must be called by any caller that issues an explicit
/// Commit() while keeping a long-lived reference to this codeunit (for example
/// Codeunit 5895 "Inventory Adjustment".CheckAndCommit). The configuration set via
/// SetCalledFromAdjustment / SetCalledFromInvtPutawayPick / etc. is preserved.
/// </summary>
procedure ResetGLPostingState()
begin
InventoryPostingToGL.ResetGLPostingState();
end;

internal procedure GetPostToGL(): Boolean
begin
exit(PostToGL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2033,6 +2033,24 @@ codeunit 12 "Gen. Jnl.-Post Line"
SequenceNoMgt.ValidateSeqNo(TableNo);
end;

/// <summary>
/// Invalidates the transaction-scoped caches in this codeunit so the next call to RunWithCheck
/// is forced through StartPosting (which re-takes the G/L Entry table lock and re-reads the
/// last entry number from disk) instead of taking the ContinuePosting fast path with a stale
/// NextEntryNo.
/// </summary>
procedure ResetTransactionState()
begin
NextEntryNo := 0;
NextTransactionNo := 0;
NextVATEntryNo := 0;
FirstEntryNo := 0;
FirstNewVATEntryNo := 0;
IsGLRegInserted := false;
TempGLEntryBuf.Reset();
TempGLEntryBuf.DeleteAll();
end;

/// <summary>
/// Checks if transaction is balanced for both local and additional currencies, inserts all G/L Entries that were created for the Gen. Journal Line.
/// If posting is performed for application purpose, original Customer and Vendor Ledger Entries are updated to reflect that.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@ codeunit 5802 "Inventory Posting To G/L"
NextTransactionNo := GenJnlPostLine.GetNextTransactionNo();
end;

/// <summary>
/// Resets the transaction-scoped state of the underlying Codeunit "Gen. Jnl.-Post Line"
/// instance held by this codeunit so the next G/L posting call re-takes the G/L Entry
/// table lock and re-reads the last entry number from disk. Must be called by any caller
/// that issues an explicit Commit() while keeping a long-lived reference to this codeunit.
/// See Codeunit "Gen. Jnl.-Post Line".ResetTransactionState for details.
/// </summary>
procedure ResetGLPostingState()
begin
GenJnlPostLine.ResetTransactionState();
end;

procedure BufferInvtPosting(var ValueEntry: Record "Value Entry"): Boolean
var
CostToPost: Decimal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2028,6 +2028,24 @@ codeunit 12 "Gen. Jnl.-Post Line"
SequenceNoMgt.ValidateSeqNo(TableNo);
end;

/// <summary>
/// Invalidates the transaction-scoped caches in this codeunit so the next call to RunWithCheck
/// is forced through StartPosting (which re-takes the G/L Entry table lock and re-reads the
/// last entry number from disk) instead of taking the ContinuePosting fast path with a stale
/// NextEntryNo.
/// </summary>
procedure ResetTransactionState()
begin
NextEntryNo := 0;
NextTransactionNo := 0;
NextVATEntryNo := 0;
FirstEntryNo := 0;
FirstNewVATEntryNo := 0;
IsGLRegInserted := false;
TempGLEntryBuf.Reset();
TempGLEntryBuf.DeleteAll();
end;

/// <summary>
/// Checks if transaction is balanced for both local and additional currencies, inserts all G/L Entries that were created for the Gen. Journal Line.
/// If posting is performed for application purpose, original Customer and Vendor Ledger Entries are updated to reflect that.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4949,6 +4949,20 @@ codeunit 22 "Item Jnl.-Post Line"
PostToGL := NewPostToGL;
end;

/// <summary>
/// Resets the transaction-scoped state of the downstream G/L posting codeunits
/// (Codeunit "Inventory Posting To G/L" -> Codeunit "Gen. Jnl.-Post Line") so the
/// next G/L posting call re-takes the G/L Entry table lock and re-reads the last
/// entry number from disk. Must be called by any caller that issues an explicit
/// Commit() while keeping a long-lived reference to this codeunit (for example
/// Codeunit 5895 "Inventory Adjustment".CheckAndCommit). The configuration set via
/// SetCalledFromAdjustment / SetCalledFromInvtPutawayPick / etc. is preserved.
/// </summary>
procedure ResetGLPostingState()
begin
InventoryPostingToGL.ResetGLPostingState();
end;

internal procedure GetPostToGL(): Boolean
begin
exit(PostToGL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2146,6 +2146,24 @@ codeunit 12 "Gen. Jnl.-Post Line"
exit(NewTransaction);
end;

/// <summary>
/// Invalidates the transaction-scoped caches in this codeunit so the next call to RunWithCheck
/// is forced through StartPosting (which re-takes the G/L Entry table lock and re-reads the
/// last entry number from disk) instead of taking the ContinuePosting fast path with a stale
/// NextEntryNo.
/// </summary>
procedure ResetTransactionState()
begin
NextEntryNo := 0;
NextTransactionNo := 0;
NextVATEntryNo := 0;
FirstEntryNo := 0;
FirstNewVATEntryNo := 0;
IsGLRegInserted := false;
TempGLEntryBuf.Reset();
TempGLEntryBuf.DeleteAll();
end;

/// <summary>
/// Checks if transaction is balanced for both local and additional currencies, inserts all G/L Entries that were created for the Gen. Journal Line.
/// If posting is performed for application purpose, original Customer and Vendor Ledger Entries are updated to reflect that.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4958,6 +4958,20 @@ codeunit 22 "Item Jnl.-Post Line"
PostToGL := NewPostToGL;
end;

/// <summary>
/// Resets the transaction-scoped state of the downstream G/L posting codeunits
/// (Codeunit "Inventory Posting To G/L" -> Codeunit "Gen. Jnl.-Post Line") so the
/// next G/L posting call re-takes the G/L Entry table lock and re-reads the last
/// entry number from disk. Must be called by any caller that issues an explicit
/// Commit() while keeping a long-lived reference to this codeunit (for example
/// Codeunit 5895 "Inventory Adjustment".CheckAndCommit). The configuration set via
/// SetCalledFromAdjustment / SetCalledFromInvtPutawayPick / etc. is preserved.
/// </summary>
procedure ResetGLPostingState()
begin
InventoryPostingToGL.ResetGLPostingState();
end;

internal procedure GetPostToGL(): Boolean
begin
exit(PostToGL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2018,6 +2018,24 @@ codeunit 12 "Gen. Jnl.-Post Line"
SequenceNoMgt.ValidateSeqNo(TableNo);
end;

/// <summary>
/// Invalidates the transaction-scoped caches in this codeunit so the next call to RunWithCheck
/// is forced through StartPosting (which re-takes the G/L Entry table lock and re-reads the
/// last entry number from disk) instead of taking the ContinuePosting fast path with a stale
/// NextEntryNo.
/// </summary>
procedure ResetTransactionState()
begin
NextEntryNo := 0;
NextTransactionNo := 0;
NextVATEntryNo := 0;
FirstEntryNo := 0;
FirstNewVATEntryNo := 0;
IsGLRegInserted := false;
TempGLEntryBuf.Reset();
TempGLEntryBuf.DeleteAll();
end;

/// <summary>
/// Checks if transaction is balanced for both local and additional currencies, inserts all G/L Entries that were created for the Gen. Journal Line.
/// If posting is performed for application purpose, original Customer and Vendor Ledger Entries are updated to reflect that.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2027,6 +2027,24 @@ codeunit 12 "Gen. Jnl.-Post Line"
SequenceNoMgt.ValidateSeqNo(TableNo);
end;

/// <summary>
/// Invalidates the transaction-scoped caches in this codeunit so the next call to RunWithCheck
/// is forced through StartPosting (which re-takes the G/L Entry table lock and re-reads the
/// last entry number from disk) instead of taking the ContinuePosting fast path with a stale
/// NextEntryNo.
/// </summary>
procedure ResetTransactionState()
begin
NextEntryNo := 0;
NextTransactionNo := 0;
NextVATEntryNo := 0;
FirstEntryNo := 0;
FirstNewVATEntryNo := 0;
IsGLRegInserted := false;
TempGLEntryBuf.Reset();
TempGLEntryBuf.DeleteAll();
end;

/// <summary>
/// Checks if transaction is balanced for both local and additional currencies, inserts all G/L Entries that were created for the Gen. Journal Line.
/// If posting is performed for application purpose, original Customer and Vendor Ledger Entries are updated to reflect that.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2335,6 +2335,24 @@ codeunit 12 "Gen. Jnl.-Post Line"
SequenceNoMgt.ValidateSeqNo(TableNo);
end;

/// <summary>
/// Invalidates the transaction-scoped caches in this codeunit so the next call to RunWithCheck
/// is forced through StartPosting (which re-takes the G/L Entry table lock and re-reads the
/// last entry number from disk) instead of taking the ContinuePosting fast path with a stale
/// NextEntryNo.
/// </summary>
procedure ResetTransactionState()
begin
NextEntryNo := 0;
NextTransactionNo := 0;
NextVATEntryNo := 0;
FirstEntryNo := 0;
FirstNewVATEntryNo := 0;
IsGLRegInserted := false;
TempGLEntryBuf.Reset();
TempGLEntryBuf.DeleteAll();
end;

/// <summary>
/// Checks if transaction is balanced for both local and additional currencies, inserts all G/L Entries that were created for the Gen. Journal Line.
/// If posting is performed for application purpose, original Customer and Vendor Ledger Entries are updated to reflect that.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@ codeunit 5802 "Inventory Posting To G/L"
NextTransactionNo := GenJnlPostLine.GetNextTransactionNo();
end;

/// <summary>
/// Resets the transaction-scoped state of the underlying Codeunit "Gen. Jnl.-Post Line"
/// instance held by this codeunit so the next G/L posting call re-takes the G/L Entry
/// table lock and re-reads the last entry number from disk. Must be called by any caller
/// that issues an explicit Commit() while keeping a long-lived reference to this codeunit.
/// See Codeunit "Gen. Jnl.-Post Line".ResetTransactionState for details.
/// </summary>
procedure ResetGLPostingState()
begin
GenJnlPostLine.ResetTransactionState();
end;

procedure BufferInvtPosting(var ValueEntry: Record "Value Entry"): Boolean
var
CostToPost: Decimal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4976,6 +4976,20 @@ codeunit 22 "Item Jnl.-Post Line"
PostToGL := NewPostToGL;
end;

/// <summary>
/// Resets the transaction-scoped state of the downstream G/L posting codeunits
/// (Codeunit "Inventory Posting To G/L" -> Codeunit "Gen. Jnl.-Post Line") so the
/// next G/L posting call re-takes the G/L Entry table lock and re-reads the last
/// entry number from disk. Must be called by any caller that issues an explicit
/// Commit() while keeping a long-lived reference to this codeunit (for example
/// Codeunit 5895 "Inventory Adjustment".CheckAndCommit). The configuration set via
/// SetCalledFromAdjustment / SetCalledFromInvtPutawayPick / etc. is preserved.
/// </summary>
procedure ResetGLPostingState()
begin
InventoryPostingToGL.ResetGLPostingState();
end;

internal procedure GetPostToGL(): Boolean
begin
exit(PostToGL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2123,6 +2123,24 @@ codeunit 12 "Gen. Jnl.-Post Line"
SequenceNoMgt.ValidateSeqNo(TableNo);
end;

/// <summary>
/// Invalidates the transaction-scoped caches in this codeunit so the next call to RunWithCheck
/// is forced through StartPosting (which re-takes the G/L Entry table lock and re-reads the
/// last entry number from disk) instead of taking the ContinuePosting fast path with a stale
/// NextEntryNo.
/// </summary>
procedure ResetTransactionState()
begin
NextEntryNo := 0;
NextTransactionNo := 0;
NextVATEntryNo := 0;
FirstEntryNo := 0;
FirstNewVATEntryNo := 0;
IsGLRegInserted := false;
TempGLEntryBuf.Reset();
TempGLEntryBuf.DeleteAll();
end;

/// <summary>
/// Checks if transaction is balanced for both local and additional currencies, inserts all G/L Entries that were created for the Gen. Journal Line.
/// If posting is performed for application purpose, original Customer and Vendor Ledger Entries are updated to reflect that.
Expand Down
Loading
Loading