diff --git a/src/Apps/W1/Subscription Billing/App/Service Commitments/Tables/SubscriptionLine.Table.al b/src/Apps/W1/Subscription Billing/App/Service Commitments/Tables/SubscriptionLine.Table.al index c9c071b8e6..f5e28d8dd7 100644 --- a/src/Apps/W1/Subscription Billing/App/Service Commitments/Tables/SubscriptionLine.Table.al +++ b/src/Apps/W1/Subscription Billing/App/Service Commitments/Tables/SubscriptionLine.Table.al @@ -752,6 +752,8 @@ table 8059 "Subscription Line" begin if IsInitialTermEmpty() then exit; + if not IsExtensionTermEmpty() then + exit; TestField("Subscription Line Start Date"); "Subscription Line End Date" := CalcDate("Initial Term", "Subscription Line Start Date"); @@ -764,10 +766,16 @@ table 8059 "Subscription Line" if "Subscription Line End Date" <> 0D then "Term Until" := "Subscription Line End Date" else - if not IsNoticePeriodEmpty() then begin + if not IsExtensionTermEmpty() then begin TestField("Subscription Line Start Date"); - "Term Until" := CalcDate("Notice Period", "Subscription Line Start Date"); - "Term Until" := CalcDate('<-1D>', "Term Until"); + if not IsInitialTermEmpty() then begin + "Term Until" := CalcDate("Initial Term", "Subscription Line Start Date"); + "Term Until" := CalcDate('<-1D>', "Term Until"); + end else + if not IsNoticePeriodEmpty() then begin + "Term Until" := CalcDate("Notice Period", "Subscription Line Start Date"); + "Term Until" := CalcDate('<-1D>', "Term Until"); + end; end; CalculateCancellationPossibleUntil(); end; diff --git a/src/Apps/W1/Subscription Billing/Test/Service Commitments/SalesServiceCommitmentTest.Codeunit.al b/src/Apps/W1/Subscription Billing/Test/Service Commitments/SalesServiceCommitmentTest.Codeunit.al index bfe4501dca..d1dddf514d 100644 --- a/src/Apps/W1/Subscription Billing/Test/Service Commitments/SalesServiceCommitmentTest.Codeunit.al +++ b/src/Apps/W1/Subscription Billing/Test/Service Commitments/SalesServiceCommitmentTest.Codeunit.al @@ -2083,6 +2083,32 @@ codeunit 139915 "Sales Service Commitment Test" Assert.AreEqual(SalespersonPurchaser.Code, ServiceObject."Salesperson Code", 'Salesperson Code should be populated from Customer'); end; + [Test] + procedure CheckSubscriptionLineEndDateNotSetWhenSubsequentTermIsUsed() + begin + // [SCENARIO] When posting a Sales Order for an item with both Initial Term and Subsequent Term, + // the resulting Subscription Line End Date must remain empty (contract auto-renews indefinitely) + Initialize(); + + // [GIVEN] A Sales Service Commitment Item with a package having Initial Term <12M> and Subsequent Term <12M> + // Note: InitServiceCommitmentPackageLineFields (called in Initialize) already sets both terms + ContractTestLibrary.SetupSalesServiceCommitmentItemAndAssignToServiceCommitmentPackage(Item, Enum::"Item Service Commitment Type"::"Sales with Service Commitment", ServiceCommitmentPackage.Code); + + // [GIVEN] A Sales Order for the item + LibrarySales.CreateSalesHeader(SalesHeader, SalesHeader."Document Type"::Order, ''); + LibrarySales.CreateSalesLineWithShipmentDate(SalesLine, SalesHeader, Enum::"Sales Line Type"::Item, Item."No.", WorkDate(), 1); + + // [WHEN] The Sales Order is posted + LibrarySales.PostSalesDocument(SalesHeader, true, true); + + // [THEN] The resulting Subscription Line End Date is empty because a Subsequent Term is defined + ServiceObject.FilterOnItemNo(Item."No."); + ServiceObject.FindFirst(); + ServiceCommitment.SetRange("Subscription Header No.", ServiceObject."No."); + ServiceCommitment.FindFirst(); + ServiceCommitment.TestField("Subscription Line End Date", 0D); + end; + #endregion Tests #region Procedures diff --git a/src/Apps/W1/Subscription Billing/Test/Service Objects/ServiceObjectTest.Codeunit.al b/src/Apps/W1/Subscription Billing/Test/Service Objects/ServiceObjectTest.Codeunit.al index 31614eb724..9869932204 100644 --- a/src/Apps/W1/Subscription Billing/Test/Service Objects/ServiceObjectTest.Codeunit.al +++ b/src/Apps/W1/Subscription Billing/Test/Service Objects/ServiceObjectTest.Codeunit.al @@ -308,8 +308,8 @@ codeunit 148157 "Service Object Test" SubscriptionLine.SetRange("Subscription Header No.", SubscriptionHeader."No."); SubscriptionLine.FindFirst(); - // [GIVEN] The Subscription Line End Date, Term Until, and Cancellation Possible Until are populated - Assert.AreNotEqual(0D, SubscriptionLine."Subscription Line End Date", '"Service End Date" not set.'); + // [GIVEN] End Date is not auto-set because Subsequent Term (Extension Term) is defined; Term Until and Cancellation are still populated + Assert.AreEqual(0D, SubscriptionLine."Subscription Line End Date", '"Service End Date" should not be set when Subsequent Term is defined.'); Assert.AreNotEqual(0D, SubscriptionLine."Term Until", '"Term Until" not set.'); Assert.AreNotEqual(0D, SubscriptionLine."Cancellation Possible Until", '"Cancellation Possible Until" is not set.'); @@ -688,6 +688,34 @@ codeunit 148157 "Service Object Test" SubscriptionLine.TestField("Subscription Line End Date", 0D); end; + [Test] + procedure CheckSubscriptionLineEndDateNotSetWhenSubsequentTermIsUsed() + var + Item: Record Item; + SubscriptionLine: Record "Subscription Line"; + SubscriptionHeader: Record "Subscription Header"; + DateFormulaVariable: DateFormula; + begin + // [SCENARIO] CalculateServiceEndDate does not set End Date when Subsequent Term (Extension Term) is defined + Initialize(); + + SetupServiceObjectWithServiceCommitment(Item, SubscriptionHeader, false, false); + FindServiceCommitment(SubscriptionLine, SubscriptionHeader."No."); + + // [GIVEN] A Subscription Line with Start Date, Initial Term of 1 month, and Subsequent Term of 1 month + SubscriptionLine.Validate("Subscription Line Start Date", WorkDate()); + Evaluate(DateFormulaVariable, '<1M>'); + SubscriptionLine.Validate("Initial Term", DateFormulaVariable); + SubscriptionLine.Validate("Extension Term", DateFormulaVariable); + + // [WHEN] CalculateServiceEndDate is called + SubscriptionLine.CalculateServiceEndDate(); + + // [THEN] Subscription Line End Date remains empty because Subsequent Term is defined + SubscriptionLine.TestField("Subscription Line End Date", 0D); + end; + + [Test] procedure CheckServiceCommitmentServiceInitialTerminationDatesCalculation() var @@ -1926,8 +1954,11 @@ codeunit 148157 "Service Object Test" ExpectedTermUntil: Date; ExpectedCancellationPossibleUntil: Date; begin - ExpectedEndDate := CalcDate(InitialTerm + '-1D', StartDate); - ExpectedTermUntil := ExpectedEndDate; + ExpectedTermUntil := CalcDate(InitialTerm + '-1D', StartDate); + if Format(SubscriptionLine."Extension Term") = '' then + ExpectedEndDate := ExpectedTermUntil + else + ExpectedEndDate := 0D; ExpectedCancellationPossibleUntil := CalcDate('-' + NoticePeriod, ExpectedTermUntil); if DateTimeManagement.IsLastDayOfMonth(ExpectedTermUntil) then DateTimeManagement.MoveDateToLastDayOfMonth(ExpectedCancellationPossibleUntil);