diff --git a/src/Apps/W1/Subscription Billing/App/Contract Renewal/Tables/PlannedSubscriptionLine.Table.al b/src/Apps/W1/Subscription Billing/App/Contract Renewal/Tables/PlannedSubscriptionLine.Table.al index 0fd7a7c2dd..609c7df913 100644 --- a/src/Apps/W1/Subscription Billing/App/Contract Renewal/Tables/PlannedSubscriptionLine.Table.al +++ b/src/Apps/W1/Subscription Billing/App/Contract Renewal/Tables/PlannedSubscriptionLine.Table.al @@ -197,6 +197,7 @@ table 8002 "Planned Subscription Line" if Format("Extension Term") = '' then TestField("Notice Period", "Extension Term"); DateFormulaManagement.ErrorIfDateFormulaNegative("Extension Term"); + CheckRatioBetweenBillingBasePeriodAndRhythm(); end; } field(23; "Billing Rhythm"; DateFormula) @@ -206,6 +207,7 @@ table 8002 "Planned Subscription Line" begin DateFormulaManagement.ErrorIfDateFormulaEmpty("Billing Rhythm", FieldCaption("Billing Rhythm")); DateFormulaManagement.ErrorIfDateFormulaNegative("Billing Rhythm"); + CheckRatioBetweenBillingBasePeriodAndRhythm(); end; } field(24; "Cancellation Possible Until"; Date) @@ -397,12 +399,6 @@ table 8002 "Planned Subscription Line" key(Contract; "Subscription Contract No.", "Subscription Contract Line No.") { } key(Quote; "Sales Quote No.", "Sales Quote Line No.") { } } - trigger OnModify() - begin - xRec.Get(xRec."Entry No."); - if ((xRec."Billing Base Period" <> Rec."Billing Base Period") or (xRec."Billing Rhythm" <> Rec."Billing Rhythm")) then - DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm")); - end; local procedure CheckServiceDates() begin @@ -437,6 +433,13 @@ table 8002 "Planned Subscription Line" Validate(Price, 0); end; + local procedure CheckRatioBetweenBillingBasePeriodAndRhythm() + var + begin + if (Format("Billing Base Period") <> '') and (Format("Billing Rhythm") <> '') then + DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm")); + end; + var Currency: Record Currency; CurrExchRate: Record "Currency Exchange Rate"; diff --git a/src/Apps/W1/Subscription Billing/App/Sales Service Commitments/Tables/SalesSubscriptionLine.Table.al b/src/Apps/W1/Subscription Billing/App/Sales Service Commitments/Tables/SalesSubscriptionLine.Table.al index 5d6cfe4ce7..c954d37a60 100644 --- a/src/Apps/W1/Subscription Billing/App/Sales Service Commitments/Tables/SalesSubscriptionLine.Table.al +++ b/src/Apps/W1/Subscription Billing/App/Sales Service Commitments/Tables/SalesSubscriptionLine.Table.al @@ -181,7 +181,7 @@ table 8068 "Sales Subscription Line" trigger OnValidate() begin TestIfSalesOrderIsReleased(); - DateFormulaManagementGlobal.ErrorIfDateFormulaNegative("Initial Term"); + DateFormulaManagement.ErrorIfDateFormulaNegative("Initial Term"); end; } field(24; "Notice Period"; DateFormula) @@ -190,7 +190,7 @@ table 8068 "Sales Subscription Line" trigger OnValidate() begin TestIfSalesOrderIsReleased(); - DateFormulaManagementGlobal.ErrorIfDateFormulaNegative("Notice Period"); + DateFormulaManagement.ErrorIfDateFormulaNegative("Notice Period"); end; } field(25; "Extension Term"; DateFormula) @@ -201,7 +201,7 @@ table 8068 "Sales Subscription Line" TestIfSalesOrderIsReleased(); if Format("Extension Term") = '' then TestField("Notice Period", "Extension Term"); - DateFormulaManagementGlobal.ErrorIfDateFormulaNegative("Extension Term"); + DateFormulaManagement.ErrorIfDateFormulaNegative("Extension Term"); end; } field(26; "Billing Base Period"; DateFormula) @@ -212,8 +212,9 @@ table 8068 "Sales Subscription Line" trigger OnValidate() begin TestIfSalesOrderIsReleased(); - DateFormulaManagementGlobal.ErrorIfDateFormulaEmpty("Billing Base Period", FieldCaption("Billing Base Period")); - DateFormulaManagementGlobal.ErrorIfDateFormulaNegative("Billing Base Period"); + DateFormulaManagement.ErrorIfDateFormulaEmpty("Billing Base Period", FieldCaption("Billing Base Period")); + DateFormulaManagement.ErrorIfDateFormulaNegative("Billing Base Period"); + CheckRatioBetweenBillingBasePeriodAndRhythm(); end; } field(27; "Billing Rhythm"; DateFormula) @@ -224,8 +225,9 @@ table 8068 "Sales Subscription Line" trigger OnValidate() begin TestIfSalesOrderIsReleased(); - DateFormulaManagementGlobal.ErrorIfDateFormulaEmpty("Billing Rhythm", FieldCaption("Billing Rhythm")); - DateFormulaManagementGlobal.ErrorIfDateFormulaNegative("Billing Rhythm"); + DateFormulaManagement.ErrorIfDateFormulaEmpty("Billing Rhythm", FieldCaption("Billing Rhythm")); + DateFormulaManagement.ErrorIfDateFormulaNegative("Billing Rhythm"); + CheckRatioBetweenBillingBasePeriodAndRhythm(); end; } field(28; "Invoicing via"; Enum "Invoicing Via") @@ -393,9 +395,6 @@ table 8068 "Sales Subscription Line" trigger OnModify() begin TestIfSalesOrderIsReleased(); - xRec.Get(xRec."Line No."); - if ((xRec."Billing Base Period" <> Rec."Billing Base Period") or (xRec."Billing Rhythm" <> Rec."Billing Rhythm")) then - DateFormulaManagementGlobal.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm")); end; trigger OnDelete() @@ -688,7 +687,6 @@ table 8068 "Sales Subscription Line" var SalesLineVAT: Record "Sales Line"; ContractRenewalMgt: Codeunit "Sub. Contract Renewal Mgt."; - DateFormulaManagement: Codeunit "Date Formula Management"; IsHandled: Boolean; RhythmIdentifier: Code[20]; ContractRenewalPriceCalculationRatio: Decimal; @@ -842,6 +840,13 @@ table 8068 "Sales Subscription Line" SalesLine := NewSalesLine; end; + local procedure CheckRatioBetweenBillingBasePeriodAndRhythm() + var + begin + if (Format("Billing Base Period") <> '') and (Format("Billing Rhythm") <> '') then + DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm")); + end; + [IntegrationEvent(false, false)] local procedure OnCalculateBaseTypeElseCaseOnCalculateCalculationBaseAmountCustomer(SalesSubscriptionLine: Record "Sales Subscription Line"; SalesLine: Record "Sales Line"; var CalculatedBaseAmount: Decimal; var IsHandled: Boolean) begin @@ -876,7 +881,7 @@ table 8068 "Sales Subscription Line" Currency: Record Currency; CurrExchRate: Record "Currency Exchange Rate"; SalesLine: Record "Sales Line"; - DateFormulaManagementGlobal: Codeunit "Date Formula Management"; + DateFormulaManagement: Codeunit "Date Formula Management"; ServiceAmountIncreaseErr: Label '%1 cannot be greater than %2.', Comment = '%1 and %2 are numbers'; ReleasedSalesOrderExistsErr: Label 'Subscription Lines cannot be edited on orders with status = Released.'; CalculateBaseTypeOptionNotImplementedErr: Label 'Unknown option %1 for %2.\\ Object Name: %3, Procedure: %4', Comment = '%1=Format("Calculation Base Type"), %2 = Fieldcaption for "Calculation Base Type", %3 = Current object name, %4 = Current procedure name'; 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 fe3a3a65e2..0bcd39c898 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 @@ -182,6 +182,7 @@ table 8059 "Subscription Line" begin DateFormulaManagement.ErrorIfDateFormulaEmpty("Billing Base Period", FieldCaption("Billing Base Period")); DateFormulaManagement.ErrorIfDateFormulaNegative("Billing Base Period"); + CheckRatioBetweenBillingBasePeriodAndRhythm(); end; } field(16; "Invoicing via"; Enum "Invoicing Via") @@ -254,6 +255,7 @@ table 8059 "Subscription Line" begin DateFormulaManagement.ErrorIfDateFormulaEmpty("Billing Rhythm", FieldCaption("Billing Rhythm")); DateFormulaManagement.ErrorIfDateFormulaNegative("Billing Rhythm"); + CheckRatioBetweenBillingBasePeriodAndRhythm(); end; } field(24; "Cancellation Possible Until"; Date) @@ -595,9 +597,6 @@ table 8059 "Subscription Line" trigger OnModify() begin - xRec.Get(xRec."Entry No."); - if ((xRec."Billing Base Period" <> Rec."Billing Base Period") or (xRec."Billing Rhythm" <> Rec."Billing Rhythm")) then - DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm")); DisplayErrorIfContractLinesExist(ClosedContractLineExistErr, true); SetUpdateRequiredOnBillingLines(); UpdateCustomerContractLineServiceCommitmentDescription(); @@ -1925,6 +1924,13 @@ table 8059 "Subscription Line" end; end; + local procedure CheckRatioBetweenBillingBasePeriodAndRhythm() + var + begin + if (Format("Billing Base Period") <> '') and (Format("Billing Rhythm") <> '') then + DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm")); + end; + [IntegrationEvent(false, false)] local procedure OnAfterUpdateNextBillingDate(var SubscriptionLine: Record "Subscription Line"; LastBillingToDate: Date) begin diff --git a/src/Apps/W1/Subscription Billing/App/Service Commitments/Tables/SubscriptionPackageLine.Table.al b/src/Apps/W1/Subscription Billing/App/Service Commitments/Tables/SubscriptionPackageLine.Table.al index 00edee60dc..34ec19e936 100644 --- a/src/Apps/W1/Subscription Billing/App/Service Commitments/Tables/SubscriptionPackageLine.Table.al +++ b/src/Apps/W1/Subscription Billing/App/Service Commitments/Tables/SubscriptionPackageLine.Table.al @@ -108,6 +108,7 @@ table 8056 "Subscription Package Line" trigger OnValidate() begin DateFormulaManagement.ErrorIfDateFormulaNegative("Billing Base Period"); + CheckRatioBetweenBillingBasePeriodAndRhythm(); end; } field(11; "Billing Rhythm"; DateFormula) @@ -117,6 +118,7 @@ table 8056 "Subscription Package Line" begin DateFormulaManagement.ErrorIfDateFormulaEmpty("Billing Rhythm", FieldCaption("Billing Rhythm")); DateFormulaManagement.ErrorIfDateFormulaNegative("Billing Rhythm"); + CheckRatioBetweenBillingBasePeriodAndRhythm(); end; } field(12; "Sub. Line Start Formula"; DateFormula) @@ -221,12 +223,6 @@ table 8056 "Subscription Package Line" Clustered = true; } } - trigger OnModify() - begin - xRec.Get(xRec."Subscription Package Code", xRec."Line No."); - if ((xRec."Billing Base Period" <> Rec."Billing Base Period") or (xRec."Billing Rhythm" <> Rec."Billing Rhythm")) then - DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm")); - end; var DateFormulaManagement: Codeunit "Date Formula Management"; @@ -303,4 +299,11 @@ table 8056 "Subscription Package Line" begin exit(Rec.Partner = Rec.Partner::Vendor); end; + + local procedure CheckRatioBetweenBillingBasePeriodAndRhythm() + var + begin + if (Format("Billing Base Period") <> '') and (Format("Billing Rhythm") <> '') then + DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm")); + end; } diff --git a/src/Apps/W1/Subscription Billing/Test/Base/ContractTestLibrary.Codeunit.al b/src/Apps/W1/Subscription Billing/Test/Base/ContractTestLibrary.Codeunit.al index b75d566683..995e359550 100644 --- a/src/Apps/W1/Subscription Billing/Test/Base/ContractTestLibrary.Codeunit.al +++ b/src/Apps/W1/Subscription Billing/Test/Base/ContractTestLibrary.Codeunit.al @@ -1145,7 +1145,6 @@ codeunit 139685 "Contract Test Library" Clear(ServiceCommitment."Billing Base Period"); Clear(ServiceCommitment."Billing Rhythm"); Evaluate(ServiceCommitment."Billing Base Period", BillingBasePeriodText); - ServiceCommitment.Validate("Billing Base Period"); Evaluate(ServiceCommitment."Billing Rhythm", BillingRhythmText); ServiceCommitment.Validate("Billing Rhythm"); 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 6905a6dae0..b5fc423eea 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 @@ -64,6 +64,7 @@ codeunit 139915 "Sales Service Commitment Test" NoOfServiceObjects: Integer; NotCreatedProperlyErr: Label 'Subscription Lines are not created properly.'; SalesServiceCommitmentCannotBeDeletedErr: Label 'The Sales Subscription Line cannot be deleted, because it is the last line with Process Contract Renewal. Please delete the Sales line in order to delete the Sales Subscription Line.', Locked = true; + NaturalNumberRatioErr: Label 'The ratio of ''%1'' and ''%2'' or vice versa must give a natural number.', Comment = '%1=Field Caption, %2=Field Caption'; #region Tests @@ -1267,6 +1268,38 @@ codeunit 139915 "Sales Service Commitment Test" LibrarySales.CreateSalesLine(SalesLine, SalesHeader, Enum::"Sales Line Type"::Item, Item."No.", LibraryRandom.RandIntInRange(1, 100)); end; + [Test] + procedure PreventInvalidDateFormulaRatioForSalesSubscriptionLine() + var + TwelveMonthsDateFormula: DateFormula; + FifteenMonthsDateFormula: DateFormula; + begin + // [SCENARIO] When a Sales Subscription Line has been created with a Billing Base Period and a Billing Rhythm that do not have a valid ratio, the error is thrown as soon as an invalid date formula is entered + + // [GIVEN] When a Sales Subscription Line with Billing Base Period and Billing Rhythm equal to 12M has been created + Initialize(); + Evaluate(TwelveMonthsDateFormula, '<12M>'); + ServiceCommPackageLine.Validate("Billing Base Period", TwelveMonthsDateFormula); + ServiceCommPackageLine.Validate("Billing Rhythm", TwelveMonthsDateFormula); + ServiceCommPackageLine.Modify(false); + ContractTestLibrary.SetupSalesServiceCommitmentItemAndAssignToServiceCommitmentPackage(Item, Enum::"Item Service Commitment Type"::"Service Commitment Item", ServiceCommitmentPackage.Code); + LibrarySales.CreateSalesHeader(SalesHeader, SalesHeader."Document Type"::Quote, ''); + LibrarySales.CreateSalesLine(SalesLine, SalesHeader, Enum::"Sales Line Type"::Item, Item."No.", LibraryRandom.RandIntInRange(1, 100)); + + Commit(); // retain data after asserterror + + // [WHEN] An invalid date formula is created for the purpose of validating Billing Base Period and Billing Rhythm + Evaluate(FifteenMonthsDateFormula, '<15M>'); + + // [THEN] Error expected when invalid date formula is entered for Billing Base Period or Billing Rhythm + SalesServiceCommitment.FilterOnSalesLine(SalesLine); + SalesServiceCommitment.FindFirst(); + asserterror SalesServiceCommitment.Validate("Billing Base Period", FifteenMonthsDateFormula); + Assert.ExpectedError(StrSubstNo(NaturalNumberRatioErr, SalesServiceCommitment.FieldCaption("Billing Base Period"), SalesServiceCommitment.FieldCaption("Billing Rhythm"))); + asserterror SalesServiceCommitment.Validate("Billing Rhythm", FifteenMonthsDateFormula); + Assert.ExpectedError(StrSubstNo(NaturalNumberRatioErr, SalesServiceCommitment.FieldCaption("Billing Base Period"), SalesServiceCommitment.FieldCaption("Billing Rhythm"))); + end; + [Test] procedure RunNormalSalesServiceCommitmentDeletion() begin diff --git a/src/Apps/W1/Subscription Billing/Test/Service Commitments/ServiceCommitmentTest.Codeunit.al b/src/Apps/W1/Subscription Billing/Test/Service Commitments/ServiceCommitmentTest.Codeunit.al index 37d3296488..32db10b9f4 100644 --- a/src/Apps/W1/Subscription Billing/Test/Service Commitments/ServiceCommitmentTest.Codeunit.al +++ b/src/Apps/W1/Subscription Billing/Test/Service Commitments/ServiceCommitmentTest.Codeunit.al @@ -25,6 +25,7 @@ codeunit 148156 "Service Commitment Test" LibrarySales: Codeunit "Library - Sales"; LibraryTestInitialize: Codeunit "Library - Test Initialize"; PackageLineMissingInvoicingItemNoErr: Label 'The %1 %2 can not be used with Item %3, because at least one of the Service Commitment Package lines is missing an %4.', Locked = true; + NaturalNumberRatioErr: Label 'The ratio of ''%1'' and ''%2'' or vice versa must give a natural number.', Comment = '%1=Field Caption, %2=Field Caption'; #region Tests @@ -308,6 +309,54 @@ codeunit 148156 "Service Commitment Test" asserterror ServiceCommitment.Modify(true); end; + [Test] + procedure PreventInvalidDateFormulaRatioForSubscriptionLine() + var + FifteenMonthsDateFormula: DateFormula; + begin + // [SCENARIO] When a Subscription Line has been created with a Billing Base Period and a Billing Rhythm that do not have a valid ratio, the error is thrown as soon as an invalid date formula is entered + + // [GIVEN] A single Subscription Line with Billing Base Period and Billing Rhythm equal to 12M has been created + Initialize(); + ContractTestLibrary.CreateServiceObjectForItemWithServiceCommitments(ServiceObject, Enum::"Invoicing Via"::Contract, false, Item, 1, 0, '<12M>', '<12M>'); + + Commit(); // retain data after asserterror + + // [WHEN] An invalid date formula is created for the purpose of validating Billing Base Period and Billing Rhythm + Evaluate(FifteenMonthsDateFormula, '<15M>'); + + // [THEN] Error expected when invalid date formula is entered for Billing Base Period or Billing Rhythm + ServiceCommitment.SetRange("Subscription Header No.", ServiceObject."No."); + ServiceCommitment.FindFirst(); + asserterror ServiceCommitment.Validate("Billing Base Period", FifteenMonthsDateFormula); + Assert.ExpectedError(StrSubstNo(NaturalNumberRatioErr, ServiceCommitment.FieldCaption("Billing Base Period"), ServiceCommitment.FieldCaption("Billing Rhythm"))); + asserterror ServiceCommitment.Validate("Billing Rhythm", FifteenMonthsDateFormula); + Assert.ExpectedError(StrSubstNo(NaturalNumberRatioErr, ServiceCommitment.FieldCaption("Billing Base Period"), ServiceCommitment.FieldCaption("Billing Rhythm"))); + end; + + [Test] + procedure PreventInvalidDateFormulaRatioForSubscriptionPackageLine() + var + FifteenMonthsDateFormula: DateFormula; + begin + // [SCENARIO] When a Subscription Package Line has been created with a Billing Base Period and a Billing Rhythm that do not have a valid ratio, the error is thrown as soon as an invalid date formula is entered + + // [GIVEN] A single Subscription Package Line with Billing Base Period and Billing Rhythm equal to 12M has been created + Initialize(); + ContractTestLibrary.CreateServiceCommitmentPackageWithLine('', ServiceCommitmentPackage, ServiceCommPackageLine); + Commit(); // retain data after asserterror + + // [WHEN] An invalid date formula is created for the purpose of validating Billing Base Period and Billing Rhythm + Evaluate(FifteenMonthsDateFormula, '<15M>'); + + // [THEN] Error expected when invalid date formula is entered for Billing Base Period or Billing Rhythm + asserterror ServiceCommPackageLine.Validate("Billing Base Period", FifteenMonthsDateFormula); + Assert.ExpectedError(StrSubstNo(NaturalNumberRatioErr, ServiceCommPackageLine.FieldCaption("Billing Base Period"), ServiceCommPackageLine.FieldCaption("Billing Rhythm"))); + asserterror ServiceCommPackageLine.Validate("Billing Rhythm", FifteenMonthsDateFormula); + Assert.ExpectedError(StrSubstNo(NaturalNumberRatioErr, ServiceCommPackageLine.FieldCaption("Billing Base Period"), ServiceCommPackageLine.FieldCaption("Billing Rhythm"))); + end; + + [Test] [HandlerFunctions('ExchangeRateSelectionModalPageHandler,MessageHandler')] procedure TestOverdueServiceCommitments() @@ -463,14 +512,14 @@ codeunit 148156 "Service Commitment Test" local procedure ValidateDateFormulaCombinations(DateFormulaText1: Text; DateFormulaText2: Text) var - DateFormula1: DateFormula; + EvaluatedDateFormula: DateFormula; begin ServiceCommPackageLine.Get(ServiceCommPackageLine."Subscription Package Code", ServiceCommPackageLine."Line No."); - Evaluate(DateFormula1, DateFormulaText1); - ServiceCommPackageLine."Billing Base Period" := DateFormula1; - Evaluate(DateFormula1, DateFormulaText2); - ServiceCommPackageLine."Billing Rhythm" := DateFormula1; - ServiceCommPackageLine.Modify(true); + Evaluate(EvaluatedDateFormula, DateFormulaText1); + ServiceCommPackageLine."Billing Base Period" := EvaluatedDateFormula; + Evaluate(EvaluatedDateFormula, DateFormulaText2); + ServiceCommPackageLine.Validate("Billing Rhythm", EvaluatedDateFormula); + ServiceCommPackageLine.Modify(false); end; #endregion 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 4048a53e43..4f89230d38 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 @@ -34,6 +34,9 @@ codeunit 148157 "Service Object Test" LibraryTestInitialize: Codeunit "Library - Test Initialize"; LibraryVariableStorage: Codeunit "Library - Variable Storage"; NoStartDateErr: Label 'Start Date is not entered.', Locked = true; + NaturalNumberRatioErr: Label 'The ratio of ''%1'' and ''%2'' or vice versa must give a natural number.', Comment = '%1=Field Caption, %2=Field Caption'; + CurrentPeriodErr: Label 'Current Period cannot be used for The Date Formula.'; + ComplexFormulaErr: Label 'The Date Formula cannot be complex.'; IsInitialized: Boolean; #region Tests @@ -198,34 +201,27 @@ codeunit 148157 "Service Object Test" Commit(); // retain data after asserterror ContractTestLibrary.ValidateBillingBasePeriodAndBillingRhythmOnServiceCommitment(ServiceCommitment, '<5D>', '<20D>'); - ServiceCommitment.Modify(true); ContractTestLibrary.ValidateBillingBasePeriodAndBillingRhythmOnServiceCommitment(ServiceCommitment, '<1W>', '<4W>'); - ServiceCommitment.Modify(true); ContractTestLibrary.ValidateBillingBasePeriodAndBillingRhythmOnServiceCommitment(ServiceCommitment, '<1M>', '<6Q>'); - ServiceCommitment.Modify(true); ContractTestLibrary.ValidateBillingBasePeriodAndBillingRhythmOnServiceCommitment(ServiceCommitment, '<1Q>', '<3Q>'); - ServiceCommitment.Modify(true); ContractTestLibrary.ValidateBillingBasePeriodAndBillingRhythmOnServiceCommitment(ServiceCommitment, '<1Y>', '<2Y>'); - ServiceCommitment.Modify(true); ContractTestLibrary.ValidateBillingBasePeriodAndBillingRhythmOnServiceCommitment(ServiceCommitment, '<3M>', '<1Y>'); - ServiceCommitment.Modify(true); ContractTestLibrary.ValidateBillingBasePeriodAndBillingRhythmOnServiceCommitment(ServiceCommitment, '<6M>', '<1Q>'); - ServiceCommitment.Modify(true); - - ContractTestLibrary.ValidateBillingBasePeriodAndBillingRhythmOnServiceCommitment(ServiceCommitment, '<1D>', '<1M>'); - asserterror ServiceCommitment.Modify(true); - ContractTestLibrary.ValidateBillingBasePeriodAndBillingRhythmOnServiceCommitment(ServiceCommitment, '<1W>', '<1M>'); - asserterror ServiceCommitment.Modify(true); - ContractTestLibrary.ValidateBillingBasePeriodAndBillingRhythmOnServiceCommitment(ServiceCommitment, '<2M>', '<7M>'); - asserterror ServiceCommitment.Modify(true); - ContractTestLibrary.ValidateBillingBasePeriodAndBillingRhythmOnServiceCommitment(ServiceCommitment, '<2Q>', '<5Q>'); - asserterror ServiceCommitment.Modify(true); - ContractTestLibrary.ValidateBillingBasePeriodAndBillingRhythmOnServiceCommitment(ServiceCommitment, '<2Y>', '<3Y>'); - asserterror ServiceCommitment.Modify(true); - ContractTestLibrary.ValidateBillingBasePeriodAndBillingRhythmOnServiceCommitment(ServiceCommitment, '', '<1Y>'); - asserterror ServiceCommitment.Modify(true); - ContractTestLibrary.ValidateBillingBasePeriodAndBillingRhythmOnServiceCommitment(ServiceCommitment, '<1M + 1Q>', '<1Y>'); - asserterror ServiceCommitment.Modify(true); + + asserterror ContractTestLibrary.ValidateBillingBasePeriodAndBillingRhythmOnServiceCommitment(ServiceCommitment, '<1D>', '<1M>'); + Assert.ExpectedError(StrSubstNo(NaturalNumberRatioErr, ServiceCommitment.FieldCaption("Billing Base Period"), ServiceCommitment.FieldCaption("Billing Rhythm"))); + asserterror ContractTestLibrary.ValidateBillingBasePeriodAndBillingRhythmOnServiceCommitment(ServiceCommitment, '<1W>', '<1M>'); + Assert.ExpectedError(StrSubstNo(NaturalNumberRatioErr, ServiceCommitment.FieldCaption("Billing Base Period"), ServiceCommitment.FieldCaption("Billing Rhythm"))); + asserterror ContractTestLibrary.ValidateBillingBasePeriodAndBillingRhythmOnServiceCommitment(ServiceCommitment, '<2M>', '<7M>'); + Assert.ExpectedError(StrSubstNo(NaturalNumberRatioErr, ServiceCommitment.FieldCaption("Billing Base Period"), ServiceCommitment.FieldCaption("Billing Rhythm"))); + asserterror ContractTestLibrary.ValidateBillingBasePeriodAndBillingRhythmOnServiceCommitment(ServiceCommitment, '<2Q>', '<5Q>'); + Assert.ExpectedError(StrSubstNo(NaturalNumberRatioErr, ServiceCommitment.FieldCaption("Billing Base Period"), ServiceCommitment.FieldCaption("Billing Rhythm"))); + asserterror ContractTestLibrary.ValidateBillingBasePeriodAndBillingRhythmOnServiceCommitment(ServiceCommitment, '<2Y>', '<3Y>'); + Assert.ExpectedError(StrSubstNo(NaturalNumberRatioErr, ServiceCommitment.FieldCaption("Billing Base Period"), ServiceCommitment.FieldCaption("Billing Rhythm"))); + asserterror ContractTestLibrary.ValidateBillingBasePeriodAndBillingRhythmOnServiceCommitment(ServiceCommitment, '', '<1Y>'); + Assert.ExpectedError(StrSubstNo(CurrentPeriodErr)); + asserterror ContractTestLibrary.ValidateBillingBasePeriodAndBillingRhythmOnServiceCommitment(ServiceCommitment, '<1M + 1Q>', '<1Y>'); + Assert.ExpectedError(StrSubstNo(ComplexFormulaErr)); end; [Test]