GWY
2022-05-21 a3460549533111815e7f73d6cef601a58031525d
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
@isTest
private class AssetTriggerHandlerTest {
    
    static Product2 prd1;
    static Product2 prd2;
    static Account acc;
    static Account dealer;
    static Contact core;
    static User testUser;
    static Asset asset;
    static Asset assetC1;
    static Asset assetC2;
    static void setupTestData() {
 
        OlympusCalendar__c oc1 = new OlympusCalendar__c(Date__c = Date.today().addDays(1), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc2 = new OlympusCalendar__c(Date__c = Date.today().addDays(2), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc3 = new OlympusCalendar__c(Date__c = Date.today().addDays(3), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc4 = new OlympusCalendar__c(Date__c = Date.today().addDays(4), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc5 = new OlympusCalendar__c(Date__c = Date.today().addDays(5), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc6 = new OlympusCalendar__c(Date__c = Date.today().addDays(6), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc7 = new OlympusCalendar__c(Date__c = Date.today().addDays(7), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc8 = new OlympusCalendar__c(Date__c = Date.today().addDays(8), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc9 = new OlympusCalendar__c(Date__c = Date.today().addDays(9), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc10 = new OlympusCalendar__c(Date__c = Date.today().addDays(10), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc11 = new OlympusCalendar__c(Date__c = Date.today().addDays(11), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc12 = new OlympusCalendar__c(Date__c = Date.today().addDays(12), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc13 = new OlympusCalendar__c(Date__c = Date.today().addDays(-1), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc14 = new OlympusCalendar__c(Date__c = Date.today().addDays(-2), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc15 = new OlympusCalendar__c(Date__c = Date.today().addDays(-3), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc16 = new OlympusCalendar__c(Date__c = Date.today().addDays(-4), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc17 = new OlympusCalendar__c(Date__c = Date.today().addDays(-5), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
 
        insert new OlympusCalendar__c[] {oc1,oc2,oc3,oc4,oc5,oc6,oc7,oc8,oc9,oc10,oc11,oc12,oc13,oc14,oc15,oc16,oc17};
 
        List<RecordType> dealerIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Dealer'];
        if (dealerIE.size() == 0) {
            return;
        }
        List<RecordType> olyCompany = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'OlympusCompany'];
        if (olyCompany.size() == 0) {
            return;
        }
 
        List<RecordType> loa_individual = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_个体管理'];
        if (loa_individual.size() == 0) {
            return;
        }
        List<RecordType> loa_number = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_数量管理'];
        if (loa_number.size() == 0) {
            return;
        }
 
        //代理商用户
        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'];
        dealer = new Account();
        dealer.Name = 'test dealer';
        dealer.RecordTypeId = rectDealer[0].Id;
        dealer.ProductSegment__c = 'IE';
        dealer.PostCode__c='000000';
        insert dealer;
        core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=dealer.id);
        insert core;
        testUser = New User(ContactId = core.id,Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser01@prectech.com');
        insert testUser;
 
        //样机客户
        acc = new Account();
        acc.Name = 'test dealer';
        acc.RecordTypeId = olyCompany[0].Id;
        acc.ProductSegment__c = 'IE';
        acc.PostCode__c='000000';
        insert acc;
 
        // 产品
        prd1 = new Product2();
        prd1.Product_ECCode__c      = 'testSBG001';
        prd1.ProductCode            = 'testSBG001';
        prd1.Name                   = 'testSBG001';
        prd1.IsActive               = true;
 
        prd2 = new Product2();
        prd2.Product_ECCode__c      = 'testSBG002';
        prd2.ProductCode            = 'testSBG002';
        prd2.Name                   = 'testSBG002';
        prd2.IsActive               = true;
        insert new Product2[] {prd1, prd2};
 
        // 保有设备 (个体管理)
        assetC1 = new Asset();
        assetC1.RecordTypeId = loa_individual[0].Id;
        assetC1.SerialNumber = 'assetC1';
        assetC1.Name = 'assetC1';
        assetC1.AccountId = acc.Id;
        assetC1.Product2Id = prd1.Id;
        assetC1.Quantity = 1;
        assetC1.Status = '在库';
        assetC1.Equipment_Type__c = 'IE';
        assetC1.loaner_place__c = '北京酒仙桥';
        assetC1.Remarks2__c = 'assetC1';
        
        // 保有设备 (个体管理)
        assetC2 = new Asset();
        assetC2.RecordTypeId = loa_individual[0].Id;
        assetC2.SerialNumber = 'assetC2';
        assetC2.Name = 'assetC2';
        assetC2.AccountId = acc.Id;
        assetC2.Product2Id = prd2.Id;
        assetC2.Quantity = 1;
        assetC2.Status = '在库';
        assetC2.Equipment_Type__c = 'IE';
        assetC2.loaner_place__c = '北京酒仙桥';
        insert new Asset[] {assetC2,assetC1};
    }
    @isTest static void test_method_one() {
 
        setupTestData();
 
        List<RecordType> rectLapp = [select Id from RecordType where IsActive = true and SobjectType = 'loaner_application__c' and Name = 'IE'];
        if (rectLapp.size() == 0) {
            return;
        }
        List<RecordType> loa_individual = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_个体管理'];
        if (loa_individual.size() == 0) {
            return;
        }
 
        // Implement test code
        loaner_application__c loanerApp = new loaner_application__c();
        loanerApp.Name = 'TESTYJ0001';
        loanerApp.Approval_Step__c = 1;
        loanerApp.Status__c = '已批准';
        loanerApp.Rental_Start_Date__c = Date.today();
        loanerApp.Rental_End_Date__c = Date.today();
        loanerApp.Loaner_Ser__c = 'test';
        loanerApp.Equipment_Type__c = 'IE';
        loanerApp.RecordTypeId = rectLapp[0].Id;
        loanerApp.Demo_purpose__c = '演示';
        loanerApp.Request_shipping_Date__c = Date.today();
        loanerApp.Request_return_Date__c = Date.today();
        insert loanerApp;
        LoanerApplicationWebService.sendOutAll(loanerApp.Id);
 
        loaner_application_detail__c loanerAppDet = new loaner_application_detail__c();
        loanerAppDet.RAESD_Status__c = '出库前已检测';
        loanerAppDet.Name = 'TESTYJ0001-01';
        loanerAppDet.loaner_application__c = loanerApp.Id;
        loanerAppDet.LOANER__c = assetC2.Id;
        loanerAppDet.Allocate_Date__c = Date.today();
        insert loanerAppDet;
 
 
 
 
        assetC2.Status_text__c = '待修理';
        update assetC2;
    }
 
    @isTest static void test_01(){
        List<RecordType> dealerIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Dealer'];
        if (dealerIE.size() == 0) {
            return;
        }
        List<RecordType> olyCompany = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'OlympusCompany'];
        if (olyCompany.size() == 0) {
            return;
        }
 
        List<RecordType> loa_individual = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_个体管理'];
        if (loa_individual.size() == 0) {
            return;
        }
        List<RecordType> loa_number = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_数量管理'];
        if (loa_number.size() == 0) {
            return;
        }
 
        //代理商用户
        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'];
        dealer = new Account();
        dealer.Name = 'test dealer';
        dealer.RecordTypeId = rectDealer[0].Id;
        dealer.ProductSegment__c = 'BS';
        dealer.PostCode__c='000000';
        insert dealer;
        core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=dealer.id);
        insert core;
        testUser = New User(ContactId = core.id,Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser01@prectech.com');
        insert testUser;
 
        //样机客户
        acc = new Account();
        acc.Name = 'test dealer';
        acc.RecordTypeId = olyCompany[0].Id;
        acc.ProductSegment__c = 'BS';
        acc.PostCode__c='000000';
        insert acc;
 
        loaner_Set__c loanerSet = new loaner_Set__c();
        loanerSet.Equipment_Type__c = 'BS';
        loanerSet.Set_No__c = 'IETEST0001';
        loanerSet.Name = 'IETEST0001';
 
        insert loanerSet;
 
        // 产品
        prd1 = new Product2();
        prd1.Product_ECCode__c      = 'testSBG001';
        prd1.ProductCode            = 'testSBG001';
        prd1.Name                   = 'testSBG001';
        prd1.IsActive               = true;
 
        prd2 = new Product2();
        prd2.Product_ECCode__c      = 'testSBG002';
        prd2.ProductCode            = 'testSBG002';
        prd2.Name                   = 'testSBG002';
        prd2.IsActive               = true;
        insert new Product2[] {prd1, prd2};
 
        // 保有设备 (数量管理)
        Asset asset = new Asset();
        asset.RecordTypeId = loa_number[0].Id;
        asset.SerialNumber = 'asset';
        asset.Name = 'asset';
        asset.AccountId = acc.Id;
        asset.Product2Id = prd2.Id;
        asset.Quantity = 1;
        asset.Status = '在库';
        asset.Equipment_Type__c = 'BS';
        asset.loaner_place__c = '广州办';
        asset.total_number__c = 20;
        asset.Remarks2__c = 'asset';
 
        // 保有设备 (个体管理)
        Asset assetC1 = new Asset();
        assetC1.RecordTypeId = loa_individual[0].Id;
        assetC1.SerialNumber = 'assetC1';
        assetC1.Name = 'assetC1';
        assetC1.AccountId = acc.Id;
        assetC1.Product2Id = prd1.Id;
        assetC1.Quantity = 1;
        assetC1.Status = '出借';
        assetC1.Equipment_Type__c = 'BS';
        assetC1.loaner_place__c = '北京酒仙桥';
        assetC1.Remarks2__c = 'assetC1';
        
        // 保有设备 (个体管理)
        Asset assetC2 = new Asset();
        assetC2.RecordTypeId = loa_individual[0].Id;
        assetC2.SerialNumber = 'assetC2';
        assetC2.Name = 'assetC2';
        assetC2.AccountId = acc.Id;
        assetC2.Product2Id = prd1.Id;
        assetC2.Quantity = 1;
        assetC2.Status = '出借';
        assetC2.Equipment_Type__c = 'BS';
        assetC2.loaner_place__c = '北京酒仙桥';
        insert new Asset[] {asset,assetC1};
 
        Loaner_Set_Detail__c lSD1 = new Loaner_Set_Detail__c();
        lSD1.Loaner_Set__c = loanerSet.Id;
        lSD1.Asset__c = asset.Id;
        Loaner_Set_Detail__c lSD2 = new Loaner_Set_Detail__c();
        lSD2.Loaner_Set__c = loanerSet.Id;
        lSD2.Asset__c = assetC1.Id;
        insert new Loaner_Set_Detail__c[] {lSD1,lSD2};
 
        asset.Status = '出借';
 
        update asset;
 
        assetC1.Status = '在库';
 
        update assetC1;
 
    }
 
    @isTest static void test_method_two() {
 
        setupTestData();
 
        List<RecordType> rectLapp = [select Id from RecordType where IsActive = true and SobjectType = 'loaner_application__c' and Name = 'IE'];
        if (rectLapp.size() == 0) {
            return;
        }
        List<RecordType> loa_individual = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_个体管理'];
        if (loa_individual.size() == 0) {
            return;
        }
 
        // Implement test code
        loaner_application__c loanerApp = new loaner_application__c();
        loanerApp.Name = 'TESTYJ0001';
        loanerApp.Approval_Step__c = 1;
        loanerApp.Status__c = '已批准';
        loanerApp.Rental_Start_Date__c = Date.today();
        loanerApp.Rental_End_Date__c = Date.today();
        loanerApp.Loaner_Ser__c = 'test';
        loanerApp.Equipment_Type__c = 'IE';
        loanerApp.RecordTypeId = rectLapp[0].Id;
        loanerApp.Demo_purpose__c = '演示';
        loanerApp.Request_shipping_Date__c = Date.today();
        loanerApp.Request_return_Date__c = Date.today();
        insert loanerApp;
        LoanerApplicationWebService.sendOutAll(loanerApp.Id);
 
        loaner_application_detail__c loanerAppDet = new loaner_application_detail__c();
        loanerAppDet.RAESD_Status__c = '已回库';
        loanerAppDet.Name = 'TESTYJ0001-01';
        loanerAppDet.loaner_application__c = loanerApp.Id;
        loanerAppDet.LOANER__c = assetC1.Id;
        loanerAppDet.Allocate_Date__c = Date.today();
        insert loanerAppDet;
 
        assetC1.Status = '出借';
        update assetC1;
 
        
        assetC1.Status_text__c = '待修理';
        update assetC1;
        
    }
 
}