GWY
2022-04-27 12b7399736e90d33bfe0c2d29917d6f075246e00
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
@isTest
private class SWOTriggerHandlerTest {
    static testMethod void testMethod1() {
        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        List<RecordType> rectOpp = [select Id from RecordType where IsActive = true and SobjectType = 'Opportunity' and Name = 'SSBD'];
        Id pricebookId = Test.getStandardPricebookId();
        
        Pricebook2 pricebook = new Pricebook2(
            Name = 'IE',
            ProductSegment__c = 'IE',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine',
            CurrencyIsoCode = 'CNY'
        );
        insert pricebook;
        
        Product2 product1 = new Product2();
        product1.Name = 'product1';
        product1.IsActive = true;
        product1.ProductCode = 'product1';
        product1.ProductStatus__c = '1';
        product1.NMPAStatus_one__c = 'Z1';
        product1.MaterialStatus_one_Start__c = Date.today().addDays(-22);
        product1.MaterialStatus_one_End__c = Date.today().addDays(22);
        insert product1;
 
        User_FaultInfo__c uf = new User_FaultInfo__c();
        // uf.Name = 'Test';
        insert uf;
 
         List<RecordType> rectDealer = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Dealer'];
        Profile prof = [select Id from Profile where Name ='SSBG DEALER IE'];
        Account dealer = new Account();
        dealer.Name = 'test dealer';
        dealer.RecordTypeId = rectDealer[0].Id;
        dealer.ProductSegment__c = 'BS';
        dealer.PostCode__c='000000';
        insert dealer;
        Contact core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=dealer.id);
        insert core;
        User testUser = New User(ContactId = core.id,Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = '00e28000001sZE6',TimeZoneSidKey='Asia/Shanghai', UserName='testUser01@prectech.com');
 
        User user2 = new User();
        user2.LastName = 'test2';
        user2.FirstName = 'test2';
        user2.Alias = 'test2';
        user2.Email = 'test2@test.com';
        user2.Username = 'Xin_Prectech@olympus.com.cn';
        user2.CommunityNickname = 'test2';
        user2.IsActive = true;
        user2.EmailEncodingKey = 'ISO-2022-JP';
        user2.TimeZoneSidKey = 'Asia/Tokyo';
        user2.LocaleSidKey = 'ja_JP';
        user2.LanguageLocaleKey = 'ja';
        user2.ProfileId = '00e28000001sZE6';//System.Label.SystemAdmin;
        insert user2;
 
        SWO__c swo = new SWO__c();
        swo.Name = 'Test';
        swo.QUANTITY__c = 22;
        swo.ESTIMATED_LABOUR_HOURS__c = 22;
        swo.LABOUR_RATE__c = 22;
        swo.OFFICE__c = 'Beijing';
        swo.SWO_PRIORITY__c = 'Medium';
        swo.SWO_STATUS__c = 'Close Denied';
        swo.TYPE__c = 'Service';
        swo.ASSIGNEDTO__c = user2.Id;
        swo.DEPARTMENT__c = 'Field Service';
        swo.REASON__c = 'Replacement';
        swo.PRODUCT_TYPE__c = 'NDT';
        swo.ITEM__c = product1.Id;
        swo.INSTRUMENT_RECEIVE_DATE__c = Datetime.now();
        swo.INSTRUMENT_SHIP_DATE__c = Datetime.now().addDays(1);
        swo.DIAGNOSIS_START__c = Datetime.now();
        swo.DIAGNOSIS_END__c = Datetime.now().addDays(1);
        swo.PO_RECEIVE_DATE__c = Datetime.now();
        swo.Quotation_send__c = Datetime.now().addDays(1);
        swo.REPAIR_START__c = Datetime.now();
        swo.REPAIR_END__c = Datetime.now().addDays(1);
 
        swo.CALIBRATION_START__c = Datetime.now();
        swo.CALIBRATION_END__c = Datetime.now().addDays(1);
 
        swo.FQC_START__c = Datetime.now();
        swo.FQC_end__c = Datetime.now().addDays(1);
 
        swo.Repair_DateTime__c = Datetime.now();
        swo.DELIVERED_TO_SERVICE__c = Datetime.now().addDays(1);
        swo.CASE_NUMBER__c = uf.Id;
 
        insert swo;
        swo.SWO_STATUS__c = 'Quotation approved';
        update swo;
        swo.SWO_STATUS__c = 'Quotation for approval';
        update swo;
        swo.SWO_STATUS__c = 'Parts Hold';
        update swo;
        swo.SWO_STATUS__c = 'Delivered to Technician';
        update swo;
        swo.SWO_STATUS__c = 'Ready to Quote';
        update swo;
        swo.SWO_STATUS__c = 'Ready for Sales order';
        update swo;
        swo.SWO_STATUS__c = 'Repair';
        update swo;
        swo.SWO_STATUS__c = 'In Queue';
        update swo;
        swo.SWO_STATUS__c = 'Close cancel';
        update swo;
        swo.SWO_STATUS__c = 'Close Denied';
        update swo;
        swo.SWO_STATUS__c = 'Parts request for diagnosis';
        update swo;
        swo.SWO_STATUS__c = 'Parts ready for diagnosis';
        update swo;
        swo.SWO_STATUS__c = 'Ready to ship';
        update swo;
        swo.SWO_STATUS__c = 'Ready for Customer pickup';
        update swo;
        User user3 = user2;
        user3.Id = null;
        user3.LastName = 'test3';
        user3.FirstName = 'test3';
        user3.Alias = 'test3';
        user3.Email = 'test3@test.com';
        user3.Username = 'Dai_Prectech@olympus.com.cn';
        user3.CommunityNickname = 'test3';
        insert user3;
        swo.ASSIGNEDTO__c = user3.Id;
        update swo;
    }
}