Skip to content

Commit f6a10e8

Browse files
committed
Invalid Date Formula Ratio for Subscription Package Line prevented
1 parent 3f21d9c commit f6a10e8

File tree

6 files changed

+106
-27
lines changed

6 files changed

+106
-27
lines changed

src/Apps/W1/Subscription Billing/App/Contract Renewal/Tables/PlannedSubscriptionLine.Table.al

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ table 8002 "Planned Subscription Line"
197197
if Format("Extension Term") = '' then
198198
TestField("Notice Period", "Extension Term");
199199
DateFormulaManagement.ErrorIfDateFormulaNegative("Extension Term");
200+
if (Format("Billing Base Period") <> '') and (Format("Billing Rhythm") <> '') then
201+
DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm"));
200202
end;
201203
}
202204
field(23; "Billing Rhythm"; DateFormula)
@@ -206,6 +208,8 @@ table 8002 "Planned Subscription Line"
206208
begin
207209
DateFormulaManagement.ErrorIfDateFormulaEmpty("Billing Rhythm", FieldCaption("Billing Rhythm"));
208210
DateFormulaManagement.ErrorIfDateFormulaNegative("Billing Rhythm");
211+
if (Format("Billing Base Period") <> '') and (Format("Billing Rhythm") <> '') then
212+
DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm"));
209213
end;
210214
}
211215
field(24; "Cancellation Possible Until"; Date)
@@ -397,12 +401,6 @@ table 8002 "Planned Subscription Line"
397401
key(Contract; "Subscription Contract No.", "Subscription Contract Line No.") { }
398402
key(Quote; "Sales Quote No.", "Sales Quote Line No.") { }
399403
}
400-
trigger OnModify()
401-
begin
402-
xRec.Get(xRec."Entry No.");
403-
if ((xRec."Billing Base Period" <> Rec."Billing Base Period") or (xRec."Billing Rhythm" <> Rec."Billing Rhythm")) then
404-
DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm"));
405-
end;
406404

407405
local procedure CheckServiceDates()
408406
begin

src/Apps/W1/Subscription Billing/App/Sales Service Commitments/Tables/SalesSubscriptionLine.Table.al

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ table 8068 "Sales Subscription Line"
181181
trigger OnValidate()
182182
begin
183183
TestIfSalesOrderIsReleased();
184-
DateFormulaManagementGlobal.ErrorIfDateFormulaNegative("Initial Term");
184+
DateFormulaManagement.ErrorIfDateFormulaNegative("Initial Term");
185185
end;
186186
}
187187
field(24; "Notice Period"; DateFormula)
@@ -190,7 +190,7 @@ table 8068 "Sales Subscription Line"
190190
trigger OnValidate()
191191
begin
192192
TestIfSalesOrderIsReleased();
193-
DateFormulaManagementGlobal.ErrorIfDateFormulaNegative("Notice Period");
193+
DateFormulaManagement.ErrorIfDateFormulaNegative("Notice Period");
194194
end;
195195
}
196196
field(25; "Extension Term"; DateFormula)
@@ -201,7 +201,7 @@ table 8068 "Sales Subscription Line"
201201
TestIfSalesOrderIsReleased();
202202
if Format("Extension Term") = '' then
203203
TestField("Notice Period", "Extension Term");
204-
DateFormulaManagementGlobal.ErrorIfDateFormulaNegative("Extension Term");
204+
DateFormulaManagement.ErrorIfDateFormulaNegative("Extension Term");
205205
end;
206206
}
207207
field(26; "Billing Base Period"; DateFormula)
@@ -212,8 +212,10 @@ table 8068 "Sales Subscription Line"
212212
trigger OnValidate()
213213
begin
214214
TestIfSalesOrderIsReleased();
215-
DateFormulaManagementGlobal.ErrorIfDateFormulaEmpty("Billing Base Period", FieldCaption("Billing Base Period"));
216-
DateFormulaManagementGlobal.ErrorIfDateFormulaNegative("Billing Base Period");
215+
DateFormulaManagement.ErrorIfDateFormulaEmpty("Billing Base Period", FieldCaption("Billing Base Period"));
216+
DateFormulaManagement.ErrorIfDateFormulaNegative("Billing Base Period");
217+
if (Format("Billing Base Period") <> '') and (Format("Billing Rhythm") <> '') then
218+
DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm"));
217219
end;
218220
}
219221
field(27; "Billing Rhythm"; DateFormula)
@@ -224,8 +226,10 @@ table 8068 "Sales Subscription Line"
224226
trigger OnValidate()
225227
begin
226228
TestIfSalesOrderIsReleased();
227-
DateFormulaManagementGlobal.ErrorIfDateFormulaEmpty("Billing Rhythm", FieldCaption("Billing Rhythm"));
228-
DateFormulaManagementGlobal.ErrorIfDateFormulaNegative("Billing Rhythm");
229+
DateFormulaManagement.ErrorIfDateFormulaEmpty("Billing Rhythm", FieldCaption("Billing Rhythm"));
230+
DateFormulaManagement.ErrorIfDateFormulaNegative("Billing Rhythm");
231+
if (Format("Billing Base Period") <> '') and (Format("Billing Rhythm") <> '') then
232+
DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm"));
229233
end;
230234
}
231235
field(28; "Invoicing via"; Enum "Invoicing Via")
@@ -393,9 +397,6 @@ table 8068 "Sales Subscription Line"
393397
trigger OnModify()
394398
begin
395399
TestIfSalesOrderIsReleased();
396-
xRec.Get(xRec."Line No.");
397-
if ((xRec."Billing Base Period" <> Rec."Billing Base Period") or (xRec."Billing Rhythm" <> Rec."Billing Rhythm")) then
398-
DateFormulaManagementGlobal.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm"));
399400
end;
400401

