Skip to content

Commit 70ad5a8

Browse files
committed
Adressing feedback and covering failing tests
1 parent f6a10e8 commit 70ad5a8

File tree

8 files changed

+69
-53
lines changed

8 files changed

+69
-53
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,7 @@ 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"));
200+
CheckRatioBetweenBillingBasePeriodAndRhythm();
202201
end;
203202
}
204203
field(23; "Billing Rhythm"; DateFormula)
@@ -209,7 +208,7 @@ table 8002 "Planned Subscription Line"
209208
DateFormulaManagement.ErrorIfDateFormulaEmpty("Billing Rhythm", FieldCaption("Billing Rhythm"));
210209
DateFormulaManagement.ErrorIfDateFormulaNegative("Billing Rhythm");
211210
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"));
211+
CheckRatioBetweenBillingBasePeriodAndRhythm();
213212
end;
214213
}
215214
field(24; "Cancellation Possible Until"; Date)
@@ -435,6 +434,13 @@ table 8002 "Planned Subscription Line"
435434
Validate(Price, 0);
436435
end;
437436

437+
local procedure CheckRatioBetweenBillingBasePeriodAndRhythm()
438+
var
439+
begin
440+
if (Format("Billing Base Period") <> '') and (Format("Billing Rhythm") <> '') then
441+
DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm"));
442+
end;
443+
438444
var
439445
Currency: Record Currency;
440446
CurrExchRate: Record "Currency Exchange Rate";

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,7 @@ table 8068 "Sales Subscription Line"
214214
TestIfSalesOrderIsReleased();
215215
DateFormulaManagement.ErrorIfDateFormulaEmpty("Billing Base Period", FieldCaption("Billing Base Period"));
216216
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"));
217+
CheckRatioBetweenBillingBasePeriodAndRhythm();
219218
end;
220219
}
221220
field(27; "Billing Rhythm"; DateFormula)
@@ -228,8 +227,7 @@ table 8068 "Sales Subscription Line"
228227
TestIfSalesOrderIsReleased();
229228
DateFormulaManagement.ErrorIfDateFormulaEmpty("Billing Rhythm", FieldCaption("Billing Rhythm"));
230229
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"));
230+
CheckRatioBetweenBillingBasePeriodAndRhythm();
233231
end;
234232
}
235233
field(28; "Invoicing via"; Enum "Invoicing Via")
@@ -842,6 +840,13 @@ table 8068 "Sales Subscription Line"
842840
SalesLine := NewSalesLine;
843841
end;
844842

843+
local procedure CheckRatioBetweenBillingBasePeriodAndRhythm()
844+
var
845+
begin
846+
if (Format("Billing Base Period") <> '') and (Format("Billing Rhythm") <> '') then
847+
DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm"));
848+
end;
849+
845850
[IntegrationEvent(false, false)]
846851
local procedure OnCalculateBaseTypeElseCaseOnCalculateCalculationBaseAmountCustomer(SalesSubscriptionLine: Record "Sales Subscription Line"; SalesLine: Record "Sales Line"; var CalculatedBaseAmount: Decimal; var IsHandled: Boolean)
847852
begin

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ 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"));
185+
CheckRatioBetweenBillingBasePeriodAndRhythm();
187186
end;
188187
}
189188
field(16; "Invoicing via"; Enum "Invoicing Via")
@@ -256,8 +255,7 @@ table 8059 "Subscription Line"
256255
begin
257256
DateFormulaManagement.ErrorIfDateFormulaEmpty("Billing Rhythm", FieldCaption("Billing Rhythm"));
258257
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"));
258+
CheckRatioBetweenBillingBasePeriodAndRhythm();
261259
end;
262260
}
263261
field(24; "Cancellation Possible Until"; Date)
@@ -1926,6 +1924,13 @@ table 8059 "Subscription Line"
19261924
end;
19271925
end;
19281926

1927+
local procedure CheckRatioBetweenBillingBasePeriodAndRhythm()
1928+
var
1929+
begin
1930+
if (Format("Billing Base Period") <> '') and (Format("Billing Rhythm") <> '') then
1931+
DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm"));
1932+
end;
1933+
19291934
[IntegrationEvent(false, false)]
19301935
local procedure OnAfterUpdateNextBillingDate(var SubscriptionLine: Record "Subscription Line"; LastBillingToDate: Date)
19311936
begin

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ 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"));
111+
CheckRatioBetweenBillingBasePeriodAndRhythm();
113112
end;
114113
}
115114
field(11; "Billing Rhythm"; DateFormula)
@@ -119,8 +118,7 @@ table 8056 "Subscription Package Line"
119118
begin
120119
DateFormulaManagement.ErrorIfDateFormulaEmpty("Billing Rhythm", FieldCaption("Billing Rhythm"));
121120
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"));
121+
CheckRatioBetweenBillingBasePeriodAndRhythm();
124122
end;
125123
}
126124
field(12; "Sub. Line Start Formula"; DateFormula)
@@ -301,4 +299,11 @@ table 8056 "Subscription Package Line"
301299
begin
302300
exit(Rec.Partner = Rec.Partner::Vendor);
303301
end;
302+
303+
local procedure CheckRatioBetweenBillingBasePeriodAndRhythm()
304+
var
305+
begin
306+
if (Format("Billing Base Period") <> '') and (Format("Billing Rhythm") <> '') then
307+
DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm"));
308+
end;
304309
}

