高章伟
2022-03-10 823b027c0decb82043c6e39f2d6ef1bb020220b1
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
@isTest
private class OrderTriggerTest {
 
    // 无特殊条件合同
    static testMethod void myTest1() {
        OrderTriggerHandler.asd();
        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        Account accIE = new Account(
            Name = '*',
            RecordTypeId = rectIE[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c='Customer IE',
            FacilityName__c='abc',
            PostCode__c='000000'
        );
        insert accIE;
 
        Contact con = new Contact();
        con.LastName = 'test';
        con.AccountId = accIE.Id;
        con.MobilePhone = 'MobilePhoneD__c';
        con.OtherPhone = 'OtherPhoneD__c';
        con.Fax = 'FaxD__c';
        con.Email = 'EmailD__c@test.com';
        con.Phone = 'PhoneD__c';
        con.Title = 'TitleD__c';
        con.Address1__c = 'Address1D__c';
        con.Address2__c = 'Address2D__c';
        con.Address3__c = 'Address3D__c';
        con.Postcode__c = '100111';
        con.ContactStatus__c = 'ContactStatusD__c';
        con.CancelReason__c = 'CancelReasonD__c';
        con.StatusD__c = 'Pass';
 
        insert con;
 
        PriceBook2 pricebook =new PriceBook2(
            Name = 'IE'
        );
        insert pricebook;
 
        List<RecordType> rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity'];
        // 有预定下单日
        Opportunity opp = new Opportunity(
            Name = 'test opp',
            AccountId = accIE.Id,
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            StageName = 'Phase3',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'IE',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            SalesChannel__c = 'direct',
            TradeType__c = 'Taxation'
        );
        insert opp;
        
        User user = new User();
        user.LastName = 'test1';
        user.FirstName = 'test2';
        user.Alias = 'test3';
        user.Email = 'test4@test.com';
        user.Username = 'test11122@test222.com';
        user.CommunityNickname = 'test22';
        user.IsActive = true;
        user.EmailEncodingKey = 'ISO-2022-JP';
        user.TimeZoneSidKey = 'Asia/Tokyo';
        user.LocaleSidKey = 'ja_JP';
        user.LanguageLocaleKey = 'ja';
        user.ProfileId = System.Label.SystemAdmin;
        insert user;
 
        OpportunityTeamMember otm1 = new OpportunityTeamMember();
        otm1.opportunityId = opp.Id;
        otm1.userId = user.Id;
        otm1.teamMemberRole = 'Sales Manager';
        insert otm1;
 
        //王鹏伟 新加 客户名和最终用户与询价对比
        OpportunityContactRole role = new OpportunityContactRole(
            Role  = 'End user',
            IsPrimary = true,
            OpportunityId = opp.Id,
            ContactId = con.Id
            );
        insert role;
 
        OrderItemTriggerHandler.tess();
 
        List<RecordType> rectOdr = [select id from RecordType where IsActive = true and SobjectType = 'Order' and Name = 'IESalesContract'];
        Order odr = new Order(
            Name = '',
            Status = 'Draft',
            AccountId = accIE.Id,
            ApproveStatus__c = 'Draft',
            OpportunityId = opp.Id,
            EffectiveDate = Date.today(),
            RecordTypeId = rectOdr[0].Id,
            SpecialDeliveryAccount__c = accIE.Id,
            SpecialDeliveryAccount_D__c = accIE.Id,
            SpecialDeliveryContact2_D__c = con.Id,
            EndUser__c = con.Id,
            EndUserD__c = con.Id
        );
        insert odr;
 
        // User user = new User();
        // user.LastName = 'test1';
        // user.FirstName = 'test2';
        // user.Alias = 'test3';
        // user.Email = 'test4@test.com';
        // user.Username = 'test11122@test222.com';
        // user.CommunityNickname = 'test22';
        // user.IsActive = true;
        // user.EmailEncodingKey = 'ISO-2022-JP';
        // user.TimeZoneSidKey = 'Asia/Tokyo';
        // user.LocaleSidKey = 'ja_JP';
        // user.LanguageLocaleKey = 'ja';
        // user.ProfileId = System.Label.SystemAdmin;
        // insert user;
 
        /*List<User> userList = [select id,SalesAsistManager__c from user where id =:UserInfo.getUserId()];
        if (userList.size() > 0) {
            userList[0].SalesAsistManager__c = user.Id;
            update userList;
        }*/
 
        List<Order> orderList = [select id, ApproveStatus__c from Order where Id = :odr.Id];
        //System.assertEquals('OrderDraft', orderList[0].ApproveStatus__c);
 
        odr.ApproveStatus__c = 'Completed';
        update odr;
        odr.ApproveStatus__c = 'Submit';
        update odr;
        odr.ApproveStatus__c = 'OrderReject';
        update odr;
 
        List<Order> orderList2 = [select id, ApproveStatus__c from Order where Id = :odr.Id];
        System.assertEquals('OrderReject', orderList2[0].ApproveStatus__c);
 
        odr.ApproveStatus__c = 'Completed';
        update odr;
        odr.ApproveStatus__c = 'Submit';
        update odr;
        odr.ApproveStatus__c = 'OrderPass';
        update odr;
 
        List<Order> orderList3 = [select id, ApproveStatus__c from Order where Id = :odr.Id];
        System.assertEquals('OrderPass', orderList3[0].ApproveStatus__c);
    }
 
    // 有特殊条件合同
    static testMethod void myTest2() {
        OrderTriggerHandler.asd();
        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        Account accIE = new Account(
            Name = '*',
            RecordTypeId = rectIE[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c='Customer IE',
            FacilityName__c='abc',
            PostCode__c='000000'
        );
        insert accIE;
 
        Contact con = new Contact();
        con.LastName = 'test';
        con.AccountId = accIE.Id;
        con.MobilePhone = 'MobilePhoneD__c';
        con.OtherPhone = 'OtherPhoneD__c';
        con.Fax = 'FaxD__c';
        con.Email = 'EmailD__c@test.com';
        con.Phone = 'PhoneD__c';
        con.Title = 'TitleD__c';
        con.Address1__c = 'Address1D__c';
        con.Address2__c = 'Address2D__c';
        con.Address3__c = 'Address3D__c';
        con.Postcode__c = '100111';
        con.ContactStatus__c = 'ContactStatusD__c';
        con.CancelReason__c = 'CancelReasonD__c';
        con.StatusD__c = 'Pass';
 
        insert con;
 
        PriceBook2 pricebook =new PriceBook2(
            Name = 'IE'
        );
        insert pricebook;
 
        List<RecordType> rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity'];
        // 有预定下单日
        Opportunity opp = new Opportunity(
            Name = 'test opp',
            AccountId = accIE.Id,
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            StageName = 'Phase3',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'IE',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            SalesChannel__c = 'direct',
            TradeType__c = 'Taxation'
        );
        insert opp;
 
        //王鹏伟 新加 客户名和最终用户与询价对比
        OpportunityContactRole role = new OpportunityContactRole(
            Role  = 'End user',
            IsPrimary = true,
            OpportunityId = opp.Id,
            ContactId = con.Id
            );
        insert role;
 
        Order odr = new Order(
            Name = '',
            Status = 'Draft',
            AccountId = accIE.Id,
            ApproveStatus__c = 'Draft',
            OpportunityId = opp.Id,
            EffectiveDate = Date.today(),
            IE_SP5_D__c = true,
            IE_SP8__c = true,
            SpecialDeliveryAccount_D__c = accIE.Id,
            SpecialDeliveryContact2_D__c = con.Id,
            EndUser__c = con.Id,
            EndUserD__c = con.Id
        );
        insert odr;
        List<Order> orderList = [select id, ApproveStatus__c,ProductSegment__c,Status__c,IE_SP5_D__c,IE_SP6_D__c,IE_SP7_D__c,IE_SP8_D__c from Order where Id = :odr.Id];
        System.debug('orderList--->'+orderList);
        // System.assertEquals('Draft', orderList[0].ApproveStatus__c);
 
        odr.ApproveStatus__c = 'Completed';
        update odr;
        odr.ApproveStatus__c = 'Submit';
        update odr;
        odr.ApproveStatus__c = 'Pass';
        update odr;
 
        List<Order> orderList2 = [select id, ApproveStatus__c from Order where Id = :odr.Id];
        System.assertEquals('Pass', orderList2[0].ApproveStatus__c);
 
        odr.ApproveStatus__c = 'Completed2';
        update odr;
        odr.ApproveStatus__c = 'OrderSubmit';
        update odr;
        odr.ApproveStatus__c = 'OrderPass';
        update odr;
 
        List<Order> orderList3 = [select id, ApproveStatus__c from Order where Id = :odr.Id];
        System.assertEquals('OrderPass', orderList3[0].ApproveStatus__c);
 
        odr.ApproveStatus__c = 'Completed2';
        update odr;
        odr.ApproveStatus__c = 'OrderSubmit';
        update odr;
        odr.ApproveStatus__c = 'OrderReject';
        update odr;
 
        List<Order> orderList4 = [select id, ApproveStatus__c from Order where Id = :odr.Id];
        System.assertEquals('OrderReject', orderList4[0].ApproveStatus__c);
    }
 
    //
    static testMethod void myTest3() {
        OrderTriggerHandler.asd();
        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        Account accIE = new Account(
            Name = '*',
            RecordTypeId = rectIE[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c='Customer IE',
            FacilityName__c='abc',
            PostCode__c='000000'
        );
        insert accIE; 
 
        Contact con = new Contact();
        con.LastName = 'test';
        con.AccountId = accIE.Id;
        con.MobilePhone = 'MobilePhoneD__c';
        con.OtherPhone = 'OtherPhoneD__c';
        con.Fax = 'FaxD__c';
        con.Email = 'EmailD__c@test.com';
        con.Phone = 'PhoneD__c';
        con.Title = 'TitleD__c';
        con.Address1__c = 'Address1D__c';
        con.Address2__c = 'Address2D__c';
        con.Address3__c = 'Address3D__c';
        con.Postcode__c = '100111';
        con.ContactStatus__c = 'ContactStatusD__c';
        con.CancelReason__c = 'CancelReasonD__c';
        con.StatusD__c = 'Pass';
 
        insert con;
 
        PriceBook2 pricebook =new PriceBook2(
            Name = 'IE'
        );
        insert pricebook;
 
        List<RecordType> rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity'];
        // 有预定下单日
        Opportunity opp = new Opportunity(
            Name = 'test opp',
            AccountId = accIE.Id,
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            StageName = 'Phase3',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'IE',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            SalesChannel__c = 'direct',
            TradeType__c = 'Taxation',
            compo_opp__c = false
        );
        insert opp;
        //王鹏伟 新加 客户名和最终用户与询价对比
        OpportunityContactRole role = new OpportunityContactRole(
            Role  = 'End user',
            IsPrimary = true,
            OpportunityId = opp.Id,
            ContactId = con.Id
            );
        insert role;
 
        Order odr = new Order(
            Name = '',
            Status = 'Draft',
            AccountId = accIE.Id,
            ApproveStatus__c = 'Draft',
            OpportunityId = opp.Id,
            EffectiveDate = Date.today(),
            SpecialDeliveryAccount_D__c = accIE.Id,
            SpecialDeliveryContact2_D__c = con.Id,
            EndUser__c = con.Id,
            EndUserD__c = con.Id
        );
        insert odr;
 
        odr.SP_11__c = true;
        odr.SP_102__c = true;
        odr.SP_103__c = true;
        odr.SP_106__c = true;
        odr.SP_111__c = true;
        odr.SP_121__c = true;
        odr.SP_131__c = true;
        odr.SP_141__c = true;
        odr.SP_151__c = true;
        odr.SP_161__c = true;
        odr.SP_171__c = true;
        odr.SP_181__c = true;
        odr.SP_191__c = true;
        odr.SP_202__c = true;
        odr.SP_21__c = true;
        odr.SP_22__c = false;
        odr.SP_31__c = true;
        odr.SP_32__c = false;
        odr.SP_33__c = false;
        odr.SP_41__c = true;
        odr.SP_51__c = true;
        odr.SP_52__c = true;
        odr.SP_62__c = true;
        odr.SP_71__c = true;
        odr.SP_81__c = true;
        odr.SP_91__c = true;
 
        odr.IE_SP1__c = true;
        odr.IE_SP2__c = true;
        odr.IE_SP3__c = true;
        odr.IE_SP4__c = false;
        odr.IE_SP5__c = true;
        odr.IE_SP6__c = true;
        odr.IE_SP7__c = true;
 
        odr.RVI_SP1__c = true;
        odr.RVI_SP2__c = false;
        odr.RVI_SP3__c = true;
        odr.RVI_SP4__c = true;
        odr.RVI_SP5__c = true;
        odr.RVI_SP6__c = true;
 
        odr.NDT_SP1__c = true;
        odr.NDT_SP2__c = true;
        odr.NDT_SP3__c = true;
        odr.NDT_SP4__c = true;
        odr.NDT_SP5__c = true;
        odr.NDT_SP6__c = true;
        odr.NDT_SP7__c = true;
        odr.NDT_SP8__c = true;
        odr.NDT_SP9__c = true;
        odr.NDT_SP10__c = true;
        odr.NDT_SP11__c = true;
 
        odr.ANI_SP1__c = true;
        odr.ANI_SP2__c = true;
        odr.ANI_SP3__c = true;
        odr.ANI_SP4__c = true;
        odr.ANI_SP5__c = true;
        odr.ANI_SP6__c = true;
 
        odr.NormalDis_SerContractCondition__c = true;
        odr.HighDis_SerContractCondition__c = false;
        odr.SpecialDis_SerContractCondition__c = false;
        odr.Warranty_SerContractCondition__c = true;
 
        odr.Discount__c = 0.5;
        odr.Olympus_Price_BeforeDiscount__c = 2000;
        odr.PaymentCondition__c = 'PaymentCondition__c';
        odr.SpecialDelivery__c = 'SpecialDelivery__c';
        odr.SpecialDeliveryContact__c = 'SpecialDeliveryContact__c';
        odr.SpecialDeliveryPhone__c = '11223344';
        odr.SpecialDeliveryAddress__c = 'SpecialDeliveryAddress__c';
        odr.SpecialParkage__c = 'SpecialParkage__c';
        odr.SpecialWarranty__c = 'SpecialWarranty__c';
        odr.DealerProfit__c = 0.4;
        odr.SpecialDelDate__c = Date.today().addDays(1);
        odr.OtherApply__c = 'OtherApply__c';
 
        odr.CustomerContractPrice__c = 2000;
        odr.OlympusContractPrices__c = 1000;
        odr.EndUser__c = con.Id;
 
        odr.Andor__c = true;
        odr.Bitplane__c = true;
        odr.CoolLED__c = true;
        odr.Lumen__c = true;
        odr.Lumenera__c = true;
        odr.Media_Cybernetics__c = true;
        odr.Narishige__c = true;
        odr.Newport__c = true;
        odr.OSIS_Germany__c = true;
        odr.OSIS_Singapore__c = true;
        odr.Photometrics__c = true;
        odr.Prior_Scientific__c = true;
        odr.Q_Imaging__c = true;
        odr.Tokai_Hit__c = true;
        odr.Other_Third__c = true;
        odr.ServiceFee__c = 500;
        odr.AlongProduct__c = '是';
        odr.Cost__c = 500;
        odr.Sub_DealerC__c = '9878971';
        odr.Shipment_Term__c = 'CIP';
 
        odr.Contract_Status__c = 'Active';
 
        update odr;
    }
 
    static testMethod void myTest4() {
        OrderTriggerHandler.asd();
        List<RecordType> rectBS = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer BS'];
        //List<RecordType> rectDealer = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Dealer'];
        //List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
 
        //Account buyer = new Account(
        //    Name = '*',
        //    FacilityName__c = 'buyer',
        //    PostCode__c = '123456',
        //    DivisionName__c='Dealer',
        //    OwnerId = UserInfo.getUserId(),
        //    RecordTypeId = rectDealer[0].Id,
        //    ProductSegment__c = 'BS',
        //    ManagementCode_Ext__c = 'P11111'
        //    //ProductSegment__c = 'BS'
        //);
        //Account delivery = new Account(
        //    Name = '*',
        //    FacilityName__c = 'delivery',
        //    PostCode__c = '123456'
        //);
        //Account user = new Account(
        //    Name = '*',
        //    FacilityName__c = 'user',
        //    PostCode__c = '123456',
        //    RecordTypeId = rectIE[0].Id
        //);
        //insert new List<Account> {buyer, delivery, user};
        List<RecordType> rectDealer = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Dealer'];
 
        Account dealerParent = new Account();
        dealerParent.Name = 'test dealer';
        dealerParent.RecordTypeId = rectDealer[0].Id;
        dealerParent.ProductSegment__c = 'BS';
        dealerParent.PostCode__c='000000';
        dealerParent.ManagementCode_Ext__c = 'P11111';
        insert dealerParent;
 
        Account dealer1 = new Account();
        dealer1.Name = 'test dealer';
        dealer1.RecordTypeId = rectDealer[0].Id;
        dealer1.ProductSegment__c = 'BS';
        dealer1.PostCode__c='000000';
        dealer1.ManagementCode_Ext__c = 'C22222';
        dealer1.ParentId = dealerParent.Id;
        insert dealer1;
 
        Account dealer2 = new Account();
        dealer2.Name = 'test dealer';
        dealer2.RecordTypeId = rectDealer[0].Id;
        dealer2.ProductSegment__c = 'BS';
        dealer2.PostCode__c='000000';
        dealer2.ManagementCode_Ext__c = 'C33333';
        dealer2.ParentId = dealerParent.Id;
        insert dealer2;
 
        Account accBS = new Account(
            Name = '*',
            RecordTypeId = rectBS[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c='Customer BS',
            FacilityName__c='abc',
            PostCode__c='000000'
        );
        insert accBS;
 
        Contact con = new Contact();
        con.LastName = 'test';
        con.AccountId = accBS.Id;
        con.MobilePhone = 'MobilePhoneD__c';
        con.OtherPhone = 'OtherPhoneD__c';
        con.Fax = 'FaxD__c';
        con.Email = 'EmailD__c@test.com';
        con.Phone = 'PhoneD__c';
        con.Title = 'TitleD__c';
        con.Address1__c = 'Address1D__c';
        con.Address2__c = 'Address2D__c';
        con.Address3__c = 'Address3D__c';
        con.Postcode__c = '100111';
        con.ContactStatus__c = 'ContactStatusD__c';
        con.CancelReason__c = 'CancelReasonD__c';
        con.StatusD__c = 'Pass';
 
        insert con;
 
        Id pricebookId = Test.getStandardPricebookId();
 
        Pricebook2 pricebook = new Pricebook2(
            Name = 'BS',
            ProductSegment__c = 'BS',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine',
            isActive = true
        );
        insert pricebook;
 
        Product2 product1 = new Product2();
        product1.Name = 'product1';
        product1.ProductCode = 'product1';
        product1.Product_ECCode__c = 'product1';
        product1.IsActive = true;
        insert product1;
 
        PricebookEntry standardPrice1 = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = product1.Id,
            UnitPrice = 0,
            IsActive = true
        );
        insert standardPrice1;
 
        PricebookEntry entry1 = new PricebookEntry(Pricebook2Id = pricebook.Id, Product2Id = product1.Id);
        entry1.UnitPrice = 0;
        entry1.IsActive = true;
        entry1.UseStandardPrice = false;
        insert entry1;
 
        List<RecordType> rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity'];
        // 有预定下单日
        Opportunity opp = new Opportunity(
            Name = 'test opp',
            AccountId = accBS.Id,
            useing__c = 'OEM',
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            StageName = 'Phase3',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'BS',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            SalesChannel__c = 'direct',
            TradeType__c = 'Taxation',
            Dealer__c = dealer1.Id,
            Machine_Parts__c = 'Machine',
            InquiryResult__c = '112233'
        );
        insert opp;
 
        //王鹏伟 新加 客户名和最终用户与询价对比
        OpportunityContactRole role = new OpportunityContactRole(
            Role  = 'End user',
            IsPrimary = true,
            OpportunityId = opp.Id,
            ContactId = con.Id
            );
        insert role;
 
        Order odr = new Order(
            Name = '',
            Status = 'Draft',
            AccountId = accBS.Id,
            ApproveStatus__c = 'Draft',
            OpportunityId = opp.Id,
            EffectiveDate = Date.today(),
            IE_SP5_D__c = true,
            SP_61D__c = true,
            SpecialDeliveryAccount_D__c = accBS.Id,
            SpecialDeliveryContact2_D__c = con.Id,
            EndUser__c = con.Id,
            EndUserD__c = con.Id
        );
        insert odr;
 
        OrderItem oi1 = new OrderItem(
            OrderId = odr.Id,
            PriceBookEntryId = entry1.Id,
            Quantity = 1,
            UnitPrice = 10
        );
        insert oi1;
 
        /*Opportunity opp1 = [select id,Order_Date__c,DeliveryDate__c from Opportunity where Id = :opp.Id];
        System.assertEquals(null, opp1.Order_Date__c);
        System.assertEquals(null, opp1.DeliveryDate__c);
 
        odr.OrderDate__c = Date.today();
        update odr;*/
 
        Delivery__c delivery1 = new Delivery__c(
            SSBD_Contract__c = odr.Id,
            Delivery_Date__c = Date.today().addDays(-1),
            Delivery_Status__c = '未发货'
        );
        insert delivery1;
 
        Opportunity opp2 = [select id,Order_Date__c,DeliveryDate__c from Opportunity where Id = :opp.Id];
        //System.assertEquals(Date.today(), opp2.Order_Date__c);
        System.assertEquals(null, opp2.DeliveryDate__c);
 
        Delivery__c delivery2 = new Delivery__c(
            SSBD_Contract__c = odr.Id,
            Delivery_Date__c = Date.today(),
            Delivery_Status__c = '部分发货'
        );
        insert delivery2;
 
        Opportunity opp3 = [select id,Order_Date__c,DeliveryDate__c from Opportunity where Id = :opp.Id];
        System.assertEquals(null, opp3.DeliveryDate__c);
 
        Delivery__c delivery3 = new Delivery__c(
            SSBD_Contract__c = odr.Id,
            Delivery_Date__c = Date.today().addDays(1),
            Delivery_Status__c = '全部发货'
        );
        insert delivery3;
 
        /*Opportunity opp4 = [select id,Order_Date__c,DeliveryDate__c from Opportunity where Id = :opp.Id];
        //System.assertEquals(Date.today().addDays(1), opp4.DeliveryDate__c);
 
        odr.RecordTypeId = System.Label.RT_Contract_BS_Tax_Approval;
        update odr;*/
    }
    static testMethod void myTest5(){
        OrderTriggerHandler.asd();
        Id pricebookId = Test.getStandardPricebookId();
 
        Pricebook2 pricebook = new Pricebook2(
            Name = 'ANI',
            ProductSegment__c = 'ANI',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine',
            isActive = true
        );
        insert pricebook;
 
        Product2 product1 = new Product2();
        product1.Name = 'product1';
        product1.ProductCode = 'product1';
        product1.Product_ECCode__c = 'product1';
        product1.IsActive = true;
        insert product1;
 
        PricebookEntry standardPrice1 = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = product1.Id,
            UnitPrice = 0,
            IsActive = true
        );
        insert standardPrice1;
 
        PricebookEntry entry1 = new PricebookEntry(Pricebook2Id = pricebook.Id, Product2Id = product1.Id);
        entry1.UnitPrice = 0;
        entry1.IsActive = true;
        entry1.UseStandardPrice = false;
        insert entry1;
 
        List<RecordType> rectANI = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer ANI'];
        Account user = new Account(
            Name = '*',
            FacilityName__c = 'user',
            PostCode__c = '123456',
            RecordTypeId = rectANI[0].Id
        );
        insert user;
 
        Contact contact = new Contact(
            LastName = 'contact',
            AccountId = user.Id
        );
        insert contact;
 
        Opportunity opp = new Opportunity(
            Name = 'test opp',
            AccountId = user.Id,
            StageName = 'Phase3',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'ANI',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            Machine_Parts__c = 'Machine',
            Pricebook2Id = pricebook.Id
        );
        insert opp;
 
         //王鹏伟 新加 客户名和最终用户与询价对比
        OpportunityContactRole role = new OpportunityContactRole(
            Role  = 'End user',
            IsPrimary = true,
            OpportunityId = opp.Id,
            ContactId = contact.Id
            );
        insert role;
 
        OpportunityLineItem oli1 = new OpportunityLineItem(
            OpportunityId = opp.Id,
            PricebookEntryId = entry1.Id,
            Quantity = 10,
            UnitPrice = 10
        );
        OpportunityLineItem oli2 = new OpportunityLineItem(
            OpportunityId = opp.Id,
            PricebookEntryId = entry1.Id,
            Quantity = 20,
            UnitPrice = 20
        );
        insert new OpportunityLineItem[] {oli1, oli2};
 
        OpportunityContactRole ocr = new OpportunityContactRole(
            OpportunityId = opp.Id,
            ContactId = contact.Id,
            IsPrimary = true
        );
        insert ocr;
 
        Quote quo = new Quote(
            Name = 'quo',
            OpportunityId = opp.Id,
            Pricebook2Id = pricebook.Id,
            SetName1__c = 'setname01',
            SetQty1__c = 1
        );
        insert quo;
 
        QuoteLineItem qli1 = new QuoteLineItem(
            QuoteId = quo.Id,
            PricebookEntryId = entry1.Id,
            Quantity = 10,
            UnitPrice = 10,
            Custom_Price__c = 15,
            Set__c = 'set01'
        );
        QuoteLineItem qli2 = new QuoteLineItem(
            QuoteId = quo.Id,
            PricebookEntryId = entry1.Id,
            Quantity = 20,
            UnitPrice = 20,
            Custom_Price__c = 25,
            Set__c = 'set01'
        );
        insert new QuoteLineItem[] {qli1, qli2};
 
        opp.SyncedQuoteId = quo.Id;
        update opp;
 
        Order order = new Order(
            Name = 'order',
            CurrencyIsoCode = 'CNY',
            AccountId = user.Id,
            OpportunityId = opp.Id,
            QuoteId = quo.Id,
            EffectiveDate = Date.today(),
            Status = 'Draft',
            Pricebook2Id = pricebook.Id,
            EndUser__c = contact.Id,
            EndUserD__c = contact.Id
        );
        insert order;
    }
}