From e8c80f2539e68874237e97714c7478cb368f79d2 Mon Sep 17 00:00:00 2001 From: alexei-dobriansky <77933119+alexei-dobriansky@users.noreply.github.com> Date: Fri, 3 Jul 2026 16:39:21 +0200 Subject: [PATCH 1/2] Bug 641331: Copy Production Order Document lookup shows the current document Report 99003802 LookupDocNo() only set SetRange(Status, StatusType) and never excluded the target document, so the current production order appeared in the Document No. lookup and could be selected, producing a late "cannot be copied onto itself" error. Exclude the target with SetFilter("No.", '<>%1', ...) when the from-status matches the target's status, mirroring Copy Sales/Purchase Document. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../CopyProductionOrderDocument.Report.al | 2 + .../SCMManufacturing.Codeunit.al | 58 +++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/src/Layers/W1/BaseApp/Manufacturing/Document/CopyProductionOrderDocument.Report.al b/src/Layers/W1/BaseApp/Manufacturing/Document/CopyProductionOrderDocument.Report.al index 7f57cfa28e..1a172678e0 100644 --- a/src/Layers/W1/BaseApp/Manufacturing/Document/CopyProductionOrderDocument.Report.al +++ b/src/Layers/W1/BaseApp/Manufacturing/Document/CopyProductionOrderDocument.Report.al @@ -129,6 +129,8 @@ report 99003802 "Copy Production Order Document" local procedure LookupDocNo() begin FromProdOrder.SetRange(Status, StatusType); + if ToProdOrder.Status = StatusType then + FromProdOrder.SetFilter("No.", '<>%1', ToProdOrder."No."); FromProdOrder."No." := DocNo; if PAGE.RunModal(0, FromProdOrder) = ACTION::LookupOK then DocNo := FromProdOrder."No."; diff --git a/src/Layers/W1/Tests/SCM-Manufacturing/SCMManufacturing.Codeunit.al b/src/Layers/W1/Tests/SCM-Manufacturing/SCMManufacturing.Codeunit.al index 32a162e3cf..d643cad2e2 100644 --- a/src/Layers/W1/Tests/SCM-Manufacturing/SCMManufacturing.Codeunit.al +++ b/src/Layers/W1/Tests/SCM-Manufacturing/SCMManufacturing.Codeunit.al @@ -208,6 +208,35 @@ codeunit 137404 "SCM Manufacturing" CopyProductionOrder(ProductionOrder.Status::Released); end; + [Test] + [HandlerFunctions('CopyProdOrderDocLookupRequestPageHandler,ProductionOrderListModalPageHandler')] + [Scope('OnPrem')] + procedure CopyProductionOrderDocumentLookupExcludesTargetOrder() + var + TargetProductionOrder: Record "Production Order"; + SourceProductionOrder: Record "Production Order"; + CopyProductionOrderDocument: Report "Copy Production Order Document"; + begin + // [FEATURE] [Copy Production Order] + // [SCENARIO 641331] The Copy Production Order Document lookup does not list the target production order itself. + Initialize(); + + // [GIVEN] A target Released production order and another Released production order to copy from + CreateReleasedProductionOrder(TargetProductionOrder); + CreateReleasedProductionOrder(SourceProductionOrder); + + // [WHEN] Opening the Document No. lookup for the target with status Released + LibraryVariableStorage.Enqueue("Production Order Status"::Released); + LibraryVariableStorage.Enqueue(TargetProductionOrder."No."); + LibraryVariableStorage.Enqueue(SourceProductionOrder."No."); + Clear(CopyProductionOrderDocument); + CopyProductionOrderDocument.SetProdOrder(TargetProductionOrder); + CopyProductionOrderDocument.Run(); + + // [THEN] The target is absent from the lookup and the source can be selected (verified in the handlers) + LibraryVariableStorage.AssertEmpty(); + end; + local procedure CopyProductionOrder(Status: Enum "Production Order Status") var ProductionOrder: Record "Production Order"; @@ -7350,6 +7379,35 @@ codeunit 137404 "SCM Manufacturing" CopyProductionOrderDocument.OK().Invoke(); end; + [RequestPageHandler] + [Scope('OnPrem')] + procedure CopyProdOrderDocLookupRequestPageHandler(var CopyProductionOrderDocument: TestRequestPage "Copy Production Order Document") + begin + CopyProductionOrderDocument.Status.SetValue(LibraryVariableStorage.DequeueInteger()); + CopyProductionOrderDocument.DocumentNo.Lookup(); + CopyProductionOrderDocument.Cancel().Invoke(); + end; + + [ModalPageHandler] + [Scope('OnPrem')] + procedure ProductionOrderListModalPageHandler(var ProductionOrderList: TestPage "Production Order List") + var + TargetNo: Code[20]; + SourceNo: Code[20]; + begin + TargetNo := CopyStr(LibraryVariableStorage.DequeueText(), 1, MaxStrLen(TargetNo)); + SourceNo := CopyStr(LibraryVariableStorage.DequeueText(), 1, MaxStrLen(SourceNo)); + + // The target production order must not appear in the lookup. + ProductionOrderList.Filter.SetFilter("No.", TargetNo); + Assert.IsFalse(ProductionOrderList.First(), 'The target production order must not appear in the Copy Production Order Document lookup.'); + + // The source production order can be selected. + ProductionOrderList.Filter.SetFilter("No.", SourceNo); + Assert.IsTrue(ProductionOrderList.First(), 'The source production order should be selectable in the lookup.'); + ProductionOrderList.OK().Invoke(); + end; + [RequestPageHandler] [Scope('OnPrem')] procedure ImplementRegisteredAbsenceHandler(var ImplementRegisteredAbsence: TestRequestPage "Implement Registered Absence") From 61cc2c72a8eb8886641dc40f4827789c8d6e2efe Mon Sep 17 00:00:00 2001 From: alexei-dobriansky <77933119+alexei-dobriansky@users.noreply.github.com> Date: Fri, 3 Jul 2026 16:40:03 +0200 Subject: [PATCH 2/2] Bug 641331: Propagate Copy Production Order Document lookup test to CZ layer Miapp propagation of the new SCMManufacturing test to the CZ Tests layer. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../SCMManufacturing.Codeunit.al | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/Layers/CZ/Tests/SCM-Manufacturing/SCMManufacturing.Codeunit.al b/src/Layers/CZ/Tests/SCM-Manufacturing/SCMManufacturing.Codeunit.al index 00731dc74c..fc618e65a8 100644 --- a/src/Layers/CZ/Tests/SCM-Manufacturing/SCMManufacturing.Codeunit.al +++ b/src/Layers/CZ/Tests/SCM-Manufacturing/SCMManufacturing.Codeunit.al @@ -208,6 +208,35 @@ codeunit 137404 "SCM Manufacturing" CopyProductionOrder(ProductionOrder.Status::Released); end; + [Test] + [HandlerFunctions('CopyProdOrderDocLookupRequestPageHandler,ProductionOrderListModalPageHandler')] + [Scope('OnPrem')] + procedure CopyProductionOrderDocumentLookupExcludesTargetOrder() + var + TargetProductionOrder: Record "Production Order"; + SourceProductionOrder: Record "Production Order"; + CopyProductionOrderDocument: Report "Copy Production Order Document"; + begin + // [FEATURE] [Copy Production Order] + // [SCENARIO 641331] The Copy Production Order Document lookup does not list the target production order itself. + Initialize(); + + // [GIVEN] A target Released production order and another Released production order to copy from + CreateReleasedProductionOrder(TargetProductionOrder); + CreateReleasedProductionOrder(SourceProductionOrder); + + // [WHEN] Opening the Document No. lookup for the target with status Released + LibraryVariableStorage.Enqueue("Production Order Status"::Released); + LibraryVariableStorage.Enqueue(TargetProductionOrder."No."); + LibraryVariableStorage.Enqueue(SourceProductionOrder."No."); + Clear(CopyProductionOrderDocument); + CopyProductionOrderDocument.SetProdOrder(TargetProductionOrder); + CopyProductionOrderDocument.Run(); + + // [THEN] The target is absent from the lookup and the source can be selected (verified in the handlers) + LibraryVariableStorage.AssertEmpty(); + end; + local procedure CopyProductionOrder(Status: Enum "Production Order Status") var ProductionOrder: Record "Production Order"; @@ -7354,6 +7383,35 @@ codeunit 137404 "SCM Manufacturing" CopyProductionOrderDocument.OK().Invoke(); end; + [RequestPageHandler] + [Scope('OnPrem')] + procedure CopyProdOrderDocLookupRequestPageHandler(var CopyProductionOrderDocument: TestRequestPage "Copy Production Order Document") + begin + CopyProductionOrderDocument.Status.SetValue(LibraryVariableStorage.DequeueInteger()); + CopyProductionOrderDocument.DocumentNo.Lookup(); + CopyProductionOrderDocument.Cancel().Invoke(); + end; + + [ModalPageHandler] + [Scope('OnPrem')] + procedure ProductionOrderListModalPageHandler(var ProductionOrderList: TestPage "Production Order List") + var + TargetNo: Code[20]; + SourceNo: Code[20]; + begin + TargetNo := CopyStr(LibraryVariableStorage.DequeueText(), 1, MaxStrLen(TargetNo)); + SourceNo := CopyStr(LibraryVariableStorage.DequeueText(), 1, MaxStrLen(SourceNo)); + + // The target production order must not appear in the lookup. + ProductionOrderList.Filter.SetFilter("No.", TargetNo); + Assert.IsFalse(ProductionOrderList.First(), 'The target production order must not appear in the Copy Production Order Document lookup.'); + + // The source production order can be selected. + ProductionOrderList.Filter.SetFilter("No.", SourceNo); + Assert.IsTrue(ProductionOrderList.First(), 'The source production order should be selectable in the lookup.'); + ProductionOrderList.OK().Invoke(); + end; + [RequestPageHandler] [Scope('OnPrem')] procedure ImplementRegisteredAbsenceHandler(var ImplementRegisteredAbsence: TestRequestPage "Implement Registered Absence")