401402
trigger OnDelete()
@@ -688,7 +689,6 @@ table 8068 "Sales Subscription Line"
688689
var
689690
SalesLineVAT: Record "Sales Line";
690691
ContractRenewalMgt: Codeunit "Sub. Contract Renewal Mgt.";
691-
DateFormulaManagement: Codeunit "Date Formula Management";
692692
IsHandled: Boolean;
693693
RhythmIdentifier: Code[20];
694694
ContractRenewalPriceCalculationRatio: Decimal;
@@ -876,7 +876,7 @@ table 8068 "Sales Subscription Line"
876876
Currency: Record Currency;
877877
CurrExchRate: Record "Currency Exchange Rate";
878878
SalesLine: Record "Sales Line";
879-
DateFormulaManagementGlobal: Codeunit "Date Formula Management";
879+
DateFormulaManagement: Codeunit "Date Formula Management";
880880
ServiceAmountIncreaseErr: Label '%1 cannot be greater than %2.', Comment = '%1 and %2 are numbers';
881881
ReleasedSalesOrderExistsErr: Label 'Subscription Lines cannot be edited on orders with status = Released.';
882882
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';

src/Apps/W1/Subscription Billing/App/Service Commitments/Tables/SubscriptionLine.Table.al

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ table 8059 "Subscription Line"
182182
begin
183183
DateFormulaManagement.ErrorIfDateFormulaEmpty("Billing Base Period", FieldCaption("Billing Base Period"));
184184
DateFormulaManagement.ErrorIfDateFormulaNegative("Billing Base Period");
185+
if (Format("Billing Base Period") <> '') and (Format("Billing Rhythm") <> '') then
186+
DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm"));
185187
end;
186188
}
187189
field(16; "Invoicing via"; Enum "Invoicing Via")
@@ -254,6 +256,8 @@ table 8059 "Subscription Line"
254256
begin
255257
DateFormulaManagement.ErrorIfDateFormulaEmpty("Billing Rhythm", FieldCaption("Billing Rhythm"));
256258
DateFormulaManagement.ErrorIfDateFormulaNegative("Billing Rhythm");
259+
if (Format("Billing Base Period") <> '') and (Format("Billing Rhythm") <> '') then
260+
DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm"));
257261
end;
258262
}
259263
field(24; "Cancellation Possible Until"; Date)
@@ -595,9 +599,6 @@ table 8059 "Subscription Line"
595599

596600
trigger OnModify()
597601
begin
598-
xRec.Get(xRec."Entry No.");
599-
if ((xRec."Billing Base Period" <> Rec."Billing Base Period") or (xRec."Billing Rhythm" <> Rec."Billing Rhythm")) then
600-
DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm"));
601602
DisplayErrorIfContractLinesExist(ClosedContractLineExistErr, true);
602603
SetUpdateRequiredOnBillingLines();
603604
UpdateCustomerContractLineServiceCommitmentDescription();

