From b9ba2a4b92ca36ff79191cf938971d9222426d91 Mon Sep 17 00:00:00 2001 From: v-shuklad Date: Tue, 30 Jun 2026 16:45:40 +0530 Subject: [PATCH 1/2] Changes --- .../CRM/Opportunity/OpportunityEntry.Table.al | 6 ++ .../MarketingOpportunityMgmt.Codeunit.al | 65 +++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/src/Layers/W1/BaseApp/CRM/Opportunity/OpportunityEntry.Table.al b/src/Layers/W1/BaseApp/CRM/Opportunity/OpportunityEntry.Table.al index 0d8498cc2e..1e51eeba02 100644 --- a/src/Layers/W1/BaseApp/CRM/Opportunity/OpportunityEntry.Table.al +++ b/src/Layers/W1/BaseApp/CRM/Opportunity/OpportunityEntry.Table.al @@ -686,6 +686,7 @@ table 5093 "Opportunity Entry" TempSalesCycleStageFirst.FindFirst(); "Sales Cycle Stage" := TempSalesCycleStageFirst.Stage; "Sales Cycle Stage Description" := TempSalesCycleStageFirst.Description; + "Chances of Success %" := TempSalesCycleStageFirst."Chances of Success %"; "Action Taken" := "Action Taken"::" "; "Cancel Old To Do" := false; end; @@ -694,6 +695,7 @@ table 5093 "Opportunity Entry" TempSalesCycleStageNext.FindFirst(); "Sales Cycle Stage" := TempSalesCycleStageNext.Stage; "Sales Cycle Stage Description" := TempSalesCycleStageNext.Description; + "Chances of Success %" := TempSalesCycleStageFirst."Chances of Success %"; "Action Taken" := "Action Taken"::Next; end; "Action Type"::Previous: @@ -701,6 +703,7 @@ table 5093 "Opportunity Entry" TempSalesCycleStagePrevious.FindFirst(); "Sales Cycle Stage" := TempSalesCycleStagePrevious.Stage; "Sales Cycle Stage Description" := TempSalesCycleStagePrevious.Description; + "Chances of Success %" := TempSalesCycleStageFirst."Chances of Success %"; "Action Taken" := "Action Taken"::Previous; end; "Action Type"::Skip: @@ -708,6 +711,7 @@ table 5093 "Opportunity Entry" TempSalesCycleStageSkip.FindFirst(); "Sales Cycle Stage" := TempSalesCycleStageSkip.Stage; "Sales Cycle Stage Description" := TempSalesCycleStageSkip.Description; + "Chances of Success %" := TempSalesCycleStageFirst."Chances of Success %"; "Action Taken" := "Action Taken"::Jumped; end; "Action Type"::Update: @@ -715,6 +719,7 @@ table 5093 "Opportunity Entry" TempSalesCycleStageUpdate.FindFirst(); "Sales Cycle Stage" := TempSalesCycleStageUpdate.Stage; "Sales Cycle Stage Description" := TempSalesCycleStageUpdate.Description; + "Chances of Success %" := TempSalesCycleStageFirst."Chances of Success %"; "Action Taken" := "Action Taken"::Updated; "Cancel Old To Do" := false; end; @@ -723,6 +728,7 @@ table 5093 "Opportunity Entry" TempSalesCycleStageJump.FindLast(); "Sales Cycle Stage" := TempSalesCycleStageJump.Stage; "Sales Cycle Stage Description" := TempSalesCycleStageJump.Description; + "Chances of Success %" := TempSalesCycleStageFirst."Chances of Success %"; "Action Taken" := "Action Taken"::Jumped; end; end; diff --git a/src/Layers/W1/Tests/Marketing/MarketingOpportunityMgmt.Codeunit.al b/src/Layers/W1/Tests/Marketing/MarketingOpportunityMgmt.Codeunit.al index 493bd583ef..878c78a0cb 100644 --- a/src/Layers/W1/Tests/Marketing/MarketingOpportunityMgmt.Codeunit.al +++ b/src/Layers/W1/Tests/Marketing/MarketingOpportunityMgmt.Codeunit.al @@ -1936,6 +1936,71 @@ codeunit 136209 "Marketing Opportunity Mgmt" Format(OpportunityEntry."Action Type"::Skip))); end; + [Test] + procedure ChancesOfSuccessRevertsToCurrentStageOnActionTypeUpdate() + var + ActiveOpportunityEntry: Record "Opportunity Entry"; + Opportunity: Record Opportunity; + OpportunityEntry: Record "Opportunity Entry"; + SalesCycle: Record "Sales Cycle"; + SaleCycleStage1: Record "Sales Cycle Stage"; + SaleCycleStage2: Record "Sales Cycle Stage"; + Stage1Chances: Decimal; + Stage2Chances: Decimal; + begin + // [FEATURE] [AI test 0.4] + // [SCENARIO] Changing Action Type to Update reverts Chances of Success % to the current stage value + Initialize(); + + // [GIVEN] Sales Cycle "SC" with Stage 1 having Chances of Success % "C1" and Stage 2 having Chances of Success % "C2" + LibraryMarketing.CreateSalesCycle(SalesCycle); + CreateSalesCycleStage(SaleCycleStage1, SalesCycle.Code); + Stage1Chances := SaleCycleStage1."Chances of Success %"; + CreateSalesCycleStage(SaleCycleStage2, SalesCycle.Code); + Stage2Chances := SaleCycleStage2."Chances of Success %"; + + // [GIVEN] Opportunity "O" on Stage 1 with active entry + LibraryMarketing.CreateOpportunity(Opportunity, LibraryMarketing.CreateCompanyContactNo()); + Opportunity."Sales Cycle Code" := SalesCycle.Code; + Opportunity.Status := Opportunity.Status::"In Progress"; + Opportunity.Modify(); + + CreateOppEntryForUpdateEstimates(ActiveOpportunityEntry, SalesCycle.Code, SaleCycleStage1.Stage, Stage1Chances); + ActiveOpportunityEntry."Opportunity No." := Opportunity."No."; + ActiveOpportunityEntry.Active := true; + ActiveOpportunityEntry.Modify(); + + // [GIVEN] New Opportunity Entry "OE" initialized for the wizard with CreateStageList defaulting to Action Type = Next + CreateOppEntryForUpdateEstimates(OpportunityEntry, SalesCycle.Code, SaleCycleStage1.Stage, Stage1Chances); + OpportunityEntry."Opportunity No." := Opportunity."No."; + OpportunityEntry.Modify(); + OpportunityEntry.CreateStageList(); + + // [GIVEN] WizardActionTypeValidate2 called for Action Type = Next sets Chances of Success % to Stage 2 value + OpportunityEntry."Action Type" := OpportunityEntry."Action Type"::Next; + OpportunityEntry.WizardActionTypeValidate2(); + OpportunityEntry.Get(OpportunityEntry."Entry No."); + Assert.AreEqual( + Stage2Chances, + OpportunityEntry."Chances of Success %", + StrSubstNo( + ChancesOfSuccessOverrideErr, + Format(OpportunityEntry."Action Type"::Next))); + + // [WHEN] Action Type is changed to Update and WizardActionTypeValidate2 is called + OpportunityEntry."Action Type" := OpportunityEntry."Action Type"::Update; + OpportunityEntry.WizardActionTypeValidate2(); + + // [THEN] Chances of Success % reverts to Stage 1 value + OpportunityEntry.Get(OpportunityEntry."Entry No."); + Assert.AreEqual( + Stage1Chances, + OpportunityEntry."Chances of Success %", + StrSubstNo( + ChancesOfSuccessOverrideErr, + Format(OpportunityEntry."Action Type"::Update))); + end; + local procedure Initialize() begin LibraryTestInitialize.OnTestInitialize(CODEUNIT::"Marketing Opportunity Mgmt"); From 27be72b083cb6392af1752f4e7b7c004ef1be6e1 Mon Sep 17 00:00:00 2001 From: v-shuklad Date: Wed, 1 Jul 2026 09:59:51 +0530 Subject: [PATCH 2/2] Changes --- .../BaseApp/CRM/Opportunity/OpportunityEntry.Table.al | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Layers/W1/BaseApp/CRM/Opportunity/OpportunityEntry.Table.al b/src/Layers/W1/BaseApp/CRM/Opportunity/OpportunityEntry.Table.al index 1e51eeba02..902c7731e7 100644 --- a/src/Layers/W1/BaseApp/CRM/Opportunity/OpportunityEntry.Table.al +++ b/src/Layers/W1/BaseApp/CRM/Opportunity/OpportunityEntry.Table.al @@ -695,7 +695,7 @@ table 5093 "Opportunity Entry" TempSalesCycleStageNext.FindFirst(); "Sales Cycle Stage" := TempSalesCycleStageNext.Stage; "Sales Cycle Stage Description" := TempSalesCycleStageNext.Description; - "Chances of Success %" := TempSalesCycleStageFirst."Chances of Success %"; + "Chances of Success %" := TempSalesCycleStageNext."Chances of Success %"; "Action Taken" := "Action Taken"::Next; end; "Action Type"::Previous: @@ -703,7 +703,7 @@ table 5093 "Opportunity Entry" TempSalesCycleStagePrevious.FindFirst(); "Sales Cycle Stage" := TempSalesCycleStagePrevious.Stage; "Sales Cycle Stage Description" := TempSalesCycleStagePrevious.Description; - "Chances of Success %" := TempSalesCycleStageFirst."Chances of Success %"; + "Chances of Success %" := TempSalesCycleStagePrevious."Chances of Success %"; "Action Taken" := "Action Taken"::Previous; end; "Action Type"::Skip: @@ -711,7 +711,7 @@ table 5093 "Opportunity Entry" TempSalesCycleStageSkip.FindFirst(); "Sales Cycle Stage" := TempSalesCycleStageSkip.Stage; "Sales Cycle Stage Description" := TempSalesCycleStageSkip.Description; - "Chances of Success %" := TempSalesCycleStageFirst."Chances of Success %"; + "Chances of Success %" := TempSalesCycleStageSkip."Chances of Success %"; "Action Taken" := "Action Taken"::Jumped; end; "Action Type"::Update: @@ -719,7 +719,7 @@ table 5093 "Opportunity Entry" TempSalesCycleStageUpdate.FindFirst(); "Sales Cycle Stage" := TempSalesCycleStageUpdate.Stage; "Sales Cycle Stage Description" := TempSalesCycleStageUpdate.Description; - "Chances of Success %" := TempSalesCycleStageFirst."Chances of Success %"; + "Chances of Success %" := TempSalesCycleStageUpdate."Chances of Success %"; "Action Taken" := "Action Taken"::Updated; "Cancel Old To Do" := false; end; @@ -728,7 +728,7 @@ table 5093 "Opportunity Entry" TempSalesCycleStageJump.FindLast(); "Sales Cycle Stage" := TempSalesCycleStageJump.Stage; "Sales Cycle Stage Description" := TempSalesCycleStageJump.Description; - "Chances of Success %" := TempSalesCycleStageFirst."Chances of Success %"; + "Chances of Success %" := TempSalesCycleStageJump."Chances of Success %"; "Action Taken" := "Action Taken"::Jumped; end; end;