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 @@ -1172,6 +1172,8 @@ page 291 "Req. Worksheet"
SetControlAppearanceFromWkshBatch();
exit;
end;
if GetCurrentJnlBatchName() then
exit;
OnBeforeTemplateSelection(Rec, CurrentJnlBatchName);
ReqJnlManagement.WkshTemplateSelection(
PAGE::"Req. Worksheet", false, Enum::"Req. Worksheet Template Type"::"Req.", Rec, JnlSelected);
Expand Down Expand Up @@ -1252,6 +1254,21 @@ page 291 "Req. Worksheet"
RequisitionWkshName.SetApprovalStateForWkshBatch(RequisitionWkshName, Rec, OpenApprovalEntriesExistForCurrUser, OpenApprovalEntriesOnWkshBatchExist, CanCancelApprovalForWkshBatch, CanRequestFlowApprovalForWkshBatch, CanCancelFlowApprovalForWkshBatch, ApprovalEntriesExistSentByCurrentUser, EnabledWkshBatchWorkflowsExist);
end;

local procedure GetCurrentJnlBatchName(): boolean
begin
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(true);
end
else
exit(false);
end;

[IntegrationEvent(false, false)]
local procedure OnAfterLookupCurrentJnlBatchName(var RequisitionLine: Record "Requisition Line"; var CurrJnlBatchName: Code[10])
begin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,10 @@ page 291 "Req. Worksheet"
SetControlAppearanceFromWkshBatch();
exit;
end;

if GetCurrentJnlBatchName() then
exit;

OnBeforeTemplateSelection(Rec, CurrentJnlBatchName);
ReqJnlManagement.WkshTemplateSelection(
PAGE::"Req. Worksheet", false, Enum::"Req. Worksheet Template Type"::"Req.", Rec, JnlSelected);
Expand Down Expand Up @@ -1241,6 +1245,21 @@ page 291 "Req. Worksheet"
RequisitionWkshName.SetApprovalStateForWkshBatch(RequisitionWkshName, Rec, OpenApprovalEntriesExistForCurrUser, OpenApprovalEntriesOnWkshBatchExist, CanCancelApprovalForWkshBatch, CanRequestFlowApprovalForWkshBatch, CanCancelFlowApprovalForWkshBatch, ApprovalEntriesExistSentByCurrentUser, EnabledWkshBatchWorkflowsExist);
end;

local procedure GetCurrentJnlBatchName(): boolean
begin
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(true);
end

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.

$\textbf{🟡\ Medium\ Severity\ —\ Style} \quad \color{gray}{\texttt{\small Iteration\ 2}}$

In the new local procedure GetCurrentJnlBatchName, the then-branch of the if already ends with a terminating exit(true), so the following else exit(false) is structural noise.

Per BCQuality style guidance, drop the else and let exit(false) fall through unconditionally after the if block.

Suggested fix (apply manually — could not be anchored as a one-click suggestion):

        end;
        exit(false);

Knowledge:

👍 useful · ❤️ especially valuable · 👎 wrong - reply with why

else
exit(false);
end;

[IntegrationEvent(false, false)]
local procedure OnAfterLookupCurrentJnlBatchName(var RequisitionLine: Record "Requisition Line"; var CurrJnlBatchName: Code[10])
begin
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;
}