src/Apps/W1/Subscription Billing/App/Service Commitments/Tables/SubscriptionPackageLine.Table.al

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ table 8056 "Subscription Package Line"
108108
trigger OnValidate()
109109
begin
110110
DateFormulaManagement.ErrorIfDateFormulaNegative("Billing Base Period");
111+
if (Format("Billing Base Period") <> '') and (Format("Billing Rhythm") <> '') then
112+
DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm"));
111113
end;
112114
}
113115
field(11; "Billing Rhythm"; DateFormula)
@@ -117,6 +119,8 @@ table 8056 "Subscription Package Line"
117119
begin
118120
DateFormulaManagement.ErrorIfDateFormulaEmpty("Billing Rhythm", FieldCaption("Billing Rhythm"));
119121
DateFormulaManagement.ErrorIfDateFormulaNegative("Billing Rhythm");
122+
if (Format("Billing Base Period") <> '') and (Format("Billing Rhythm") <> '') then
123+
DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm"));
120124
end;
121125
}
122126
field(12; "Sub. Line Start Formula"; DateFormula)
@@ -221,12 +225,6 @@ table 8056 "Subscription Package Line"
221225
Clustered = true;
222226
}
223227
}
224-
trigger OnModify()
225-
begin
226-
xRec.Get(xRec."Subscription Package Code", xRec."Line No.");
227-
if ((xRec."Billing Base Period" <> Rec."Billing Base Period") or (xRec."Billing Rhythm" <> Rec."Billing Rhythm")) then
228-
DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm"));
229-
end;
230228

231229
var
232230
DateFormulaManagement: Codeunit "Date Formula Management";

src/Apps/W1/Subscription Billing/Test/Service Commitments/SalesServiceCommitmentTest.Codeunit.al

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ codeunit 139915 "Sales Service Commitment Test"
6363
NoOfServiceObjects: Integer;
6464
NotCreatedProperlyErr: Label 'Subscription Lines are not created properly.';
6565
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;
66+
NaturalNumberRatioErr: Label 'The ratio of ''%1'' and ''%2'' or vice versa must give a natural number.', Comment = '%1=Field Caption, %2=Field Caption', Locked = true;
6667

6768
#region Tests
6869

@@ -1266,6 +1267,38 @@ codeunit 139915 "Sales Service Commitment Test"
12661267
LibrarySales.CreateSalesLine(SalesLine, SalesHeader, Enum::"Sales Line Type"::Item, Item."No.", LibraryRandom.RandIntInRange(1, 100));
12671268
end;
12681269

1270+
[Test]
1271+
procedure PreventInvalidDateFormulaRatioForSalesSubscriptionLine()
1272+
var
1273+
TwelveMonthsDateFormula: DateFormula;
1274+
FifteenMonthsDateFormula: DateFormula;
1275+
begin
1276+
// [SCENARIO] When Sales Subscription Line has been created with a Billing Base Period and Billing Rhythm that do not have a valid ratio, the error is thrown as soon as invalid date formula is entered
1277+
1278+
// [GIVEN] A single SalesSubscription Line with Billing Base Period and Billing Rhythm equal to 12M has been created
1279+
Initialize();
1280+
Evaluate(TwelveMonthsDateFormula, '<12M>');
1281+
ServiceCommPackageLine.Validate("Billing Base Period", TwelveMonthsDateFormula);
1282+
ServiceCommPackageLine.Validate("Billing Rhythm", TwelveMonthsDateFormula);
1283+
ServiceCommPackageLine.Modify(false);
1284+
ContractTestLibrary.SetupSalesServiceCommitmentItemAndAssignToServiceCommitmentPackage(Item, Enum::"Item Service Commitment Type"::"Service Commitment Item", ServiceCommitmentPackage.Code);
1285+
LibrarySales.CreateSalesHeader(SalesHeader, SalesHeader."Document Type"::Quote, '');
1286+
LibrarySales.CreateSalesLine(SalesLine, SalesHeader, Enum::"Sales Line Type"::Item, Item."No.", LibraryRandom.RandIntInRange(1, 100));
1287+
1288+
Commit(); // retain data after asserterror
1289+
1290+
// [WHEN] A invalid date formula is created for the purpose of validating Billing Base Period and Billing Rhythm
1291+
Evaluate(FifteenMonthsDateFormula, '<15M>');
1292+
1293+
// [THEN] Error expected when invalid date formula is entered for Billing Base Period or Billing Rhythm
1294+
SalesServiceCommitment.FilterOnSalesLine(SalesLine);
1295+
SalesServiceCommitment.FindFirst();
1296+
asserterror SalesServiceCommitment.Validate("Billing Base Period", FifteenMonthsDateFormula);
1297+
Assert.ExpectedError(StrSubstNo(NaturalNumberRatioErr, SalesServiceCommitment.FieldCaption("Billing Base Period"), SalesServiceCommitment.FieldCaption("Billing Rhythm")));
1298+
asserterror SalesServiceCommitment.Validate("Billing Rhythm", FifteenMonthsDateFormula);
1299+
Assert.ExpectedError(StrSubstNo(NaturalNumberRatioErr, SalesServiceCommitment.FieldCaption("Billing Base Period"), SalesServiceCommitment.FieldCaption("Billing Rhythm")));
1300+
end;
1301+
12691302
[Test]
12701303
procedure RunNormalSalesServiceCommitmentDeletion()
12711304
begin

