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

GP - Safe Batch Posting #26608

Merged
merged 3 commits into from
Jun 6, 2024
Merged
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 @@ -346,15 +346,14 @@ codeunit 4019 "GP Item Migrator"
TempTrackingSpecification: Record "Tracking Specification" temporary;
DataMigrationErrorLogging: Codeunit "Data Migration Error Logging";
CreateReserveEntry: Codeunit "Create Reserv. Entry";
ItemJnlLineReserve: Codeunit "Item Jnl. Line-Reserve";
ExpirationDate: Date;
begin
if GPItem.ItemTrackingCode = '' then
exit;

DataMigrationErrorLogging.SetLastRecordUnderProcessing(Format(GPItemTransactions.RecordId));

ItemJnlLineReserve.InitFromItemJnlLine(TempTrackingSpecification, ItemJnlLine);
TempTrackingSpecification.InitFromItemJnlLine(ItemJnlLine);
jaymckinney-enavate marked this conversation as resolved.
Show resolved Hide resolved

if GPItemTransactions.ExpirationDate = DMY2Date(1, 1, 1900) then
ExpirationDate := 0D
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ codeunit 4037 "Helper Functions"
CloudMigrationTok: Label 'CloudMigration', Locked = true;
GeneralTemplateNameTxt: Label 'GENERAL', Locked = true;
NotAllJournalLinesPostedMsg: Label 'Not all journal lines were posted. Number of unposted lines - %1.', Comment = '%1 Number of unposted lines';
MigrationLogAreaBatchPostingTxt: Label 'Batch Posting', Locked = true;

procedure GetTextFromJToken(JToken: JsonToken; Path: Text): Text
var
Expand Down Expand Up @@ -1241,7 +1242,7 @@ codeunit 4037 "Helper Functions"
ItemJournalLine.SetRange("Journal Batch Name", ItemJournalBatch.Name);
ItemJournalLine.SetFilter("Item No.", '<>%1', '');
if not ItemJournalLine.IsEmpty() then
PostItemBatch(ItemJournalBatch);
SafePostItemBatch(ItemJournalBatch);
until ItemJournalBatch.Next() = 0;

// Account batches
Expand All @@ -1260,7 +1261,7 @@ codeunit 4037 "Helper Functions"
GenJournalLine.SetRange("Journal Template Name", GeneralTemplateNameTxt);
GenJournalLine.SetRange("Journal Batch Name", JournalBatchName);
if not GenJournalLine.IsEmpty() then
PostGLBatch(CopyStr(JournalBatchName, 1, 10));
SafePostGLBatch(CopyStr(JournalBatchName, 1, 10));
end;
until GenJournalBatch.Next() = 0;

Expand All @@ -1270,7 +1271,7 @@ codeunit 4037 "Helper Functions"
repeat
StatisticalAccJournalLine.SetRange("Journal Batch Name", StatisticalAccJournalBatch.Name);
if not StatisticalAccJournalLine.IsEmpty() then
PostStatisticalAccBatch(StatisticalAccJournalBatch.Name);
SafePostStatisticalAccBatch(StatisticalAccJournalBatch.Name);
until StatisticalAccJournalBatch.Next() = 0;
end;

Expand All @@ -1283,7 +1284,7 @@ codeunit 4037 "Helper Functions"
GenJournalLine.SetRange("Journal Template Name", GeneralTemplateNameTxt);
GenJournalLine.SetRange("Journal Batch Name", JournalBatchName);
if not GenJournalLine.IsEmpty() then
PostGLBatch(CopyStr(JournalBatchName, 1, 10));
SafePostGLBatch(CopyStr(JournalBatchName, 1, 10));
end;

// Vendor batches
Expand All @@ -1295,7 +1296,7 @@ codeunit 4037 "Helper Functions"
GenJournalLine.SetRange("Journal Template Name", GeneralTemplateNameTxt);
GenJournalLine.SetRange("Journal Batch Name", JournalBatchName);
if not GenJournalLine.IsEmpty() then
PostGLBatch(CopyStr(JournalBatchName, 1, 10));
SafePostGLBatch(CopyStr(JournalBatchName, 1, 10));
end;

