@@ -18,7 +18,7 @@ codeunit 134530 "No. Series Tests"
18
18
Any: Codeunit Any;
19
19
LibraryAssert: Codeunit "Library Assert";
20
20
LibraryNoSeries: Codeunit "Library - No. Series";
21
- CannotAssignNewErr: Label ' You cannot assign new numbers from the number series %1. ' , Comment = ' %1=No. Series Code' ;
21
+ CannotAssignNewErr: Label ' You cannot assign new numbers from the number series %1' , Comment = ' %1=No. Series Code' ;
22
22
23
23
#region sequence
24
24
[Test]
@@ -275,6 +275,69 @@ codeunit 134530 "No. Series Tests"
275
275
asserterror NoSeries. PeekNextNo( NoSeriesCode) ;
276
276
LibraryAssert. ExpectedError( StrSubstNo( CannotAssignNewErr, NoSeriesCode)) ;
277
277
end ;
278
+
279
+
280
+ [Test]
281
+ procedure TestGetNextNoWithMultipleLinesExhaustClosedLine_Sequence()
282
+ var
283
+ NoSeries: Codeunit "No. Series";
284
+ PermissionsMock: Codeunit "Permissions Mock";
285
+ NoSeriesCode: Code [20 ];
286
+ begin
287
+ // [Scenario] [Bug 538011] When we have multiple lines, the GetNextNo should return value from latest line. If there is no number left in the latest line, it should throw an error even there are numbers left in previous line.
288
+ // [GIVEN] Initialize the test
289
+ Initialize() ;
290
+ PermissionsMock. Set( ' No. Series - Admin' ) ;
291
+
292
+ // [GIVEN] Create a No. Series
293
+ NoSeriesCode := CopyStr( UpperCase( Any. AlphabeticText( MaxStrLen( NoSeriesCode))) , 1 , MaxStrLen( NoSeriesCode)) ;
294
+ LibraryNoSeries. CreateNoSeries( NoSeriesCode) ;
295
+ // [GIVEN] Create the first line with 10 numbers and no start day, and the 'Last No. Used' set to 'TEST0005'
296
+ LibraryNoSeries. CreateSequenceNoSeriesLine( NoSeriesCode, 1 , ' TEST0001' , ' TEST0010' , ' TEST0005' , 0D) ;
297
+ // [GIVEN] Create the second line with 10 numbers and the start date is today, and the 'Last No. Used' set to 'TEST0039', so only one number is left
298
+ LibraryNoSeries. CreateSequenceNoSeriesLine( NoSeriesCode, 1 , ' TEST0030' , ' TEST0040' , ' TEST0039' , Today()) ;
299
+
300
+ PermissionsMock. SetExactPermissionSet( ' No. Series Test' ) ;
301
+
302
+ // [WHEN] Call GetNextNo and we get the last number from the second Series Line.
303
+ LibraryAssert. AreEqual( ' TEST0040' , NoSeries. GetNextNo( NoSeriesCode, Today()) , ' Get the last SN from the second Series Line' ) ;
304
+ // [Then] Call GetNextNo again, and we get an error since the second Series Line is out of SN although the first Series Line still has SN.
305
+ asserterror NoSeries. GetNextNo( NoSeriesCode, Today()) ;
306
+ LibraryAssert. ExpectedError( StrSubstNo( CannotAssignNewErr, NoSeriesCode)) ;
307
+ end ;
308
+
309
+ #if not CLEAN24
310
+ #pragma warning disable AL0432
311
+ [Test]
312
+ procedure TestGetNextNoWithMultipleLinesExhaustClosedLine_Sequence_ObsoleteCode()
313
+ var
314
+ NoSeriesManagement: Codeunit NoSeriesManagement;
315
+ PermissionsMock: Codeunit "Permissions Mock";
316
+ NoSeriesCode: Code [20 ];
317
+ begin
318
+ // [Scenario] [Bug 538011] When we have multiple lines, the GetNextNo should return value from latest line. If there is no number left in the latest line, it should throw an error even there are numbers left in previous line.
319
+ // [GIVEN] Initialize the test
320
+ Initialize() ;
321
+ PermissionsMock. Set( ' No. Series - Admin' ) ;
322
+
323
+ // [GIVEN] Create a No. Series
324
+ NoSeriesCode := CopyStr( UpperCase( Any. AlphabeticText( MaxStrLen( NoSeriesCode))) , 1 , MaxStrLen( NoSeriesCode)) ;
325
+ LibraryNoSeries. CreateNoSeries( NoSeriesCode) ;
326
+ // [GIVEN] Create the first line with 10 numbers and no start day, and the 'Last No. Used' set to 'TEST0005'
327
+ LibraryNoSeries. CreateSequenceNoSeriesLine( NoSeriesCode, 1 , ' TEST0001' , ' TEST0010' , ' TEST0005' , 0D) ;
328
+ // [GIVEN] Create the second line with 10 numbers and the start date is today, and the 'Last No. Used' set to 'TEST0039', so only one number is left
329
+ LibraryNoSeries. CreateSequenceNoSeriesLine( NoSeriesCode, 1 , ' TEST0030' , ' TEST0040' , ' TEST0039' , Today()) ;
330
+
331
+ PermissionsMock. SetExactPermissionSet( ' No. Series Test' ) ;
332
+
333
+ // [WHEN] Call GetNextNo and we get the last number from the second Series Line.
334
+ LibraryAssert. AreEqual( ' TEST0040' , NoSeriesManagement. GetNextNo( NoSeriesCode, Today() , true) , ' Get the last SN from the second Series Line' ) ;
335
+ // [Then] Call GetNextNo again, and we get an error since the second Series Line is out of SN although the first Series Line still has SN.
336
+ asserterror NoSeriesManagement. GetNextNo( NoSeriesCode, Today() , true) ;
337
+ LibraryAssert. ExpectedError( StrSubstNo( CannotAssignNewErr, NoSeriesCode)) ;
338
+ end ;
339
+ #pragma warning restore AL0432
340
+ #endif
278
341
#endregion
279
342
280
343
#region normal
@@ -566,6 +629,68 @@ codeunit 134530 "No. Series Tests"
566
629
LibraryAssert. AreEqual( StartingNo, NoSeries. GetNextNo( NoSeriesCode) , ' not the first number' ) ;
567
630
LibraryAssert. AreEqual( IncStr( StartingNo) , NoSeries. GetNextNo( NoSeriesCode) , ' not the second number' ) ;
568
631
end ;
632
+
633
+ [Test]
634
+ procedure TestGetNextNoWithMultipleLinesExhaustClosedLine()
635
+ var
636
+ NoSeries: Codeunit "No. Series";
637
+ PermissionsMock: Codeunit "Permissions Mock";
638
+ NoSeriesCode: Code [20 ];
639
+ begin
640
+ // [Scenario] [Bug 538011] When we have multiple lines, the GetNextNo should return value from latest line. If there is no number left in the latest line, it should throw an error even there are numbers left in previous line.
641
+ // [GIVEN] Initialize the test
642
+ Initialize() ;
643
+ PermissionsMock. Set( ' No. Series - Admin' ) ;
644
+
645
+ // [GIVEN] Create a No. Series
646
+ NoSeriesCode := CopyStr( UpperCase( Any. AlphabeticText( MaxStrLen( NoSeriesCode))) , 1 , MaxStrLen( NoSeriesCode)) ;
647
+ LibraryNoSeries. CreateNoSeries( NoSeriesCode) ;
648
+ // [GIVEN] Create the first line with 10 numbers and no start day, and the 'Last No. Used' set to 'TEST0005'
649
+ LibraryNoSeries. CreateNormalNoSeriesLine( NoSeriesCode, 1 , ' TEST0001' , ' TEST0010' , ' TEST0005' , 0D) ;
650
+ // [GIVEN] Create the second line with 10 numbers and the start date is today, and the 'Last No. Used' set to 'TEST0039', so only one number is left
651
+ LibraryNoSeries. CreateNormalNoSeriesLine( NoSeriesCode, 1 , ' TEST0030' , ' TEST0040' , ' TEST0039' , Today()) ;
652
+
653
+ PermissionsMock. SetExactPermissionSet( ' No. Series Test' ) ;
654
+
655
+ // [WHEN] Call GetNextNo and we get the last number from the second Series Line.
656
+ LibraryAssert. AreEqual( ' TEST0040' , NoSeries. GetNextNo( NoSeriesCode, Today()) , ' Get the last SN from the second Series Line' ) ;
657
+ // [Then] Call GetNextNo again, and we get an error since the second Series Line is out of SN although the first Series Line still has SN.
658
+ asserterror NoSeries. GetNextNo( NoSeriesCode, Today()) ;
659
+ LibraryAssert. ExpectedError( StrSubstNo( CannotAssignNewErr, NoSeriesCode)) ;
660
+ end ;
661
+
662
+ #if not CLEAN24
663
+ #pragma warning disable AL0432
664
+ [Test]
665
+ procedure TestGetNextNoWithMultipleLinesExhaustClosedLine_ObsoleteCode()
666
+ var
667
+ NoSeriesManagement: Codeunit NoSeriesManagement;
668
+ PermissionsMock: Codeunit "Permissions Mock";
669
+ NoSeriesCode: Code [20 ];
670
+ begin
671
+ // [Scenario] [Bug 538011] When we have multiple lines, the GetNextNo should return value from latest line. If there is no number left in the latest line, it should throw an error even there are numbers left in previous line.
672
+ // [GIVEN] Initialize the test
673
+ Initialize() ;
674
+ PermissionsMock. Set( ' No. Series - Admin' ) ;
675
+
676
+ // [GIVEN] Create a No. Series
677
+ NoSeriesCode := CopyStr( UpperCase( Any. AlphabeticText( MaxStrLen( NoSeriesCode))) , 1 , MaxStrLen( NoSeriesCode)) ;
678
+ LibraryNoSeries. CreateNoSeries( NoSeriesCode) ;
679
+ // [GIVEN] Create the first line with 10 numbers and no start day, and the 'Last No. Used' set to 'TEST0005'
680
+ LibraryNoSeries. CreateNormalNoSeriesLine( NoSeriesCode, 1 , ' TEST0001' , ' TEST0010' , ' TEST0005' , 0D) ;
681
+ // [GIVEN] Create the second line with 10 numbers and the start date is today, and the 'Last No. Used' set to 'TEST0039', so only one number is left
682
+ LibraryNoSeries. CreateNormalNoSeriesLine( NoSeriesCode, 1 , ' TEST0030' , ' TEST0040' , ' TEST0039' , Today()) ;
683
+
684
+ PermissionsMock. SetExactPermissionSet( ' No. Series Test' ) ;
685
+
686
+ // [WHEN] Call GetNextNo and we get the last number from the second Series Line.
687
+ LibraryAssert. AreEqual( ' TEST0040' , NoSeriesManagement. GetNextNo( NoSeriesCode, Today() , true) , ' Get the last SN from the second Series Line' ) ;
688
+ // [Then] Call GetNextNo again, and we get an error since the second Series Line is out of SN although the first Series Line still has SN.
689
+ asserterror NoSeriesManagement. GetNextNo( NoSeriesCode, Today() , true) ;
690
+ LibraryAssert. ExpectedError( StrSubstNo( CannotAssignNewErr, NoSeriesCode)) ;
691
+ end ;
692
+ #pragma warning restore AL0432
693
+ #endif
569
694
#endregion
570
695
571
696
#region GetLastNoUsed
0 commit comments