buli
2022-04-26 5835379ec30b1667c4e522db9d294c9b7bb8633a
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
/**
 * @description       : 
 * @author            : ChangeMeIn@UserSettingsUnder.SFDoc
 * @group             : 
 * @last modified on  : 04-21-2022
 * @last modified by  : ChangeMeIn@UserSettingsUnder.SFDoc
**/
@isTest
private class OpportunityTriggerTest {
    
    // 关闭询价插入和更新
    static testMethod void myTest1() {
        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 = '123456'
        );
        insert accIE; 
        
        PriceBook2 pricebook =new PriceBook2(
            Name = 'IE',
            ProductSegment__c = 'IE',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine'
        );
        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 = 'Prospect Created',
            CancelReason__c = 'Inquiry repeat',
            Cancel_reason_D__c = 'Inquiry repeat',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'IE',
            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'
        );
        insert opp;
 
        OpportunityWebService.UpdateStageName(opp.Id, 'Closed Cancel');
        update opp;
        
        List<Opportunity> oppList = [Select Id, CloseDate, ProductSegmentCompetitor__c, Pricebook2Id from Opportunity where Id = :opp.Id];
        
        //System.assertEquals(Date.today().addDays(2), oppList[0].CloseDate);
        //System.assertEquals('IE', oppList[0].ProductSegmentCompetitor__c);
        //System.assertEquals(pricebook.Id, oppList[0].Pricebook2Id);
        
    }
    
    // 未关闭询价插入和更新
    static testMethod void myTest2() {
        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 = '123456'
        );
        insert accIE; 
        
        PriceBook2 pricebook =new PriceBook2(
            Name = 'IE',
            ProductSegment__c = 'IE',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine'
        );
        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 = 'Prospect Created',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'IE',
            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'
        );
        insert opp;
        
        List<Opportunity> oppList = [Select Id, CloseDate, ProductSegmentCompetitor__c, Pricebook2Id from Opportunity where Id = :opp.Id];
        
        //System.assertEquals(Date.today().addDays(2), oppList[0].CloseDate);
        //System.assertEquals('IE', oppList[0].ProductSegmentCompetitor__c);
        //System.assertEquals(pricebook.Id, oppList[0].Pricebook2Id);
        
        opp.ExpectedOrderDate__c = Date.today().addDays(3);
        opp.ProductSegment__c = 'BS';
        update opp;
        
        List<Opportunity> oppList2 = [Select Id, CloseDate, ProductSegmentCompetitor__c, Pricebook2Id from Opportunity where Id = :opp.Id];
        
        //System.assertEquals(Date.today().addDays(3), oppList2[0].CloseDate);
        //System.assertEquals('BS', oppList2[0].ProductSegmentCompetitor__c);
        
        // 无预定下单日
        Opportunity opp2 = new Opportunity(
            Name = 'test opp',
            AccountId = accIE.Id,
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            StageName = 'Prospect Created',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'IE',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            Machine_Parts__c = 'Machine'
        );
        insert opp2;
        
        List<Opportunity> oppList3 = [Select Id, CloseDate, ProductSegmentCompetitor__c, Pricebook2Id from Opportunity where Id = :opp2.Id];
        
        //System.assertEquals(Date.today().addDays(-2).addMonths(6), oppList3[0].CloseDate);
        //System.assertEquals('IE', oppList3[0].ProductSegmentCompetitor__c);
        //System.assertEquals(pricebook.Id, oppList3[0].Pricebook2Id);
        
        opp2.NewInquiryDate__c = Date.today().addDays(-3);
        opp2.ProductSegment__c = 'BS';
        update opp2;
        
        List<Opportunity> oppList4 = [Select Id, CloseDate, ProductSegmentCompetitor__c, Pricebook2Id from Opportunity where Id = :opp2.Id];
        
        //System.assertEquals(Date.today().addDays(-3).addMonths(6), oppList4[0].CloseDate);
        //System.assertEquals('BS', oppList4[0].ProductSegmentCompetitor__c);
    }
    //@isTest(SeeAllData=true)
    static testMethod void myTest3() {
        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        List<RecordType> rectForeignCompany = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'ForeignCompany'];
        Id pricebookId = Test.getStandardPricebookId();
        
        /*PriceBook2 pricebook1 = ControllerUtil.getStandardPricebook();
        Id pricebookId = pricebook1.id;*/
        Pricebook2 pricebook = new Pricebook2(
            Name = 'IE',
            ProductSegment__c = 'IE',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine',
            isActive = true
        );
        insert pricebook;
        
        /*Pricebook2 pricebook =  [select Id from PriceBook2 where ProductSegment__c = 'IE' and
         TradeType__c = 'Taxation' and SalesChannel__c = 'direct' and MachineParts__c = 'Machine' and  isActive = true limit 1];
*/
        Product2 product1 = new Product2();
        product1.Name = 'product1';
        product1.IsActive = true;
        
        Product2 product2 = new Product2();
        product2.Name = 'product2';
        product2.IsActive = true;
        
        Product2 product3 = new Product2();
        product3.Name = 'product3';
        product3.IsActive = true;
        
        insert new Product2[] {product1,product2,product3};
        
        PricebookEntry standardPrice1 = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = product1.Id,
            UnitPrice = 0,
            CurrencyIsoCode = 'CNY',
            IsActive = true
 
        );
        
        PricebookEntry standardPrice2 = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = product2.Id,
            UnitPrice = 0,
            CurrencyIsoCode = 'CNY',
            IsActive = true
        );
        
        PricebookEntry standardPrice3 = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = product3.Id,
            UnitPrice = 0,
            CurrencyIsoCode = 'CNY',
            IsActive = true
        );
        
        insert new PricebookEntry[] {standardPrice1,standardPrice2,standardPrice3};
        
        PricebookEntry entry1 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product1.Id);
        entry1.UnitPrice = 0;
        entry1.IsActive = true;
        entry1.UseStandardPrice = false;
        entry1.CurrencyIsoCode = 'CNY';
        
        PricebookEntry entry2 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product2.Id);
        entry2.UnitPrice = 0;
        entry2.IsActive = true;
        entry2.UseStandardPrice = false;
        entry2.CurrencyIsoCode = 'CNY';
        
        PricebookEntry entry3 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product3.Id);
        entry3.UnitPrice = 0;
        entry3.IsActive = true;
        entry3.UseStandardPrice = false;
        entry3.CurrencyIsoCode = 'CNY';
 
        
        insert new PricebookEntry[] {entry1,entry2,entry3};
        
        Account accIE = new Account(
            Name = '*',
            RecordTypeId = rectIE[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c='Customer IE',
            FacilityName__c='abc',
            PostCode__c = '123456'
        );
        insert accIE; 
        
        Account specialDeliveryAddress1 = new Account(Name = '*',FacilityName__c='specialDeliveryAddress1',PostCode__c = '123456');
        Account specialDeliveryAddress2 = new Account(Name = '*',FacilityName__c='specialDeliveryAddress2',PostCode__c = '123456');
        Account specialDeliveryAddress3 = new Account(Name = '*',FacilityName__c='specialDeliveryAddress3',PostCode__c = '123456');
        Account foreignTradeCompany1 = new Account(Name = '*',FacilityName__c='foreignTradeCompany1',PostCode__c = '123456',RecordTypeId = rectForeignCompany[0].Id);
        Account foreignTradeCompany2 = new Account(Name = '*',FacilityName__c='foreignTradeCompany2',PostCode__c = '123456',RecordTypeId = rectForeignCompany[0].Id);
        Account foreignTradeCompany3 = new Account(Name = '*',FacilityName__c='foreignTradeCompany3',PostCode__c = '123456',RecordTypeId = rectForeignCompany[0].Id);
        insert new Account[] {specialDeliveryAddress1,specialDeliveryAddress2,specialDeliveryAddress3,foreignTradeCompany1,foreignTradeCompany2,foreignTradeCompany3};
        
        User user = new User();
        user.LastName = 'test';
        user.FirstName = 'test';
        user.Alias = 'test';
        user.Email = 'User20210519@test.com';
        user.Username = 'User20210519@test222.com';
        user.CommunityNickname = 'test01';
        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;
        
        Date day1 = Date.today();
        Date day2 = day1.addDays(-1);
        List<RecordType> rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity'];
        // 有预定下单日
        Opportunity opp = new Opportunity();
        opp.Name = 'test opp';
        opp.AccountId = accIE.Id;
        opp.RecordTypeId = rectOpp[0].Id;
        opp.OwnerId = UserInfo.getUserId();
        opp.StageName = 'Prospect Created';
        opp.CurrencyIsoCode = 'CNY';
        opp.ProductSegment__c = 'IE';
        opp.CloseDate = Date.today();
        opp.NewInquiryDate__c = Date.today().addDays(-2);
        opp.ExpectedOrderDate__c = Date.today().addDays(2);
        opp.ApprovalStatus_D__c = 'Pass';
        
        opp.LeadSource = 'LeadSource_D__c';
        opp.BudgetAmount__c = 111;
        opp.CancelReasonText__c = 'Cancel_Reason_Text_D__c';
        opp.CancelReason__c = 'Cancel_reason_D__c';
        opp.CompetitorCompany__c = 'Competitor_Company_D__c';
        opp.Competitor_Product__c = 'Competitor_Product_D__c';
        opp.Competitor_Product2__c = 'Competitor_Product2_D__c';
        opp.Competitor_Product3__c = 'Competitor_Product3_D__c';
        opp.Competitor_Product4__c = 'Competitor_Product4_D__c';
        opp.Competitor_Product5__c = 'Competitor_Product5_D__c';
        opp.Competitor_Product6__c = 'Competitor_Product6_D__c';
        opp.Competitor_Product7__c = 'Competitor_Product7_D__c';
        opp.Competitor_Product8__c = 'Competitor_Product8_D__c';
        opp.CompetitorProductCode__c = 'Competitor_Product_Code_D__c';
        opp.CompetitorProductCode2__c = 'Competitor_Product_Code2_D__c';
        opp.CompetitorProductCode3__c = 'Competitor_Product_Code3_D__c';
        opp.CompetitorProductCode4__c = 'Competitor_Product_Code4_D__c';
        opp.CompetitorProductCode5__c = 'Competitor_Product_Code5_D__c';
        opp.CompetitorProductCode6__c = 'Competitor_Product_Code6_D__c';
        opp.CompetitorProductCode7__c = 'Competitor_Product_Code7_D__c';
        opp.CompetitorProductCode8__c = 'Competitor_Product_Code8_D__c';
        opp.DealerSalesStaffName__c = 'Dealer_Sales_Staff_Name_D__c';
        opp.DealerService__c = 'Dealer_Service_D__c';
        opp.ExpectedDeliveryDate__c = day1;
        opp.InquiryResult__c = 'InquiryResultD__c';
        //opp.InquiryResultCancel__c = day1;
        //opp.InquiryResultLost__c = day1;
        opp.InquiryResultOrder__c = day1;
        opp.LostAmount__c = 111;
        opp.LostCompetitorProduct__c = 'Lost_competitor_product_D__c';
        opp.LostReasonText__c = 'LostReasonText_D__c';
        opp.LostReason__c = 'Lostreason_D__c';
        opp.Phase1Date__c = day1;
        opp.Phase2Date__c = day1;
        opp.Phase3Date__c = day1;
        opp.SalesChannel__c = 'direct';
        opp.SubDealer__c = 'Sub_Dealer_D__c';
        opp.TradeType__c = 'Taxation';
        opp.Machine_Parts__c = 'Machine';
        opp.SpecialDeliveryAddress__c = specialDeliveryAddress1.Id;
        opp.ForeignTradeCompany__c = foreignTradeCompany1.Id;
  
        insert opp;
        
        OpportunityLineItem oli = new OpportunityLineItem();
        oli.OpportunityId = opp.Id;
        oli.Quantity = 2;
        oli.UnitPrice = 111;
        oli.Description = 'test';
        oli.PricebookEntryId = entry1.Id;
        
        insert oli;
        
        opp.LeadSource = 'LeadSource';
        opp.BudgetAmount__c = 222;
        opp.CancelReasonText__c = 'CancelReasonText__c';
        opp.CancelReason__c = 'CancelReason__c';
        opp.CompetitorCompany__c = 'CompetitorCompany__c';
        opp.Competitor_Product__c = 'Competitor_Product__c';
        opp.Competitor_Product2__c = 'Competitor_Product2__c';
        opp.Competitor_Product3__c = 'Competitor_Product3__c';
        opp.Competitor_Product4__c = 'Competitor_Product4__c';
        opp.Competitor_Product5__c = 'Competitor_Product5__c';
        opp.Competitor_Product6__c = 'Competitor_Product6__c';
        opp.Competitor_Product7__c = 'Competitor_Product7__c';
        opp.Competitor_Product8__c = 'Competitor_Product8__c';
        opp.CompetitorProductCode__c = 'CompetitorProductCode__c';
        opp.CompetitorProductCode2__c = 'CompetitorProductCode2__c';
        opp.CompetitorProductCode3__c = 'CompetitorProductCode3__c';
        opp.CompetitorProductCode4__c = 'CompetitorProductCode4__c';
        opp.CompetitorProductCode5__c = 'CompetitorProductCode5__c';
        opp.CompetitorProductCode6__c = 'CompetitorProductCode6__c';
        opp.CompetitorProductCode7__c = 'CompetitorProductCode7__c';
        opp.CompetitorProductCode8__c = 'CompetitorProductCode8__c';
        opp.DealerSalesStaffName__c = 'DealerSalesStaffName__c';
        opp.DealerService__c = 'DealerService__c';
        opp.ExpectedDeliveryDate__c = day2;
        opp.ExpectedOrderDate__c = day2;
        opp.InquiryResult__c = 'InquiryResult__c';
        opp.InquiryResultCancel__c = null;
        opp.InquiryResultLost__c = null;
        opp.InquiryResultOrder__c = null;
        opp.LostAmount__c = 222;
        opp.LostCompetitorProduct__c = 'LostCompetitorProduct__c';
        opp.LostReasonText__c = 'LostReasonText__c';
        opp.LostReason__c = 'LostReason__c';
        opp.NewInquiryDate__c = day2;
        opp.Phase1Date__c = day2;
        opp.Phase2Date__c = day2;
        opp.Phase3Date__c = day2;
        opp.SalesChannel__c = 'direct';
        opp.SubDealer__c = 'SubDealer__c';
        opp.TradeType__c = 'Taxation';
        opp.Machine_Parts__c = 'Machine';
        opp.SpecialDeliveryAddress__c = specialDeliveryAddress2.Id;
        opp.ForeignTradeCompany__c = foreignTradeCompany2.Id;
        
        
        opp.OwnerId = user.Id;
        
        update opp;
        
        oli.Quantity = 3;
        oli.UnitPrice = 222;
        oli.Description = 'test1';
        
        update oli;
        
        opp.LeadSource_D__c = 'newOpp.LeadSource';
        opp.Budget_Amount_D__c = 111;
        opp.Cancel_Reason_Text_D__c = 'newOpp.CancelReasonText__c';
        opp.Cancel_Reason_D__c = 'newOpp.CancelReason__c';
        opp.Competitor_Company_D__c = 'newOpp.CompetitorCompany__c';
        opp.Competitor_Product_D__c = 'newOpp.Competitor_Product__c';
        opp.Competitor_Product2_D__c = 'newOpp.Competitor_Product2__c';
        opp.Competitor_Product3_D__c = 'newOpp.Competitor_Product3__c';
        opp.Competitor_Product4_D__c = 'newOpp.Competitor_Product4__c';
        opp.Competitor_Product5_D__c = 'newOpp.Competitor_Product5__c';
        opp.Competitor_Product6_D__c = 'newOpp.Competitor_Product6__c';
        opp.Competitor_Product7_D__c = 'newOpp.Competitor_Product7__c';
        opp.Competitor_Product8_D__c = 'newOpp.Competitor_Product8__c';
        opp.Competitor_Product_Code_D__c = 'newOpp.CompetitorProductCode__c';
        opp.Competitor_Product_Code2_D__c = 'newOpp.CompetitorProductCode2__c';
        opp.Competitor_Product_Code3_D__c = 'newOpp.CompetitorProductCode3__c';
        opp.Competitor_Product_Code4_D__c = 'newOpp.CompetitorProductCode4__c';
        opp.Competitor_Product_Code5_D__c = 'newOpp.CompetitorProductCode5__c';
        opp.Competitor_Product_Code6_D__c = 'newOpp.CompetitorProductCode6__c';
        opp.Competitor_Product_Code7_D__c = 'newOpp.CompetitorProductCode7__c';
        opp.Competitor_Product_Code8_D__c = 'newOpp.CompetitorProductCode8__c';
        opp.Dealer_Sales_Staff_Name_D__c = 'newOpp.DealerSalesStaffName__c';
        opp.Dealer_Service_D__c = 'newOpp.DealerService__c';
        opp.Expected_Delivery_Date_D__c = day1;
        opp.Expected_Order_Date_D__c = day1;
        opp.Inquiry_Result_D__c = 'newOpp.InquiryResult__c';
        opp.Inquiry_Result_Cancel_D__c = null;
        opp.Inquiry_Result_Lost_D__c = null;
        opp.Inquiry_Result_Order_D__c = null;
        opp.Lost_Amount_D__c = 111;
        opp.Lost_Competitor_Product_D__c = 'newOpp.LostCompetitorProduct__c';
        opp.LostReasonText_D__c = 'newOpp.LostReasonText__c';
        opp.LostReason_D__c = 'newOpp.Lostreason__c';
        opp.New_Inquiry_Date_D__c = day1;
        opp.Phase1Date_D__c = day1;
        opp.Phase2Date_D__c = day1;
        opp.Phase3Date_D__c = day1;
        opp.Sales_Channel_D__c = 'direct';
        opp.Sub_Dealer_D__c = 'newOpp.SubDealer__c';
        opp.Trade_Type_D__c = 'Taxation';
        opp.Machine_Parts_D__c = 'Machine';
        opp.SpecialDeliveryAddress_D__c= specialDeliveryAddress3.Id;
        opp.ForeignTradeCompany_D__c = foreignTradeCompany3.Id;
        
        opp.DealerSelectOwner__c = UserInfo.getUserId();
        
        update opp;
        
        oli.QuantityD__c = 2;
        oli.UnitPriceD__c = 111;
        oli.DescriptionD__c = 'test';
        oli.DealerSelectProduct__c = product1.Id;
        
        update oli;
        
        opp.ApprovalStatus_D__c = 'Completed';
        update opp;
        opp.ApprovalStatus_D__c = 'Submit';
        update opp;
        opp.ApprovalStatus_D__c = 'Reject';
        update opp;
 
        opp.ApprovalStatus_D__c = 'Completed';
        update opp;
        opp.ApprovalStatus_D__c = 'Submit';
        update opp;
        opp.ApprovalStatus_D__c = 'Pass';
        update opp;
    }
 
    static testMethod void myTest4() {
 
        StaticParameter.OpportunityTriggerIsUpdate = true;
        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        Account accIE = new Account(
            Name = 'test',
            RecordTypeId = rectIE[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c='Customer IE',
            FacilityName__c='abc',
            PostCode__c = '123456'
        );
        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',
            ProductSegment__c = 'IE',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine'
        );
        insert pricebook;
           
        List<RecordType> rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity'];
        Opportunity opp = new Opportunity(
            Name = 'test',
            AccountId = accIE.Id,
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            StageName = 'Prospect Created',
            CancelReason__c = 'Inquiry repeat',
            Cancel_reason_D__c = 'Inquiry repeat',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'IE',
            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'
        );
        insert opp;
        
        opp.Phase1Date_D__c = Date.today();
        update opp;
 
        opp.Phase2Date_D__c = Date.today();
        update opp;
 
        opp.StageName = 'Phase3';
        update opp;
 
        OpportunityContactRole role = new OpportunityContactRole(
            Role  = 'End user',
            IsPrimary = true,
            OpportunityId = opp.Id,
            ContactId = con.Id
        );
        insert role;
 
        Order odr = new Order(
            Name = 'test',
            Status = 'Draft',
            Status__c = 'Active',
            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;
        opp.Name = 'test';
        update opp;
    }
 
    static testMethod void myTest5() {
        
        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 = '123456'
        );
        insert accIE; 
        
        PriceBook2 pricebook =new PriceBook2(
            Name = 'IE',
            ProductSegment__c = 'IE',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine'
        );
        insert pricebook;
 
        User user = new User();
        user.LastName = 'test';
        user.FirstName = 'test';
        user.Alias = 'test';
        user.Email = 'User202105191300@test.com';
        user.Username = 'User202105191300@test222.com';
        user.CommunityNickname = 'test01';
        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<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 = 'Prospect Created',
            CancelReason__c = 'Inquiry repeat',
            Cancel_reason_D__c = 'Inquiry repeat',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'IE',
            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'
        );
        insert opp;
        Opportunity oppNew = new Opportunity();
        oppNew.Name = 'test opp';
        oppNew.AccountId = accIE.Id;
        oppNew.RecordTypeId = rectOpp[0].Id;
        oppNew.OwnerId = user.Id;
        oppNew.StageName = 'Prospect Created';
        oppNew.CancelReason__c = 'Inquiry repeat';
        oppNew.Cancel_reason_D__c = 'Inquiry repeat';
        oppNew.CurrencyIsoCode = 'CNY';
        oppNew.ProductSegment__c = 'IE';
        oppNew.CloseDate = Date.today();
        oppNew.NewInquiryDate__c = Date.today().addDays(-2);
        oppNew.ExpectedOrderDate__c = Date.today().addDays(2);
        oppNew.TradeType__c = 'Taxation';
        oppNew.SalesChannel__c = 'direct';
        oppNew.Machine_Parts__c = 'Machine';
        insert oppNew;
        oppNew.Manager__c  = user.Id;
        oppNew.Have_Computer__c = true;
        oppNew.CanChangeOpp__c = true;
        oppNew.Association_Opportunity__c = opp.Id;
        update oppNew;
        /*oppNew.Association_Opportunity__c = null;
        update oppNew;*/
    }
}