// Bank batches
Expand All @@ -1307,7 +1308,7 @@ codeunit 4037 "Helper Functions"
GenJournalLine.SetRange("Journal Template Name", GeneralTemplateNameTxt);
GenJournalLine.SetRange("Journal Batch Name", JournalBatchName);
if not GenJournalLine.IsEmpty() then
PostGLBatch(CopyStr(JournalBatchName, 1, 10));
SafePostGLBatch(CopyStr(JournalBatchName, 1, 10));
end;

// Remove posted batches
Expand All @@ -1316,6 +1317,7 @@ codeunit 4037 "Helper Functions"
Session.LogMessage('00007GK', StrSubstNo(FinishedTelemetryTxt, DurationAsInt), Verbosity::Normal, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, 'Category', GetTelemetryCategory());
end;

[Obsolete('This procedure will be soon removed.', '26.0')]
procedure PostGLBatch(JournalBatchName: Code[10])
var
GenJournalLine: Record "Gen. Journal Line";
Expand All @@ -1342,6 +1344,21 @@ codeunit 4037 "Helper Functions"
codeunit.Run(codeunit::"Gen. Jnl.-Post Batch", GenJournalLine);
end;

local procedure SafePostGLBatch(JournalBatchName: Code[10])
var
GenJournalLine: Record "Gen. Journal Line";
begin
GenJournalLine.SetRange("Journal Template Name", GeneralTemplateNameTxt);
GenJournalLine.SetRange("Journal Batch Name", JournalBatchName);
if GenJournalLine.FindFirst() then begin
jaymckinney-enavate marked this conversation as resolved.
Show resolved Hide resolved
// Commit is required to safely handle errors that may occur during posting.
Commit();
if not Codeunit.Run(Codeunit::"Gen. Jnl.-Post Batch", GenJournalLine) then
LogWarningAndClearLastError(JournalBatchName);
end;
end;

[Obsolete('This procedure will be soon removed.', '26.0')]
procedure PostStatisticalAccBatch(JournalBatchName: Code[10])
var
StatisticalAccJournalLine: Record "Statistical Acc. Journal Line";
Expand All @@ -1351,14 +1368,41 @@ codeunit 4037 "Helper Functions"
Codeunit.Run(Codeunit::"Stat. Acc. Post. Batch", StatisticalAccJournalLine);
end;

local procedure PostItemBatch(ItemJournalBatch: Record "Item Journal Batch")
local procedure SafePostStatisticalAccBatch(JournalBatchName: Code[10])
var
StatisticalAccJournalLine: Record "Statistical Acc. Journal Line";
begin
StatisticalAccJournalLine.SetRange("Journal Batch Name", JournalBatchName);
if StatisticalAccJournalLine.FindFirst() then begin
jaymckinney-enavate marked this conversation as resolved.
Show resolved Hide resolved
// Commit is required to safely handle errors that may occur during posting.
Commit();
if not Codeunit.Run(Codeunit::"Stat. Acc. Post. Batch", StatisticalAccJournalLine) then
LogWarningAndClearLastError(JournalBatchName);
end;
end;

local procedure SafePostItemBatch(ItemJournalBatch: Record "Item Journal Batch")
var
ItemJournalLine: Record "Item Journal Line";
begin
ItemJournalLine.SetRange("Journal Template Name", ItemJournalBatch."Journal Template Name");
ItemJournalLine.SetRange("Journal Batch Name", ItemJournalBatch.Name);
if ItemJournalLine.FindFirst() then
Codeunit.Run(Codeunit::"Item Jnl.-Post Batch", ItemJournalLine);
if ItemJournalLine.FindFirst() then begin
jaymckinney-enavate marked this conversation as resolved.
Show resolved Hide resolved
// Commit is required to safely handle errors that may occur during posting.
Commit();
if not Codeunit.Run(Codeunit::"Item Jnl.-Post Batch", ItemJournalLine) then
LogWarningAndClearLastError(ItemJournalBatch.Name);
end;
end;

internal procedure LogWarningAndClearLastError(ContextValue: Text[50])
var
GPMigrationWarnings: Record "GP Migration Warnings";
WarningText: Text[500];
begin
WarningText := CopyStr(GetLastErrorText(false), 1, MaxStrLen(WarningText));
GPMigrationWarnings.InsertWarning(MigrationLogAreaBatchPostingTxt, ContextValue, WarningText);
ClearLastError();
end;

local procedure GLBatchHasLines(TemplateName: Code[10]; BatchName: Code[10]; AccountType: Enum "Gen. Journal Account Type"): Boolean
Expand Down
Loading