Skip to content
Draft
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 @@ -1172,6 +1172,18 @@ page 291 "Req. Worksheet"
SetControlAppearanceFromWkshBatch();
exit;
end;
// When the page is opened positioned on a specific worksheet batch (for example, from the
// Open Record action on an approval entry), use the batch from the record instead of the
// previously saved batch name that SaveValues would otherwise restore.
if (Rec."Journal Batch Name" <> '') and (Rec."Worksheet Template Name" <> '') then begin
CurrentJnlBatchName := Rec."Journal Batch Name";
Rec.FilterGroup := 2;
Rec.SetRange("Worksheet Template Name", Rec."Worksheet Template Name");
Rec.FilterGroup := 0;
ReqJnlManagement.OpenJnl(CurrentJnlBatchName, Rec);
SetControlAppearanceFromWkshBatch();
exit;
end;
OnBeforeTemplateSelection(Rec, CurrentJnlBatchName);
ReqJnlManagement.WkshTemplateSelection(
PAGE::"Req. Worksheet", false, Enum::"Req. Worksheet Template Type"::"Req.", Rec, JnlSelected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,18 @@ page 291 "Req. Worksheet"
SetControlAppearanceFromWkshBatch();
exit;
end;
// When the page is opened positioned on a specific worksheet batch (for example, from the
// Open Record action on an approval entry), use the batch from the record instead of the
// previously saved batch name that SaveValues would otherwise restore.
if (Rec."Journal Batch Name" <> '') and (Rec."Worksheet Template Name" <> '') then begin
CurrentJnlBatchName := Rec."Journal Batch Name";
Rec.FilterGroup := 2;
Rec.SetRange("Worksheet Template Name", Rec."Worksheet Template Name");
Rec.FilterGroup := 0;
ReqJnlManagement.OpenJnl(CurrentJnlBatchName, Rec);
SetControlAppearanceFromWkshBatch();
exit;
end;
OnBeforeTemplateSelection(Rec, CurrentJnlBatchName);
ReqJnlManagement.WkshTemplateSelection(
PAGE::"Req. Worksheet", false, Enum::"Req. Worksheet Template Type"::"Req.", Rec, JnlSelected);
Expand Down
51 changes: 51 additions & 0 deletions src/Layers/W1/Tests/SCM/WFWRequisitionWorksheet.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ codeunit 139506 "WFW Requisition Worksheet"
BatchWorkflowStatusFactboxMustBeVisibleLbl: Label 'Batch workflow Status factbox must be visible';
ImposedRestrictionMustBeShownLbl: Label 'Imposed restriction must be shown.';
CannotRenameRecordErr: Label 'You cannot rename a %1.', Comment = '%1 = Table Caption';
WrongBatchShownOnOpenRecordLbl: Label 'Open Record must show the requisition worksheet batch of the selected approval entry.';

[Test]
procedure TestEnsureNecessaryTableRelatiosnsAreSetup()
Expand Down Expand Up @@ -1545,6 +1546,47 @@ codeunit 139506 "WFW Requisition Worksheet"
Assert.ExpectedError('');
end;

[Test]
[HandlerFunctions('ReqWorksheetVerifyBatchPageHandler')]
procedure OpenRecordShowsCorrectBatchAfterViewingDifferentRequisitionWkshBatch()
var
FirstRequisitionWkshName: Record "Requisition Wksh. Name";
SecondRequisitionWkshName: Record "Requisition Wksh. Name";
TempRequisitionWkshName: Record "Requisition Wksh. Name" temporary;
RequisitionLine: Record "Requisition Line";
PageManagement: Codeunit "Page Management";
begin
// [SCENARIO 639932] Open Record shows the correct Requisition Worksheet batch after viewing a different batch.
Initialize();

// [GIVEN] Two Requisition Worksheet batches (same template), each with one requisition line.
CreateRequisitionWkshNameWithOneRequisitionLine(FirstRequisitionWkshName, RequisitionLine);
CreateRequisitionWkshNameWithOneRequisitionLine(SecondRequisitionWkshName, RequisitionLine);

// [GIVEN] The batches are ordered so the first one opened sorts before the second one.
if FirstRequisitionWkshName.Name > SecondRequisitionWkshName.Name then begin
TempRequisitionWkshName := FirstRequisitionWkshName;
FirstRequisitionWkshName := SecondRequisitionWkshName;
SecondRequisitionWkshName := TempRequisitionWkshName;
end;

// [GIVEN] Both batches have an open approval entry for the current user (as shown in Requests to Approve).
CreateOpenApprovalEntryForCurrentUser(FirstRequisitionWkshName.RecordId);
CreateOpenApprovalEntryForCurrentUser(SecondRequisitionWkshName.RecordId);
Commit();

// [GIVEN] The approver uses Open Record for the first batch and closes the worksheet.
LibraryVariableStorage.Enqueue(FirstRequisitionWkshName.Name);
PageManagement.PageRun(FirstRequisitionWkshName);

// [WHEN] The approver uses Open Record for the second, different batch.
LibraryVariableStorage.Enqueue(SecondRequisitionWkshName.Name);
PageManagement.PageRun(SecondRequisitionWkshName);

// [THEN] Each Open Record shows its own batch (verified in ReqWorksheetVerifyBatchPageHandler).
LibraryVariableStorage.AssertEmpty();
end;

local procedure Initialize()
var
Workflow: Record Workflow;
Expand Down Expand Up @@ -2032,4 +2074,13 @@ codeunit 139506 "WFW Requisition Worksheet"
LibraryVariableStorage.Dequeue(VariableVariant);
ApprovalEntries.Close();
end;

[PageHandler]
procedure ReqWorksheetVerifyBatchPageHandler(var ReqWorksheet: TestPage "Req. Worksheet")
begin
Assert.AreEqual(
LibraryVariableStorage.DequeueText(), ReqWorksheet.CurrentJnlBatchName.Value(),
WrongBatchShownOnOpenRecordLbl);
ReqWorksheet.Close();
end;
}
Loading