Skip to content
Closed
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 @@ -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;
Expand All @@ -694,27 +695,31 @@ table 5093 "Opportunity Entry"
TempSalesCycleStageNext.FindFirst();
"Sales Cycle Stage" := TempSalesCycleStageNext.Stage;
"Sales Cycle Stage Description" := TempSalesCycleStageNext.Description;
"Chances of Success %" := TempSalesCycleStageNext."Chances of Success %";
"Action Taken" := "Action Taken"::Next;
end;
"Action Type"::Previous:
begin
TempSalesCycleStagePrevious.FindFirst();
"Sales Cycle Stage" := TempSalesCycleStagePrevious.Stage;
"Sales Cycle Stage Description" := TempSalesCycleStagePrevious.Description;
"Chances of Success %" := TempSalesCycleStagePrevious."Chances of Success %";
"Action Taken" := "Action Taken"::Previous;
end;
"Action Type"::Skip:
begin
TempSalesCycleStageSkip.FindFirst();
"Sales Cycle Stage" := TempSalesCycleStageSkip.Stage;
"Sales Cycle Stage Description" := TempSalesCycleStageSkip.Description;
"Chances of Success %" := TempSalesCycleStageSkip."Chances of Success %";
"Action Taken" := "Action Taken"::Jumped;
end;
"Action Type"::Update:
begin
TempSalesCycleStageUpdate.FindFirst();
"Sales Cycle Stage" := TempSalesCycleStageUpdate.Stage;
"Sales Cycle Stage Description" := TempSalesCycleStageUpdate.Description;
"Chances of Success %" := TempSalesCycleStageUpdate."Chances of Success %";
"Action Taken" := "Action Taken"::Updated;
"Cancel Old To Do" := false;
end;
Expand All @@ -723,6 +728,7 @@ table 5093 "Opportunity Entry"
TempSalesCycleStageJump.FindLast();
"Sales Cycle Stage" := TempSalesCycleStageJump.Stage;
"Sales Cycle Stage Description" := TempSalesCycleStageJump.Description;
"Chances of Success %" := TempSalesCycleStageJump."Chances of Success %";
"Action Taken" := "Action Taken"::Jumped;
end;
end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Loading