-
Notifications
You must be signed in to change notification settings - Fork 402
Expand file tree
/
Copy pathJobConsumptionPurchase.Codeunit.al
More file actions
7119 lines (6184 loc) · 346 KB
/
Copy pathJobConsumptionPurchase.Codeunit.al
File metadata and controls
7119 lines (6184 loc) · 346 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
codeunit 136302 "Job Consumption Purchase"
{
Subtype = Test;
TestPermissions = Disabled;
trigger OnRun()
begin
// [FEATURE] [Purchase] [Job]
Initialized := false;
end;
var
DummyJobsSetup: Record "Jobs Setup";
LocationReceiveYesPutAwayNoBinsNo: Record Location;
LocationReceiveYesPutAwayNoBinsYes: Record Location;
LocationReceiveYesPutAwayYesBinsNo: Record Location;
LocationReceiveYesPutAwayYesBinsYes: Record Location;
LocationDirectedPutAwayAndPick: Record Location;
LocationReceiveNoPutAwayYesBinsNo: Record Location;
LocationReceiveNoPutAwayYesBinsYes: Record Location;
LibraryErrorMessage: Codeunit "Library - Error Message";
LibraryJob: Codeunit "Library - Job";
LibraryPurchase: Codeunit "Library - Purchase";
LibraryInventory: Codeunit "Library - Inventory";
LibraryWarehouse: Codeunit "Library - Warehouse";
LibraryItemTracking: Codeunit "Library - Item Tracking";
LibraryCosting: Codeunit "Library - Costing";
LibraryERM: Codeunit "Library - ERM";
Assert: Codeunit Assert;
LibraryTestInitialize: Codeunit "Library - Test Initialize";
CodeMandatoryDimensionErr: Label 'The dimensions used in Order %1, line no. %2 are invalid (Error: Select a %3 for the %4 %5 for Project %6.).', Comment = '%1=Field value,%2=Field value,%3=Field value,%4=Field name,%5=Field name,%6=Field name';
SameCodeOrNoCodeDimensionErr: Label 'The dimensions used in Order %1, line no. %2 are invalid (Error: The %3 must be %4 for %5 %6 for %7 %8. Currently it''s %9.', Comment = '%1=Field value,%2=Field value, %3 = "Dimension value code" caption, %4 = expected "Dimension value code" value, %5 = "Dimension code" caption, %6 = "Dimension Code" value, %7 = Table caption (Vendor), %8 = Table value (XYZ), %9 = current "Dimension value code" value';
BlankLbl: Label 'blank';
LibraryUtility: Codeunit "Library - Utility";
LibrarySales: Codeunit "Library - Sales";
LibraryPlanning: Codeunit "Library - Planning";
LibraryRandom: Codeunit "Library - Random";
LibraryVariableStorage: Codeunit "Library - Variable Storage";
LibrarySetupStorage: Codeunit "Library - Setup Storage";
LibraryDimension: Codeunit "Library - Dimension";
LibraryTemplates: Codeunit "Library - Templates";
Initialized: Boolean;
WrongDimJobLedgerEntryErr: Label 'Wrong Dim on Project Ledger entry %1! Expected ID: %2, Actual ID: %3.';
FieldErr: Label '%1 must be equal %2 in %3.';
ValueMustMatchErr: Label '%1 must equal to %2.';
EmptyValueErr: Label '%1 is empty in %2';
WrongTotalCostAmtErr: Label 'Total cost amount must be 0 in Posted Purchase Receipt %1.', Comment = '%1 = Document No. (e.g. "Total cost amount must be 0 in Posted Purchase Receipt 107031").';
JobPlanningLineQuantityErr: Label 'The Project Planning Line Quantity should not change.';
MustNotBeChangedErr: Label '%1 must not be changed', Comment = '%1 = Field caption';
RequisitionLineErr: Label 'Expected Requisition Line for Item No. %1 is %2.';
[Test]
[Scope('OnPrem')]
procedure DocumentDateOnJobLedgerEntry()
var
JobTask: Record "Job Task";
PurchaseHeader: Record "Purchase Header";
PurchaseLine: Record "Purchase Line";
DocumentNo: Code[20];
begin
// [SCENARIO] Verify Document Date on Job Ledger Entry.
// [GIVEN] Create Purchase Invoice with Job.
Initialize();
CreateJobWithJobTask(JobTask);
CreatePurchaseDocumentWithJobTask(
PurchaseHeader, JobTask, PurchaseHeader."Document Type"::Invoice, PurchaseLine.Type::Item, CreateItem());
// [WHEN] Post the Purhcase Invoice.
DocumentNo := LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, true);
// [THEN] Verify Document Date on Job Ledger Entry.
VerifyDocumentDateOnJobLedgerEntry(JobTask."Job No.", DocumentNo, PurchaseHeader."Document Date");
end;
[Test]
[Scope('OnPrem')]
procedure JobPlanningLineWithFullQuantity()
var
Quantity: Decimal;
begin
// [SCENARIO] Verify Quantity on Job Planning Line when Purchase Order posted with full Quantity.
Initialize();
Quantity := LibraryRandom.RandDec(10, 2);
PreparePurchHeaderWithJobPlanningNo(Quantity, Quantity);
end;
[Test]
[Scope('OnPrem')]
procedure JobPlanningLineWithPartialQuantity()
var
Quantity: Decimal;
begin
// [SCENARIO] Verify Quantity on Job Planning Line when Purchase Order posted with partial Quantity.
Initialize();
Quantity := LibraryRandom.RandDec(10, 2);
PreparePurchHeaderWithJobPlanningNo(Quantity, Quantity / 2);
end;
[Test]
[Scope('OnPrem')]
procedure PreparePurchHeaderWithRemainingQty()
var
JobPlanningLine: Record "Job Planning Line";
PurchaseHeader: Record "Purchase Header";
Quantity: Decimal;
QtyToReceive: Decimal;
begin
// [SCENARIO] Verify Quantity on Job Planning Line when Purchase Order posted with Remaining Quantity.
// [GIVEN] Create Purchase Order with Job Planning Line No. and update Quantity To Receive on Purchase Line.
Initialize();
Quantity := LibraryRandom.RandDec(10, 2);
QtyToReceive := Quantity / 2;
PreparePurchHeaderAndJobPlanningLine(PurchaseHeader, JobPlanningLine, Quantity, QtyToReceive);
LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, true);
UpdateVendorInvoiceNoOnPurchaseHeader(PurchaseHeader);
UpdatePurchLineQtyToReceive(PurchaseHeader, Quantity - QtyToReceive);
// [WHEN] Post Purchase Order with Remaining Quantity.
LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, true);
// [THEN] Verify Quantity on Job Planning Line.
VerifyQuantityOnJobPlanningLine(JobPlanningLine, Quantity);
end;
[Test]
[Scope('OnPrem')]
procedure JobPlanningLineOnPurchaseOrderPartialQtyToInvoice()
var
JobPlanningLine: Record "Job Planning Line";
PurchaseHeader: Record "Purchase Header";
Quantity: Decimal;
begin
// [SCENARIO] Verify Quantity on Job Planning Line when Purchase Order after updating Qty. to Invoice posted with partial Quantity.
// [GIVEN] Create Purchase Order with Job Planning Line No. and update Quantity To Invoice on Purchase Line.
Initialize();
Quantity := CreatePurchaseOrderWithUpdatedQuantities(PurchaseHeader, JobPlanningLine);
// [WHEN] Post Purchase Order with updated Qty. to Invoice.
LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, true);
// [THEN] Verify Quantity on Job Planning Line.
VerifyQuantityOnJobPlanningLine(JobPlanningLine, Quantity);
end;
[Test]
[Scope('OnPrem')]
procedure JobPlanningLineOnPurchaseOrderFullQtyToInvoice()
var
JobPlanningLine: Record "Job Planning Line";
PurchaseHeader: Record "Purchase Header";
Quantity: Decimal;
begin
// [SCENARIO] Verify Quantity on Job Planning Line when Purchase Order after updating Qty. to Invoice posted with full Quantity.
// [GIVEN] Create Purchase Order with Job Planning Line No. and update Quantity To Invoice on Purchase Line.
Initialize();
Quantity := CreatePurchaseOrderWithUpdatedQuantities(PurchaseHeader, JobPlanningLine);
LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, true);
UpdateVendorInvoiceNoOnPurchaseHeader(PurchaseHeader);
// [WHEN] Post Purchase Order with updated Qty. to Invoice.
LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, true);
// [THEN] Verify Quantity on Job Planning Line.
VerifyQuantityOnJobPlanningLine(JobPlanningLine, Quantity);
end;
[Test]
[Scope('OnPrem')]
procedure JobRemainingQtyOnPurchaseLine()
var
JobPlanningLine: Record "Job Planning Line";
JobPlanningLine2: Record "Job Planning Line";
JobTask: Record "Job Task";
PurchaseHeader: Record "Purchase Header";
PurchaseLine: Record "Purchase Line";
Quantity: Decimal;
RemainingQty: Decimal;
begin
// [SCENARIO] Verify Job Remaining Qty. on Purchase Line when Job Planning Line No. is updated.
// [GIVEN] Prepare Purchase Order with Job Planning Line No.
Initialize();
RemainingQty := LibraryRandom.RandDec(3, 2);
Quantity := RemainingQty + LibraryRandom.RandDec(7, 2);
PreparePurchHeaderAndJobPlanningLine(PurchaseHeader, JobPlanningLine, Quantity, Quantity - RemainingQty);
JobTask.Get(JobPlanningLine."Job No.", JobPlanningLine."Job Task No.");
CreateJobPlanningLine(JobPlanningLine2, JobTask,
JobPlanningLine.Type::Item, JobPlanningLine."No.", LibraryRandom.RandDecInRange(11, 20, 2), true);
GetPurchaseLines(PurchaseHeader, PurchaseLine);
// [WHEN] Update Job Planning Line No.
PurchaseLine.Validate("Job Planning Line No.", JobPlanningLine2."Line No.");
PurchaseLine.Modify(true);
// [THEN] Verify Job Remaining Qty. on Purchase Line.
PurchaseLine.TestField("Job Remaining Qty.", JobPlanningLine2."Remaining Qty." - PurchaseLine."Qty. to Invoice");
end;
[Test]
[Scope('OnPrem')]
procedure JobOnPurchaseInvoiceLine()
var
OrderPurchaseHeader: Record "Purchase Header";
InvoicePurchaseHeader: Record "Purchase Header";
PurchaseLine: Record "Purchase Line";
TempPurchaseLine: Record "Purchase Line" temporary;
begin
// [SCENARIO] Test integration of Jobs with Get Receipt Lines. Check that the information related to Job is copied to Purchase Invoice Line
// [SCENARIO] after creation of Invoice Lines by using the Get Receipt Lines function for a Purchase Order with Job attached to it. Test
// [SCENARIO] modification of Job related fields is not allowed after receipt.
// [SCENARIO] Check Job Planning Line, Job Ledger Entry, G/L Entry, Value Entry created after posting of Purchase Invoice.
// [GIVEN] Create a Purchase Order with Job selected on the Purchase Lines and post it as Receive.
Initialize();
CreatePurchaseOrderForJobTask(OrderPurchaseHeader);
GetPurchaseLines(OrderPurchaseHeader, PurchaseLine);
LibraryJob.CopyPurchaseLines(PurchaseLine, TempPurchaseLine);
LibraryPurchase.PostPurchaseDocument(OrderPurchaseHeader, true, false);
// [THEN] Check that job info for received order cannot be modified.
VerifyModifyPurchaseDocJobInfo(OrderPurchaseHeader);
VerifyJobInfoOnPurchRcptLines(TempPurchaseLine);
VerifyItemLedger(TempPurchaseLine);
// [WHEN] Create a Purchase Invoice by using the Get Receipt Line function for the Purchase Receipt created earlier.
CreateInvoiceWithGetReceipt(OrderPurchaseHeader."No.", InvoicePurchaseHeader);
// Saving the purchase invoice lines
GetPurchaseLines(InvoicePurchaseHeader, PurchaseLine);
TempPurchaseLine.DeleteAll();
LibraryJob.CopyPurchaseLines(PurchaseLine, TempPurchaseLine);
// [THEN] Check that the information related to Job is copied to Purchase Invoice Line after creation of Invoice Lines by using
// [THEN] the Get Receipt Lines function for a Purchase Order with Job attached to it. Check that the modification of job related fields is
// [THEN] not allowed after receive.
VerifyJobInfoOnPurchInvoice(OrderPurchaseHeader, InvoicePurchaseHeader);
VerifyModifyPurchaseDocJobInfo(InvoicePurchaseHeader);
// [WHEN] Post the Purchase Invoice.
LibraryPurchase.PostPurchaseDocument(InvoicePurchaseHeader, false, true);
// [THEN] Check the entries created after Posting of Purchase Invoice.
LibraryJob.VerifyPurchaseDocPostingForJob(TempPurchaseLine);
VerifyGLEntry(TempPurchaseLine);
VerifyValueEntries(TempPurchaseLine)
end;
[Test]
[Scope('OnPrem')]
procedure PostPurchaseOrderBlankJobTask()
var
PurchaseHeader: Record "Purchase Header";
PurchaseLine: Record "Purchase Line";
begin
// [SCENARIO] Test that the application generates an error message on posting Purchase Order with Job specified and blank Job Task No.
// [GIVEN] Create a Purchase Order with Job selected on the Purchase Lines and blank Job Task No.
Initialize();
CreatePurchaseOrderForJobTask(PurchaseHeader);
// remove job task no.
GetPurchaseLines(PurchaseHeader, PurchaseLine);
PurchaseLine.Validate("Job Task No.", '');
PurchaseLine.Modify(true);
// [WHEN] Post the Purchase Order as Receive.
asserterror LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, false);
// [THEN] Check error message on posting Purchase order with Job specified and blank Job Task No.
Assert.ExpectedTestFieldError(PurchaseLine.FieldCaption("Job Task No."), '');
end;
[Test]
[Scope('OnPrem')]
procedure JobWithPostedPurchaseOrder()
var
PurchaseHeader: Record "Purchase Header";
TempPurchaseLine: Record "Purchase Line" temporary;
PurchaseLine: Record "Purchase Line";
begin
// [SCENARIO] Test Job Planning Line and Job Ledger Entry created after posting of Purchase Order with Job attached on it.
// [GIVEN] Create a Purchase Order with Job selected on the Purchase Lines. Save Purchase Line in temporary table.
Initialize();
CreatePurchaseOrderForJobTask(PurchaseHeader);
// Save purchase lines.
GetPurchaseLines(PurchaseHeader, PurchaseLine);
LibraryJob.CopyPurchaseLines(PurchaseLine, TempPurchaseLine);
// [WHEN] Post the Purchase Order as Receive and Invoice.
LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, true);
// [THEN] Check the entries created after Posting of Purchase Order.
LibraryJob.VerifyPurchaseDocPostingForJob(TempPurchaseLine);
end;
[Test]
[Scope('OnPrem')]
procedure JobFieldsCopiedPurchaseOrder()
var
PurchaseHeader: Record "Purchase Header";
PurchaseLine: Record "Purchase Line";
begin
// [SCENARIO] Test Job Unit Price and Job Line Discount Amount are automatically filled in.
// [GIVEN]
Initialize();
// [WHEN] Create a Purchase Order with Job selected on the Purchase Lines.
CreatePurchaseOrderForJobTask(PurchaseHeader);
// [THEN] Check that the Job Unit Price and Job Line Discount Amount are automatically filled in.
GetPurchaseLines(PurchaseHeader, PurchaseLine);
VerifyJobInfo(PurchaseLine)
end;
[Test]
[HandlerFunctions('ConfirmHandlerTrue')]
[Scope('OnPrem')]
procedure DimensionCodeMandatory()
var
DefaultDimension: Record "Default Dimension";
begin
// [SCENARIO] Test dimensions on the Purchase Order are transferred correctly to Job Ledger Entry for Code Mandatory.
DimensionValuePosting(DefaultDimension."Value Posting"::"Code Mandatory");
end;
[Test]
[HandlerFunctions('ConfirmHandlerTrue')]
[Scope('OnPrem')]
procedure DimensionSameCode()
var
DefaultDimension: Record "Default Dimension";
begin
// [SCENARIO] Test dimensions on the Purchase Order are transferred correctly to Job Ledger Entry for Same Code.
DimensionValuePosting(DefaultDimension."Value Posting"::"Same Code");
end;
local procedure DimensionValuePosting(ValuePosting: Enum "Default Dimension value Posting Type")
var
PurchaseHeader: Record "Purchase Header";
PurchaseLine: Record "Purchase Line";
Job: Record Job;
HeaderDimSetID: Integer;
DocumentNo: Code[20];
begin
// [GIVEN] Create a Purchase Order with Job having dimension with Value Posting selected on the Purchase Lines.
Initialize();
CreatePurchaseOrderForJobTask(PurchaseHeader);
DocumentNo := PurchaseHeader."No.";
GetPurchaseLines(PurchaseHeader, PurchaseLine);
Job.Get(PurchaseLine."Job No.");
CreateDefaultDimForJob(Job."No.", ValuePosting);
HeaderDimSetID := PurchaseHeader."Dimension Set ID";
repeat
SetupDocumentDimPurchaseLine(PurchaseLine)
until PurchaseLine.Next() = 0;
// [WHEN] Post the Purchase Order as Receive and Invoice.
LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, true);
// [THEN] Check that dimensions on the Purchase Order are transferred correctly to Job Ledger Entry.
VerifyJobLedgerEntryDim(DocumentNo, HeaderDimSetID);
end;
[Test]
[HandlerFunctions('ConfirmHandlerTrue')]
[Scope('OnPrem')]
procedure DimensionCodeMandatoryError()
var
DefaultDimension: Record "Default Dimension";
PurchaseHeader: Record "Purchase Header";
PurchaseLine: Record "Purchase Line";
ExpectedError: Text;
begin
// [SCENARIO] The error if dimension value has not been specified on Purchase Line having Job with 'Code Mandatory'.
// [GIVEN] Create a Purchase Order with Job having dimension with Value Posting 'Code Mandatory' selected on the Purchase Lines.
PostOrderWithDimValuePostingError(
DefaultDimension."Value Posting"::"Code Mandatory", PurchaseHeader, PurchaseLine, DefaultDimension);
// [WHEN] Post the Purchase Order
Assert.IsFalse(PurchaseHeader.SendToPosting(CODEUNIT::"Purch.-Post"), 'Posting should fail');
// [THEN] Check that the application generates an error if dimensions are not selected correctly on Purchase Line.
ExpectedError :=
StrSubstNo(
CodeMandatoryDimensionErr, PurchaseHeader."No.", PurchaseLine."Line No.",
DefaultDimension.FieldCaption("Dimension Value Code"),
DefaultDimension.FieldCaption("Dimension Code"), DefaultDimension."Dimension Code", PurchaseLine."Job No.");
VerifyDimensionErrorMessage(ExpectedError);
end;
[Test]
[HandlerFunctions('ConfirmHandlerTrue')]
[Scope('OnPrem')]
procedure DimensionSameCodeError()
var
DefaultDimension: Record "Default Dimension";
PurchaseHeader: Record "Purchase Header";
PurchaseLine: Record "Purchase Line";
DimensionSetEntry: Record "Dimension Set Entry";
Job: Record Job;
ExpectedError: Text;
begin
// [SCENARIO] The error if dimension on Purchase Line are different from those on Job for 'Same Code'.
// [GIVEN] Create a Purchase Order with Job having dimension with Value Posting 'Same Code' selected on the Purchase Lines.
PostOrderWithDimValuePostingError(
DefaultDimension."Value Posting"::"Same Code", PurchaseHeader, PurchaseLine, DefaultDimension);
// [WHEN] Post the Purchase Order
Assert.IsFalse(PurchaseHeader.SendToPosting(CODEUNIT::"Purch.-Post"), 'Posting should fail');
// [THEN] Check that the application generates an error if dimensions are not selected correctly on Purchase Line.
LibraryDimension.FindDimensionSetEntry(DimensionSetEntry, PurchaseLine."Dimension Set ID");
ExpectedError :=
StrSubstNo(
SameCodeOrNoCodeDimensionErr, PurchaseHeader."No.", PurchaseLine."Line No.",
DefaultDimension.FieldCaption("Dimension Value Code"), DefaultDimension."Dimension Value Code",
DefaultDimension.FieldCaption("Dimension Code"), DefaultDimension."Dimension Code",
Job.TableCaption(), PurchaseLine."Job No.",
DimensionSetEntry."Dimension Value Code");
VerifyDimensionErrorMessage(ExpectedError);
end;
[Test]
[HandlerFunctions('ConfirmHandlerFalse')]
[Scope('OnPrem')]
procedure DimensionNoCodeError()
var
DefaultDimension: Record "Default Dimension";
PurchaseHeader: Record "Purchase Header";
PurchaseLine: Record "Purchase Line";
DimensionSetEntry: Record "Dimension Set Entry";
Job: Record Job;
ExpectedError: Text;
begin
// [SCENARIO] The error if dimension value has been specified on Purchase Line having Job with 'No Code'.
// [GIVEN] Create a Purchase Order with Job having dimension with Value Posting 'No Code' selected on the Purchase Lines.
PostOrderWithDimValuePostingError(
DefaultDimension."Value Posting"::"No Code", PurchaseHeader, PurchaseLine, DefaultDimension);
// [WHEN] Post the Purchase Order
Assert.IsFalse(PurchaseHeader.SendToPosting(CODEUNIT::"Purch.-Post"), 'Posting should fail');
// [THEN] Check that the application generates an error if dimensions are not selected correctly on Purchase Line.
LibraryDimension.FindDimensionSetEntry(DimensionSetEntry, PurchaseLine."Dimension Set ID");
ExpectedError :=
StrSubstNo(
SameCodeOrNoCodeDimensionErr, PurchaseHeader."No.", PurchaseLine."Line No.",
DefaultDimension.FieldCaption("Dimension Value Code"), BlankLbl,
DefaultDimension.FieldCaption("Dimension Code"), DefaultDimension."Dimension Code",
Job.TableCaption(), PurchaseLine."Job No.",
DimensionSetEntry."Dimension Value Code");
VerifyDimensionErrorMessage(ExpectedError);
end;
local procedure PostOrderWithDimValuePostingError(ValuePosting: Enum "Default Dimension value Posting Type"; var PurchaseHeader: Record "Purchase Header"; var PurchaseLine: Record "Purchase Line"; var DefaultDimension: Record "Default Dimension")
var
Job: Record Job;
begin
Initialize();
CreatePurchaseOrderForJobTask(PurchaseHeader);
GetPurchaseLines(PurchaseHeader, PurchaseLine);
Job.Get(PurchaseLine."Job No.");
CreateDefaultDimForJob(Job."No.", ValuePosting);
repeat
SetupDocumentDimLineError(PurchaseLine, DefaultDimension)
until PurchaseLine.Next() = 0;
PurchaseLine.FindFirst();
PurchaseHeader.Receive := true;
PurchaseHeader.Invoice := true;
PurchaseHeader.Modify();
Commit();
LibraryErrorMessage.TrapErrorMessages();
end;
[Test]
[Scope('OnPrem')]
procedure ReceiveAndInvoicePurchaseOrder()
var
PurchaseHeader: Record "Purchase Header";
TempPurchaseLine: Record "Purchase Line" temporary;
PurchaseLine: Record "Purchase Line";
begin
// [SCENARIO] Test integration of Jobs with posting of Purchase Order as Receive and then Invoice separately.
// [SCENARIO] Check G/L Entry, Value Entry, Job Ledger Entry, Job Planning Line created.
// [GIVEN] Create a Purchase Order with Job selected on the Purchase Lines. Save Purchase Line in temporary table.
Initialize();
CreatePurchaseOrderForJobTask(PurchaseHeader);
GetPurchaseLines(PurchaseHeader, PurchaseLine);
LibraryJob.CopyPurchaseLines(PurchaseLine, TempPurchaseLine);
// [WHEN] Post the Purchase Order as Receive and then post again as Invoice.
LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, false);
LibraryPurchase.PostPurchaseDocument(PurchaseHeader, false, true);
// [THEN] Check the entries created after Posting of Purchase Order.
VerifyGLEntry(TempPurchaseLine);
VerifyValueEntries(TempPurchaseLine);
LibraryJob.VerifyPurchaseDocPostingForJob(TempPurchaseLine)
end;
[Test]
[Scope('OnPrem')]
procedure PostMixedPurchaseOrder()
var
PurchaseHeader: Record "Purchase Header";
TempPurchaseLine: Record "Purchase Line" temporary;
PurchaseLine: Record "Purchase Line";
begin
// [GIVEN] Create a Purchase Order with Job selected on the Purchase Lines. Add Purchase Lines without Job.
Initialize();
CreatePurchaseOrderForJobTask(PurchaseHeader);
CreatePurchaseLines(PurchaseHeader);
GetPurchaseLines(PurchaseHeader, PurchaseLine);
LibraryJob.CopyPurchaseLines(PurchaseLine, TempPurchaseLine);
// [WHEN] Post the Purchase Order as Receive and Invoice.
LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, true);
// [THEN] Check the entries created after Posting of Purchase Order.
VerifyJobInfoOnPurchRcptLines(TempPurchaseLine);
VerifyItemLedger(TempPurchaseLine);
VerifyGLEntry(TempPurchaseLine);
VerifyValueEntries(TempPurchaseLine);
LibraryJob.VerifyPurchaseDocPostingForJob(TempPurchaseLine);
end;
[Test]
[Scope('OnPrem')]
procedure PostLCYPurchaseOrderForLCYJob()
begin
// [SCENARIO] Test integration of Jobs with posting of Purchase Order as Receive and Invoice with local currency on both Purchase Order and
// [SCENARIO] Job. Check Receipt Lines, Item Ledger Entry, Value Entry, Job Ledger Entry, Job Planning Line created.
PostJobPurchaseOrder('', '');
end;
[Test]
[Scope('OnPrem')]
procedure PostFCYPurchaseOrderForLCYJob()
begin
// [SCENARIO] Test integration of Jobs with posting of Purchase Order as Receive and Invoice with foreign currency on Purchase Order.
// [SCENARIO] Check Receipt Lines, Item Ledger Entry, G/L Entry, Value Entry, Job Ledger Entry, Job Planning Line created.
PostJobPurchaseOrder('', FindFCY());
end;
[Test]
[Scope('OnPrem')]
procedure PostLCYPurchaseOrderForFCYJob()
begin
// [SCENARIO] Test integration of Jobs with posting of Purchase Order as Receive and Invoice with foreign currency on Job.
// [SCENARIO] Check Receipt Lines, Item Ledger Entry, Value Entry, Job Ledger Entry, Job Planning Line created.
PostJobPurchaseOrder(FindFCY(), '');
end;
[Test]
[Scope('OnPrem')]
procedure PostFCYPurchaseOrderForFCYJob()
begin
// [SCENARIO] Test integration of Jobs with posting of Purchase Order as Receive and Invoice with foreign currency on both Purchase Order and
// [SCENARIO] Job. Check Receipt Lines, Item Ledger Entry, Value Entry, Job Ledger Entry, Job Planning Line created.
PostJobPurchaseOrder(FindFCY(), FindFCY());
end;
[Test]
[Scope('OnPrem')]
procedure PostLCYPurchaseOrderWithLCYJob()
begin
// [SCENARIO] Test integration of Jobs with posting of Purchase Order as Receive and Invoice with local currency on Purchase Order
// [SCENARIO] Verifying "G/L Entry","Job Ledger Entry" values
PostJobPurchaseOrderWithTypeGLAccount('', '');
end;
[Test]
[Scope('OnPrem')]
procedure PostFCYPurchaseOrderWithLCYJob()
begin
// [SCENARIO] Test integration of Jobs with posting of Purchase Order as Receive and Invoice with foreign currency on Purchase Order.
// [SCENARIO] Verifying "G/L Entry","Job Ledger Entry" values
PostJobPurchaseOrderWithTypeGLAccount('', FindFCY());
end;
[Test]
[Scope('OnPrem')]
procedure PostLCYPurchaseOrderWithrFCYJob()
begin
// [SCENARIO] Test integration of Jobs with posting of Purchase Order as Receive and Invoice with foreign currency on Job.
// [SCENARIO] Verifying "G/L Entry","Job Ledger Entry" values
PostJobPurchaseOrderWithTypeGLAccount(FindFCY(), '');
end;
[Test]
[Scope('OnPrem')]
procedure PostFCYPurchaseOrderWithFCYJob()
begin
// [SCENARIO] Test integration of Jobs with posting of Purchase Order as Receive and Invoice with foreign currency on Purchase Order and
// [SCENARIO] Verifying "G/L Entry","Job Ledger Entry" values
PostJobPurchaseOrderWithTypeGLAccount(FindFCY(), FindFCY());
end;
[Test]
[Scope('OnPrem')]
procedure PostLCYItemPurchaseOrderWithLCYJob()
begin
// [SCENARIO] Test integration of Jobs with posting of Item Purchase Order as Receive and Invoice with local currency on Purchase Order
// [SCENARIO] Verifying "G/L Entry","Job Ledger Entry" values
PostJobPurchaseOrderWithTypeItem('', '');
end;
[Test]
[Scope('OnPrem')]
procedure PostFCYItemPurchaseOrderWithLCYJob()
begin
// [SCENARIO] Test integration of Jobs with posting of Item Purchase Order as Receive and Invoice with foreign currency on Purchase Order.
// [SCENARIO] Verifying "G/L Entry","Job Ledger Entry" values
PostJobPurchaseOrderWithTypeItem('', FindFCY());
end;
[Test]
[Scope('OnPrem')]
procedure PostLCYItemPurchaseOrderWithrFCYJob()
begin
// [SCENARIO] Test integration of Jobs with posting of Item Purchase Order as Receive and Invoice with foreign currency on Job.
// [SCENARIO] Verifying "G/L Entry","Job Ledger Entry" values
PostJobPurchaseOrderWithTypeItem(FindFCY(), '');
end;
[Test]
[Scope('OnPrem')]
procedure PostFCYItemPurchaseOrderWithFCYJob()
begin
// [SCENARIO] Test integration of Jobs with posting of Item Purchase Order as Receive and Invoice with foreign currency on Purchase Order and
// [SCENARIO] Verifying "G/L Entry","Job Ledger Entry" values
PostJobPurchaseOrderWithTypeItem(FindFCY(), FindFCY());
end;
[Test]
[HandlerFunctions('ItemTrackingPageHandler,QuantityToCreatePageHandler')]
[Scope('OnPrem')]
procedure LCYJobLedgerEntryPopulatesTotalCostFromDirectUnitCost()
var
Item: Record Item;
PurchaseHeader: Record "Purchase Header";
PurchaseLine: Record "Purchase Line";
begin
// [FEATURE] [Job Ledger Entry] [Item Tracking]
// [SCENARIO 363373] Posting LCY Job Purchase Order with Serial Tracking populates Total Cost on Job Ledger Entry equal to Direct Unit Cost of appropriate Purchase Line
Initialize();
// [GIVEN] Item with Serial Tracking Code
CreateSerialTrackedItem(Item);
// [GIVEN] Job Purchase Order with Unit Cost (LCY) = "X"
CreateJobPurchaseOrderWithTracking(PurchaseHeader, PurchaseLine, Item."No.", '');
// [WHEN] Post Purchase Order as Receive and Invoice
LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, true);
// [THEN] Job Ledger Entries were created, each with Total Cost = Total Cost (LCY) = "X"
VerifyTotalCostAndPriceOnJobLedgerEntry(Item."No.", PurchaseLine."Unit Cost", PurchaseLine."Unit Cost (LCY)", PurchaseLine."Unit Price (LCY)", PurchaseLine."Unit Price (LCY)");
end;
[Test]
[HandlerFunctions('ItemTrackingPageHandler,QuantityToCreatePageHandler')]
[Scope('OnPrem')]
procedure FCYJobLedgerEntryPopulatesTotalCostFromDirectUnitCost()
var
Item: Record Item;
PurchaseHeader: Record "Purchase Header";
PurchaseLine: Record "Purchase Line";
begin
// [FEATURE] [Job Ledger Entry] [Item Tracking] [FCY]
// [SCENARIO 363373] Posting FCY Job Purchase Order with Serial Tracking populates Total Cost on Job Ledger Entry equal to Direct Unit Cost of appropriate Purchase Line
Initialize();
// [GIVEN] Item with Serial Tracking Code
CreateSerialTrackedItem(Item);
// [GIVEN] Job Purchase Order with Unit Cost = "X"
CreateJobPurchaseOrderWithTracking(PurchaseHeader, PurchaseLine, Item."No.", FindFCY());
// [WHEN] Post Purchase Order as Receive and Invoice
LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, true);
// [THEN] Job Ledger Entries were created, each with Total Cost = "X"
VerifyTotalCostAndPriceOnJobLedgerEntry(Item."No.", PurchaseLine."Unit Cost", PurchaseLine."Unit Cost (LCY)", PurchaseLine."Job Unit Price", PurchaseLine."Job Unit Price (LCY)");
end;
[Test]
[HandlerFunctions('MessageHandler')]
[Scope('OnPrem')]
procedure PurchaseOrderWithItemReserveAsAlways()
var
GeneralPostingSetup: Record "General Posting Setup";
InventorySetup: Record "Inventory Setup";
PurchaseHeader: Record "Purchase Header";
PurchaseLine: Record "Purchase Line";
PurchInvHeader: Record "Purch. Inv. Header";
GLEntry: Record "G/L Entry";
VATPostingSetup: Record "VAT Posting Setup";
DocumentNo: Code[20];
begin
// [SCENARIO] Verify GL Entry after posting a Purchase Order with Job.
Initialize();
// [GIVEN] Inventory Setup, where "Automatic Cost Adjustment" is 'Always'
InventorySetup.Get();
UpdateAutomaticCostPosting(true, InventorySetup."Automatic Cost Adjustment"::Always);
CreatePurchaseDocument(PurchaseHeader, CreateVendorWithSetup(VATPostingSetup));
GetPurchaseLines(PurchaseHeader, PurchaseLine);
GeneralPostingSetup.Get(PurchaseLine."Gen. Bus. Posting Group", PurchaseLine."Gen. Prod. Posting Group");
// [WHEN] Post Purchase Order as Receive and Invoice.
DocumentNo := LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, true);
// [THEN] Verify GL Entry.
PurchInvHeader.Get(DocumentNo);
PurchInvHeader.CalcFields("Amount Including VAT");
GLEntry.SetFilter(Amount, '>0');
FindGLEntry(GLEntry, DocumentNo, GLEntry."Document Type"::Invoice);
GLEntry.SetRange("Gen. Posting Type", GLEntry."Gen. Posting Type"::Purchase);
VerifyGLEntryAmountInclVAT(GLEntry, PurchInvHeader."Amount Including VAT");
VerifyJobOnGLEntry(PurchaseLine."Job No.", DocumentNo, GLEntry."Document Type"::Invoice);
// Tear Down.
UpdateAdjustmentAccounts(
PurchaseLine."Gen. Bus. Posting Group", PurchaseLine."Gen. Prod. Posting Group", GeneralPostingSetup."Inventory Adjmt. Account");
end;
[Test]
[HandlerFunctions('MessageHandler,PageHandler')]
[Scope('OnPrem')]
procedure PurchaseCreditMemoWithItemReserveAsAlways()
var
GLEntry: Record "G/L Entry";
GeneralPostingSetup: Record "General Posting Setup";
InventorySetup: Record "Inventory Setup";
PurchasesPayablesSetup: Record "Purchases & Payables Setup";
PurchaseHeader: Record "Purchase Header";
PurchaseLine: Record "Purchase Line";
PurchCrMemoHdr: Record "Purch. Cr. Memo Hdr.";
VATPostingSetup: Record "VAT Posting Setup";
DocumentNo: Code[20];
begin
// [SCENARIO] Verify GL Entry after posting a Purchase Credit Memo using function Return Shimpment on Credit Memo.
// Setup.
Initialize();
InventorySetup.Get();
PurchasesPayablesSetup.Get();
UpdateAutomaticCostPosting(true, InventorySetup."Automatic Cost Adjustment"::Always);
UpdateReturnShipmentOnCreditMemo(false);
CreatePurchaseDocument(PurchaseHeader, CreateVendorWithSetup(VATPostingSetup));
GetPurchaseLines(PurchaseHeader, PurchaseLine);
GeneralPostingSetup.Get(PurchaseLine."Gen. Bus. Posting Group", PurchaseLine."Gen. Prod. Posting Group");
LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, true);
CreatePurchaseHeader(PurchaseHeader."Document Type"::"Credit Memo", PurchaseHeader."Buy-from Vendor No.", PurchaseHeader);
PurchaseHeader.GetPstdDocLinesToReverse();
// [WHEN] Post Purchase Credit Memo.
DocumentNo := LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, true);
// [THEN] Verify GL Entry.
PurchCrMemoHdr.Get(DocumentNo);
PurchCrMemoHdr.CalcFields(Amount, "Amount Including VAT");
GLEntry.SetFilter(Amount, '>0');
FindGLEntry(GLEntry, DocumentNo, GLEntry."Document Type"::"Credit Memo");
VerifyGLEntryAmountInclVAT(GLEntry, PurchCrMemoHdr."Amount Including VAT");
VerifyJobOnGLEntry(PurchaseLine."Job No.", DocumentNo, GLEntry."Document Type"::"Credit Memo");
// Tear Down.
UpdateAdjustmentAccounts(
PurchaseLine."Gen. Bus. Posting Group", PurchaseLine."Gen. Prod. Posting Group", GeneralPostingSetup."Inventory Adjmt. Account");
end;
[Test]
[HandlerFunctions('ItemChargeAssignmentHandler')]
[Scope('OnPrem')]
procedure PurchaseInvoiceUsingGetReceiptLine()
var
GLEntry: Record "G/L Entry";
PurchaseHeader: Record "Purchase Header";
PurchaseLine: Record "Purchase Line";
PurchInvHeader: Record "Purch. Inv. Header";
VATPostingSetup: Record "VAT Posting Setup";
DocumentNo: Code[20];
begin
// [SCENARIO] Verify GL Entry after posting a Purchase Invoice create through Get Receipt Line function.
// [GIVEN]
Initialize();
CreatePurchaseDocument(PurchaseHeader, CreateVendorWithSetup(VATPostingSetup));
GetPurchaseLines(PurchaseHeader, PurchaseLine);
LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, false);
GetReceiptLineOnPurchaseInvoice(PurchaseHeader, PurchaseHeader."No.");
// [WHEN] Post Purchase Invoice.
DocumentNo := LibraryPurchase.PostPurchaseDocument(PurchaseHeader, false, true);
// [THEN] Verify GL Entry.
// [THEN] Verification of Item Charge Assignment Purchase has done in ItemChargeAssignmentHandler.
PurchInvHeader.Get(DocumentNo);
PurchInvHeader.CalcFields("Amount Including VAT");
GLEntry.SetFilter(Amount, '>0');
FindGLEntry(GLEntry, DocumentNo, GLEntry."Document Type"::Invoice);
GLEntry.SetRange("Gen. Posting Type", GLEntry."Gen. Posting Type"::Purchase);
VerifyGLEntryAmountInclVAT(GLEntry, PurchInvHeader."Amount Including VAT");
end;
[Test]
[Scope('OnPrem')]
procedure JobOrderReservationWithResourceShouldFail()
var
JobPlanningLine: Record "Job Planning Line";
begin
// [SCENARIO] Verify the error message while reserving the Item from Job Order to Purchase Order when Type is Resource on Job Planning Line.
// [GIVEN] Create Purchase Order and Job Plan. Update Job Planning Line with Type Resource.
Initialize();
CreatePurchaseOrderAndJobPlanningLine(JobPlanningLine, CreateItem(), LibraryRandom.RandDec(10, 2)); // Use Random for Quantity.
JobPlanningLine.Validate(Type, JobPlanningLine.Type::Resource);
JobPlanningLine.Modify(true);
// [WHEN] Reserve Item from Job Planning Line.
asserterror OpenReservationPage(JobPlanningLine."Job No.", JobPlanningLine."Job Task No.");
// [THEN] Verify error message.
Assert.ExpectedTestFieldError(JobPlanningLine.FieldCaption(Type), Format(JobPlanningLine.Type::Item));
end;
[Test]
[Scope('OnPrem')]
procedure JobOrderReservationWithoutPlanningDate()
var
JobPlanningLine: Record "Job Planning Line";
begin
// [SCENARIO] Verify the error message while reserving the Item from Job Order to Purchase Order when Planning Date is blank on Job Planning Line.
// [GIVEN] Create Purchase Order and Job Plan. Update Job Planning Line with blank Planning Date.
Initialize();
CreatePurchaseOrderAndJobPlanningLine(JobPlanningLine, CreateItem(), LibraryRandom.RandDec(10, 2)); // Use Random for Quantity.
UpdatePlanningDateOnJobPlanninglLine(JobPlanningLine, 0D);
// [WHEN] Reserve Item from Job Planning Line.
asserterror OpenReservationPage(JobPlanningLine."Job No.", JobPlanningLine."Job Task No.");
// [THEN] Verify error message.
Assert.ExpectedTestFieldError(JobPlanningLine.FieldCaption("Planning Date"), '');
end;
[Test]
[HandlerFunctions('NoQuantityOnReservePageHandler')]
[Scope('OnPrem')]
procedure JobOrderReservationWithEarlierPlanningDate()
begin
// [SCENARIO] Verify reservation lines when Planning Date is earlier than Expected Receipt Date on Job Planning Line.
Initialize();
JobOrderReservationWithPlanningDate(CreateItem(), LibraryRandom.RandDec(10, 2), -1); // Use Random for Quantity and take -1 as SignFactor.
// [THEN] Verify Reservation Line. Verification done in 'NoQuantityOnReservePageHandler'.
end;
[Test]
[HandlerFunctions('ReservationPageHandler')]
[Scope('OnPrem')]
procedure JobOrderReservationWithLaterPlanningDate()
var
ItemNumber: Code[20];
QuantityOnJobPlanningLine: Decimal;
OriginalQuantity: Decimal;
begin
// [SCENARIO] Verify reservation lines when Planning Date is later than Expected Receipt Date on Job Planning Line.
Initialize();
ItemNumber := CreateItem(); // Assign Item No. in global variable.
OriginalQuantity := LibraryRandom.RandDec(10, 2); // Assign Random Quantity in global variable.
QuantityOnJobPlanningLine := OriginalQuantity; // Assign in global variable.
EnqueueVariables(ItemNumber, QuantityOnJobPlanningLine, OriginalQuantity);
JobOrderReservationWithPlanningDate(ItemNumber, OriginalQuantity, 1); // Take 1 as SignFactor.
// [THEN] Verify Reservation Line. Verification done in 'ReservationPageHandler'.
end;
local procedure JobOrderReservationWithPlanningDate(ItemNo: Code[20]; Quantity: Decimal; SignFactor: Integer)
var
JobPlanningLine: Record "Job Planning Line";
ExpectedReceiptDate: Date;
begin
// [GIVEN] Create Purchase Order and Job Plan. Update Job Planning Line with Planning Date.
ExpectedReceiptDate := CreatePurchaseOrderAndJobPlanningLine(JobPlanningLine, ItemNo, Quantity);
UpdatePlanningDateOnJobPlanninglLine(
JobPlanningLine, CalcDate('<' + Format(SignFactor * LibraryRandom.RandInt(5)) + 'D>', ExpectedReceiptDate)); // Use Random to calculate Planning Date earlier than Expected Receipt Date.
// [WHEN] Reserve Item from Job Planning Line.
OpenReservationPage(JobPlanningLine."Job No.", JobPlanningLine."Job Task No.");
end;
[Test]
[HandlerFunctions('NoQuantityOnReservePageHandler')]
[Scope('OnPrem')]
procedure JobOrderReservationWithNegativeQuantity()
var
JobPlanningLine: Record "Job Planning Line";
begin
// [SCENARIO] Verify reservation lines when Quantity is negative on Job Planning Line.
// [GIVEN] Create Purchase Order and Job Plan. Update Job Planning Line with Random negative Quantity.
Initialize();
CreatePurchaseOrderAndJobPlanningLine(JobPlanningLine, CreateItem(), LibraryRandom.RandDec(10, 2)); // Use Random for Quantity.
UpdateJobPlanningLineQuantity(JobPlanningLine, -LibraryRandom.RandInt(10));
// [WHEN] Reserve Item from Job Planning Line.
OpenReservationPage(JobPlanningLine."Job No.", JobPlanningLine."Job Task No.");
// [THEN] Verify Reservation Line. Verification done in 'NoQuantityOnReservePageHandler'.
end;
[Test]
[HandlerFunctions('NoQuantityOnReservePageHandler')]
[Scope('OnPrem')]
procedure JobOrderReservationWithWrongLocation()
var
JobPlanningLine: Record "Job Planning Line";
begin
// [SCENARIO] Verify reservation lines when Location is different on Job Planning Line from Purchase Order.
// [GIVEN] Create Purchase Order and Job Plan. Update Job Planning Line with new Location.
Initialize();
CreatePurchaseOrderAndJobPlanningLine(JobPlanningLine, CreateItem(), LibraryRandom.RandDec(10, 2)); // Use Random for Quantity.
JobPlanningLine.Validate("Location Code", FindLocation());
JobPlanningLine.Modify(true);
// [WHEN] Reserve Item from Job Planning Line.
OpenReservationPage(JobPlanningLine."Job No.", JobPlanningLine."Job Task No.");
// [THEN] Verify Reservation Line. Verification done in 'NoQuantityOnReservePageHandler'.
end;
[Test]
[Scope('OnPrem')]
procedure PostFCYPurchaseInvoiceWithLCYJob()
var
JobTask: Record "Job Task";
PurchaseHeader: Record "Purchase Header";
PurchaseLine: Record "Purchase Line";
JobLedgerEntry: Record "Job Ledger Entry";
GLEntry: Record "G/L Entry";
Vendor: Record Vendor;
DocumentNo: Code[20];
PurchaseOrderCurrency: Code[10];
begin
// [SCENARIO] Test integration of Jobs with posting of Purchase Invoice with foreign currency on Purchase Order.
// [SCENARIO] Verifying "G/L Entry","Job Ledger Entry" values and compare then
Initialize();
// [GIVEN] created Job with local currency
PurchaseOrderCurrency := FindFCY();
CreateJobWithCurrecy(JobTask, '');
// [GIVEN] created Purchase Invoice with foreign currency
LibraryPurchase.CreateVendor(Vendor);
CreatePurchaseHeader(PurchaseHeader."Document Type"::Invoice, Vendor."No.", PurchaseHeader);
PurchaseHeader.Validate("Currency Code", PurchaseOrderCurrency);
PurchaseHeader.Modify(true);
// [GIVEN] created Purchase Invoice with GL Account
CreateGLPurchaseLine(PurchaseHeader);
// [GIVEN] update Purchase Invoice Lines with Job info
AttachJobTaskToPurchaseDoc(JobTask, PurchaseHeader);
GetPurchaseLines(PurchaseHeader, PurchaseLine);
// [WHEN] Post Purchase Invoice
DocumentNo := LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, true);
// [THEN] Verify Job Ledger Entry Amount and G/L Entry Amount should be the same
FindJobLedgerEntry(JobLedgerEntry, DocumentNo, JobTask."Job No.");
GLEntry.SetRange("G/L Account No.", PurchaseLine."No.");
FindGLEntry(GLEntry, DocumentNo, GLEntry."Document Type"::Invoice);
Assert.AreEqual(JobLedgerEntry."Total Cost (LCY)", GLEntry.Amount, 'Job Ledger Entry Total Cost and G/L Entry Amount should be equal');
end;
[Test]
[HandlerFunctions('ReserveFromCurrentLineHandler')]
[Scope('OnPrem')]
procedure ReserveItemFromJobOrderToPurchaseOrder()
var
JobPlanningLine: Record "Job Planning Line";