src/Apps/W1/Subscription Billing/Test/Base/ContractTestLibrary.Codeunit.al

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,6 @@ codeunit 139685 "Contract Test Library"
11451145
Clear(ServiceCommitment."Billing Base Period");
11461146
Clear(ServiceCommitment."Billing Rhythm");
11471147
Evaluate(ServiceCommitment."Billing Base Period", BillingBasePeriodText);
1148-
ServiceCommitment.Validate("Billing Base Period");
11491148
Evaluate(ServiceCommitment."Billing Rhythm", BillingRhythmText);
11501149
ServiceCommitment.Validate("Billing Rhythm");
11511150
end;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +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;
66+
NaturalNumberRatioErr: Label 'The ratio of ''%1'' and ''%2'' or vice versa must give a natural number.', Comment = '%1=Field Caption, %2=Field Caption';
6767

6868
#region Tests
6969

@@ -1273,9 +1273,9 @@ codeunit 139915 "Sales Service Commitment Test"
12731273
TwelveMonthsDateFormula: DateFormula;
12741274
FifteenMonthsDateFormula: DateFormula;
12751275
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
1276+
// [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
12771277

1278-
// [GIVEN] A single SalesSubscription Line with Billing Base Period and Billing Rhythm equal to 12M has been created
1278+
// [GIVEN] When a Sales Subscription Line with Billing Base Period and Billing Rhythm equal to 12M has been created
12791279
Initialize();
12801280
Evaluate(TwelveMonthsDateFormula, '<12M>');
12811281
ServiceCommPackageLine.Validate("Billing Base Period", TwelveMonthsDateFormula);
@@ -1287,7 +1287,7 @@ codeunit 139915 "Sales Service Commitment Test"
12871287

12881288
Commit(); // retain data after asserterror
12891289

1290-
// [WHEN] A invalid date formula is created for the purpose of validating Billing Base Period and Billing Rhythm
1290+
// [WHEN] An invalid date formula is created for the purpose of validating Billing Base Period and Billing Rhythm
12911291
Evaluate(FifteenMonthsDateFormula, '<15M>');
12921292

12931293
// [THEN] Error expected when invalid date formula is entered for Billing Base Period or Billing Rhythm

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +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;
27+
NaturalNumberRatioErr: Label 'The ratio of ''%1'' and ''%2'' or vice versa must give a natural number.', Comment = '%1=Field Caption, %2=Field Caption';
2828

2929
#region Tests
3030

@@ -313,15 +313,15 @@ codeunit 148156 "Service Commitment Test"
313313
var
314314
FifteenMonthsDateFormula: DateFormula;
315315
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
316+
// [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
317317

318318
// [GIVEN] A single Subscription Line with Billing Base Period and Billing Rhythm equal to 12M has been created
319319
Initialize();
320320
ContractTestLibrary.CreateServiceObjectForItemWithServiceCommitments(ServiceObject, Enum::"Invoicing Via"::Contract, false, Item, 1, 0, '<12M>', '<12M>');
321321

322322
Commit(); // retain data after asserterror
323323

324-
// [WHEN] A invalid date formula is created for the purpose of validating Billing Base Period and Billing Rhythm
324+
// [WHEN] An invalid date formula is created for the purpose of validating Billing Base Period and Billing Rhythm
325325
Evaluate(FifteenMonthsDateFormula, '<15M>');
326326

327327
// [THEN] Error expected when invalid date formula is entered for Billing Base Period or Billing Rhythm
@@ -338,14 +338,14 @@ codeunit 148156 "Service Commitment Test"
338338
var
339339
FifteenMonthsDateFormula: DateFormula;
340340
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
341+
// [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
342342

343343
// [GIVEN] A single Subscription Package Line with Billing Base Period and Billing Rhythm equal to 12M has been created
344344
Initialize();
345345
ContractTestLibrary.CreateServiceCommitmentPackageWithLine('', ServiceCommitmentPackage, ServiceCommPackageLine);
346346
Commit(); // retain data after asserterror
347347

348-
// [WHEN] A invalid date formula is created for the purpose of validating Billing Base Period and Billing Rhythm
348+
// [WHEN] An invalid date formula is created for the purpose of validating Billing Base Period and Billing Rhythm
349349
Evaluate(FifteenMonthsDateFormula, '<15M>');
350350

351351
// [THEN] Error expected when invalid date formula is entered for Billing Base Period or Billing Rhythm
@@ -511,14 +511,14 @@ codeunit 148156 "Service Commitment Test"
511511

512512
local procedure ValidateDateFormulaCombinations(DateFormulaText1: Text; DateFormulaText2: Text)
513513
var
514-
DateFormula1: DateFormula;
514+
EvaluatedDateFormula: DateFormula;
515515
begin
516516
ServiceCommPackageLine.Get(ServiceCommPackageLine."Subscription Package Code", ServiceCommPackageLine."Line No.");
517-
Evaluate(DateFormula1, DateFormulaText1);
518-
ServiceCommPackageLine."Billing Base Period" := DateFormula1;
519-
Evaluate(DateFormula1, DateFormulaText2);
520-
ServiceCommPackageLine."Billing Rhythm" := DateFormula1;
521-
ServiceCommPackageLine.Modify(true);
517+
Evaluate(EvaluatedDateFormula, DateFormulaText1);
518+
ServiceCommPackageLine."Billing Base Period" := EvaluatedDateFormula;
519+
Evaluate(EvaluatedDateFormula, DateFormulaText2);
520+
ServiceCommPackageLine.Validate("Billing Rhythm", EvaluatedDateFormula);
521+
ServiceCommPackageLine.Modify(false);
522522
end;
523523

524524
#endregion Procedures

0 commit comments

Comments
 (0)