src/Apps/W1/Subscription Billing/Test/Service Commitments/ServiceCommitmentTest.Codeunit.al

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ codeunit 148156 "Service Commitment Test"
2424
LibrarySales: Codeunit "Library - Sales";
2525
LibraryTestInitialize: Codeunit "Library - Test Initialize";
2626
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;
27+
NaturalNumberRatioErr: Label 'The ratio of ''%1'' and ''%2'' or vice versa must give a natural number.', Comment = '%1=Field Caption, %2=Field Caption', Locked = true;
2728

2829
#region Tests
2930

@@ -307,6 +308,54 @@ codeunit 148156 "Service Commitment Test"
307308
asserterror ServiceCommitment.Modify(true);
308309
end;
309310

311+
[Test]
312+
procedure PreventInvalidDateFormulaRatioForSubscriptionLine()
313+
var
314+
FifteenMonthsDateFormula: DateFormula;
315+
begin
316+
// [SCENARIO] When Subscription Line has been created with a Billing Base Period and Billing Rhythm that do not have a valid ratio, the error is thrown as soon as invalid date formula is entered
317+
318+
// [GIVEN] A single Subscription Line with Billing Base Period and Billing Rhythm equal to 12M has been created
319+
Initialize();
320+
ContractTestLibrary.CreateServiceObjectForItemWithServiceCommitments(ServiceObject, Enum::"Invoicing Via"::Contract, false, Item, 1, 0, '<12M>', '<12M>');
321+
322+
Commit(); // retain data after asserterror
323+
324+
// [WHEN] A invalid date formula is created for the purpose of validating Billing Base Period and Billing Rhythm
325+
Evaluate(FifteenMonthsDateFormula, '<15M>');
326+
327+
// [THEN] Error expected when invalid date formula is entered for Billing Base Period or Billing Rhythm
328+
ServiceCommitment.SetRange("Subscription Header No.", ServiceObject."No.");
329+
ServiceCommitment.FindFirst();
330+
asserterror ServiceCommitment.Validate("Billing Base Period", FifteenMonthsDateFormula);
331+
Assert.ExpectedError(StrSubstNo(NaturalNumberRatioErr, ServiceCommitment.FieldCaption("Billing Base Period"), ServiceCommitment.FieldCaption("Billing Rhythm")));
332+
asserterror ServiceCommitment.Validate("Billing Rhythm", FifteenMonthsDateFormula);
333+
Assert.ExpectedError(StrSubstNo(NaturalNumberRatioErr, ServiceCommitment.FieldCaption("Billing Base Period"), ServiceCommitment.FieldCaption("Billing Rhythm")));
334+
end;
335+
336+
[Test]
337+
procedure PreventInvalidDateFormulaRatioForSubscriptionPackageLine()
338+
var
339+
FifteenMonthsDateFormula: DateFormula;
340+
begin
341+
// [SCENARIO] When Subscription Package Line has been created with a Billing Base Period and Billing Rhythm that do not have a valid ratio, the error is thrown as soon as invalid date formula is entered
342+
343+
// [GIVEN] A single Subscription Package Line with Billing Base Period and Billing Rhythm equal to 12M has been created
344+
Initialize();
345+
ContractTestLibrary.CreateServiceCommitmentPackageWithLine('', ServiceCommitmentPackage, ServiceCommPackageLine);
346+
Commit(); // retain data after asserterror
347+
348+
// [WHEN] A invalid date formula is created for the purpose of validating Billing Base Period and Billing Rhythm
349+
Evaluate(FifteenMonthsDateFormula, '<15M>');
350+
351+
// [THEN] Error expected when invalid date formula is entered for Billing Base Period or Billing Rhythm
352+
asserterror ServiceCommPackageLine.Validate("Billing Base Period", FifteenMonthsDateFormula);
353+
Assert.ExpectedError(StrSubstNo(NaturalNumberRatioErr, ServiceCommPackageLine.FieldCaption("Billing Base Period"), ServiceCommPackageLine.FieldCaption("Billing Rhythm")));
354+
asserterror ServiceCommPackageLine.Validate("Billing Rhythm", FifteenMonthsDateFormula);
355+
Assert.ExpectedError(StrSubstNo(NaturalNumberRatioErr, ServiceCommPackageLine.FieldCaption("Billing Base Period"), ServiceCommPackageLine.FieldCaption("Billing Rhythm")));
356+
end;
357+
358+
310359
[Test]
311360
[HandlerFunctions('ExchangeRateSelectionModalPageHandler,MessageHandler')]
312361
procedure TestOverdueServiceCommitments()

0 commit comments

Comments
 (0)