高章伟
2022-02-24 2aa8da8af66aa8ae00f25831aed6bb0364176e7b
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
@isTest
private class ConsumableOrderDetail2TriggerTest {
    static testMethod void testInsert() {
        StaticParameter.ConsumableAssetHanderTrigger = true;
        Product2 prod01 = new Product2(Name = 'Test01', ProductCode = 'Test01', Asset_Model_No__c = 'Test01', SFDA_Status__c = '有効', Dealer_special_Object__c = true, Packing_list_manual__c = 12);
        insert new Product2[] {prod01};
        Product2__c pro1 = new Product2__c(Name = 'Pro001', OT_CODE_Text__c = 'Test001', Product2__c = prod01.Id);
        insert new Product2__c[] {pro1};
        Consumable_order__c co = new Consumable_order__c();
        co.Name = 'testorderArrive';
        insert co;
        //插入明细1
        Consumable_orderdetails__c Orderdet6 = new Consumable_orderdetails__c();
        Orderdet6.Name = 'ZSD_01_001001';
        Orderdet6.Consumable_order__c = co.Id;
        Orderdet6.RecordTypeId = System.Label.RT_ConOrderDetail1_Order  ;
        Orderdet6.Consumable_Count__c = 1;
        Orderdet6.Consumable_Product__c = pro1.Id;
        Orderdet6.Intra_Trade_List_RMB__c = 1;
        //Orderdet6.Box_Piece__c = '盒';
        insert Orderdet6;
 
        //插入发货明细
        Consumable_order_details2__c cod1 = new Consumable_order_details2__c();
        cod1.Name = 'testorderdetail21';
        cod1.Consumable_order_minor__c = co.id;
        Date d = Date.newInstance(2017, 7, 3);
        cod1.Arrive_date__c = d;
        cod1.Consumable_Product__c = pro1.Id;
        cod1.Asset_Model_No__c = 'Test01';
        upsert cod1;
 
        //插入发货明细2
        Consumable_order_details2__c cod2 = new Consumable_order_details2__c();
        cod2.Name = 'testorderdetail22';
        cod2.Asset_Model_No__c = 'Test01';
        cod2.Consumable_order_minor__c = co.id;
        cod2.Consumable_Arrived_order__c = co.id;
        cod2.Deliver_date__c = d;
        cod2.Consumable_Return_order__c = co.Id;
        upsert cod2;
 
        Consumable_order__c order1 = [select id, OrderNumber_arrived__c, Shipment_Date__c, Delivery_detail_count__c from Consumable_order__c where Id = :co.Id];
        //System.assertEquals(1,order1.OrderNumber_arrived__c);
        //System.assertEquals(d,order1.Shipment_Date__c);
        //System.assertEquals(1,order1.Delivery_detail_count__c);
 
        //更新发货明细
        Consumable_order_details2__c cod3 = new Consumable_order_details2__c();
        cod3.id = cod2.Id;
        Date d1 = Date.newInstance(2017, 7, 4);
        cod3.Arrive_date__c = d1;
        upsert cod3;
 
        //Consumable_order__c order2 = [select id,OrderNumber_arrived__c from Consumable_order__c where Id = :co.Id];
        //System.assertEquals(2,order2.OrderNumber_arrived__c);
 
        //删除发货明细
        Consumable_order_details2__c cod4 = new Consumable_order_details2__c();
        cod4.id = cod2.Id;
        delete cod4;
 
 
        //Consumable_order__c order3 = [select id,OrderNumber_arrived__c from Consumable_order__c where Id = :co.Id];
        //System.assertEquals(1,order3.OrderNumber_arrived__c);
 
        //testarrivedSet();
        //testF();
    }
 
    private static void testarrivedSet() {
        Consumable_order__c co = new Consumable_order__c();
        co.Name = 'testCo';
        List<RecordType> rtList = [select Id from RecordType where DeveloperName = 'Arrive' and SobjectType = 'Consumable_order__c'];
        co.RecordTypeId = rtList[0].Id;
        upsert co;
 
        Product2__c p = new Product2__c();
        p.Name = 'testModel';
        upsert p;
 
        //生成订单
        Consumable_orderdetails__c odd1 = new Consumable_orderdetails__c();
        odd1.Name = 'testorderdetail1';
        odd1.Consumable_order__c = co.Id;
        odd1.Dealer_Custom_Price__c = 1000;
        odd1.Consumable_count__c = 10;
        odd1.Invoiced_Procount__c = 5;
        odd1.InvoicedProCost_RMB__c = 5000;
        odd1.Shipment_Count__c = 8;
        odd1.Delivery_List_RMB__c = 1000;
        //odd1.ReturnGoods_unitPrice__c=1000;
        odd1.RrturnPro_count__c = 2;
        upsert odd1;
        System.Test.startTest();
        Consumable_order_details2__c cod1 = new Consumable_order_details2__c();
        cod1.Name = 'testCod1';
        cod1.Asset_Model_No__c = 'testModel';
        cod1.Consumable_product__c = p.Id;
        cod1.Consumable_order_minor__c = co.Id;
        //cod1.Consumable_Arrived_order__c = co.Id;
        rtList = [select Id, developername from RecordType where DeveloperName = 'Detail2_Delivery' and SobjectType = 'Consumable_order_details2__c'];
        cod1.RecordTypeId = rtList[0].Id;
        cod1.Intra_Trade_List_RMB__c = 1000;
 
        upsert cod1;
 
        //Consumable_orderdetails__c detail1 = [select Id, Name, Asset_Model_No__c, Consumable_Arrivecount__c from Consumable_orderdetails__c where Consumable_order__c = :co.Id and Asset_Model_No__c =:cod1.Asset_Model_No__c];
 
        //System.assertEquals(detail1.Asset_Model_No__c, cod1.Asset_Model_No__c);
        //System.assertEquals(detail1.Consumable_Arrivecount__c, 1);
 
        Consumable_order_details2__c cod2 = new Consumable_order_details2__c();
        cod2.id = cod1.Id;
        cod2.Consumable_Arrived_order__c = co.Id;
        cod2.RecordTypeId = rtList[0].Id;
        cod2.Intra_Trade_List_RMB__c = 1000;
 
        upsert cod2;
 
        //detail1 = [select Id, Name, Asset_Model_No__c, Consumable_Arrivecount__c from Consumable_orderdetails__c where Consumable_order__c = :co.Id and Asset_Model_No__c =:cod1.Asset_Model_No__c];
 
        //System.assertEquals(detail1.Consumable_Arrivecount__c, 2);
 
        Consumable_order_details2__c cod3 = new Consumable_order_details2__c();
        cod3.id = cod1.id;
        cod3.Name = 'testCod1';
        cod3.Asset_Model_No__c = 'testModel';
        cod3.Consumable_product__c = p.Id;
        cod3.Consumable_order_minor__c = co.Id;
        cod3.RecordTypeId = rtList[0].Id;
        cod3.Intra_Trade_List_RMB__c = 1000;
        cod3.Return_date__c = date.today();
 
        upsert cod3;
 
        delete cod2;
        System.Test.stopTest();
        //detail1 = [select Id, Name, Asset_Model_No__c, Consumable_Arrivecount__c from Consumable_orderdetails__c where Consumable_order__c = :co.Id and Asset_Model_No__c =:cod1.Asset_Model_No__c];
 
        //System.assertEquals(detail1.Consumable_Arrivecount__c, 2);
    }
 
    private static void testReturnSet() {
        Consumable_order__c co = new Consumable_order__c();
        co.Name = 'testCo';
        List<RecordType> rtList = [select Id from RecordType where DeveloperName = 'ReturnGoods' and SobjectType = 'Consumable_order__c'];
        co.RecordTypeId = rtList[0].Id;
        upsert co;
 
        Product2__c p = new Product2__c();
        p.Name = 'testModel';
        upsert p;
 
        //生成订单
        Consumable_orderdetails__c odd1 = new Consumable_orderdetails__c();
        odd1.Name = 'testorderdetail1';
        odd1.Consumable_order__c = co.Id;
        odd1.Dealer_Custom_Price__c = 1000;
        odd1.Consumable_count__c = 10;
        odd1.Invoiced_Procount__c = 5;
        odd1.InvoicedProCost_RMB__c = 5000;
        odd1.Shipment_Count__c = 8;
        odd1.Delivery_List_RMB__c = 1000;
        //odd1.ReturnGoods_unitPrice__c=1000;
        odd1.RrturnPro_count__c = 2;
        upsert odd1;
 
        Consumable_order_details2__c cod1 = new Consumable_order_details2__c();
        cod1.Name = 'testCod1';
        cod1.Asset_Model_No__c = 'testModel';
        cod1.Consumable_product__c = p.Id;
        cod1.Consumable_order_minor__c = co.Id;
        cod1.Consumable_Return_order__c = co.Id;
        cod1.Return_date__c = date.today();
        rtList = [select Id, developername from RecordType where DeveloperName = 'Detail2_Delivery' and SobjectType = 'Consumable_order_details2__c'];
        cod1.RecordTypeId = rtList[0].Id;
        cod1.Intra_Trade_List_RMB__c = 1000;
        System.Test.startTest();
        upsert cod1;
 
        //Consumable_orderdetails__c detail1 = [select Id, Name, Asset_Model_No__c, Consumable_Arrivecount__c from Consumable_orderdetails__c where Consumable_order__c = :co.Id and Asset_Model_No__c =:cod1.Asset_Model_No__c];
 
        //System.assertEquals(detail1.Asset_Model_No__c, cod1.Asset_Model_No__c);
        //System.assertEquals(detail1.Consumable_Arrivecount__c, 1);
 
        Consumable_order_details2__c cod2 = new Consumable_order_details2__c();
        cod2.id = cod1.id;
        cod2.Consumable_Return_order__c = co.Id;
        cod2.RecordTypeId = rtList[0].Id;
        cod2.Intra_Trade_List_RMB__c = 1000;
        cod2.Return_date__c = date.today();
        upsert cod2;
 
        //detail1 = [select Id, Name, Asset_Model_No__c, Consumable_Arrivecount__c from Consumable_orderdetails__c where Consumable_order__c = :co.Id and Asset_Model_No__c =:cod1.Asset_Model_No__c];
 
        //System.assertEquals(detail1.Consumable_Arrivecount__c, 2);
 
        Consumable_order_details2__c cod3 = new Consumable_order_details2__c();
        cod3.id = cod1.id;
        cod3.Intra_Trade_List_RMB__c = 1000;
        cod3.Return_date__c = date.today();
 
        upsert cod3;
        delete cod2;
        System.Test.stopTest();
        //detail1 = [select Id, Name, Asset_Model_No__c, Consumable_Arrivecount__c from Consumable_orderdetails__c where Consumable_order__c = :co.Id and Asset_Model_No__c =:cod1.Asset_Model_No__c];
 
        //System.assertEquals(detail1.Consumable_Arrivecount__c, 2);
    }
 
 
    //返品
    static testMethod void productReturn_new() {
        //Oly_TriggerHandler.bypass('NFM701ControllerHandler');
        StaticParameter.ConsumableAssetHanderTrigger = true;
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        Profile prof = [select Id from Profile where Name = '901_经销商社区普通权限_2重验证(ET)'];//
 
 
 
        Account myAccount2 = new Account(name = 'Testaccount002', Dealer_discount__c = 20, RecordTypeId = rectCo[0].Id);
        insert myAccount2;
 
        Contact core = new Contact(email = 'jplumber@salesforce.com', firstname = 'Joe', lastname = 'Plumber', accountid = myAccount2.id);
        insert core;
        user MyUser_Test = 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 = 'testUser@testorg.com');
        insert MyUser_Test;
        system.runAs(myUser_Test) {
                        
        Product2 prod01 = new Product2(Name='Test01',ProductCode='Test01',Asset_Model_No__c = 'Test01',SFDA_Status__c = '有効',Dealer_special_Object__c = true);
        Product2 prod02 = new Product2(Name='Test02',ProductCode='Test02',Asset_Model_No__c = 'Test02',SFDA_Status__c = '有効',Dealer_special_Object__c = true);
        insert new Product2[]{prod01,prod02};
        Product2__c pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='Test001',Product2__c = prod01.Id);
        Product2__c pro2 = new Product2__c(Name='Pro002',OT_CODE_Text__c='Test002',Product2__c = prod02.Id);
        insert new Product2__c[] {pro1, pro2};
            //订单
            Consumable_order__c Order1 = new Consumable_order__c();
            Order1.Name = 'OCM_01_001';
            Order1.Order_status__c = '批准';
            Order1.Order_type__c = '订单';
            Order1.Dealer_Info__c = myAccount2.Id;
            Order1.RecordTypeid = System.Label.RT_ConOrder_Delivery;
            insert  Order1;
            //Consumable_order__c coc = [select Dealer_Info__r.name from Consumable_order__c where Id =:Order1.Id];
            //system.assertEquals('qeee',coc.Dealer_Info__r.name);
 
            //订单明细
            //fahuo
            Consumable_orderdetails__c Orderdet = new Consumable_orderdetails__c();
            Orderdet.Name = 'OCM_01_001001';
            Orderdet.Consumable_order__c = Order1.Id;
            Orderdet.RecordTypeId = System.Label.RT_ConOrderDetail1_Order;
            Orderdet.Consumable_Product__c = pro1.Id;
            Orderdet.Consumable_count__c = 4;
            insert Orderdet;
 
            //发货明细
            //fahuo
            Consumable_order_details2__c Orderdet1 = new Consumable_order_details2__c();
            Orderdet1.Name = 'OCM_01_001001';
            Orderdet1.Consumable_order_minor__c = Order1.Id;
            Orderdet1.Consumable_Product__c = pro1.Id;
            Orderdet1.Asset_Model_No__c = 'Pro001';
            Orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet1.Box_Piece__c ='盒';
            Orderdet1.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRA';
            //daohuo
            Consumable_order_details2__c Orderdet2 = new Consumable_order_details2__c();
            Orderdet2.Name = 'OCM_01_001002';
            Orderdet2.Consumable_order_minor__c = Order1.Id;
            Orderdet2.Consumable_Product__c = pro1.Id;
            Orderdet2.Asset_Model_No__c = 'Pro001';
            Orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet2.Box_Piece__c ='盒';
            Orderdet2.Arrive_date__c = Date.today();
            //Orderdet2.Send_Date__c = Date.today();
            //Orderdet2.Used_date__c= Date.today();
            Orderdet2.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRB';
            //sale
            Consumable_order_details2__c Orderdet3 = new Consumable_order_details2__c();
            Orderdet3.Name = 'OCM_01_001003';
            Orderdet3.Consumable_order_minor__c = Order1.Id;
            Orderdet3.Consumable_Product__c = pro1.Id;
            Orderdet3.Asset_Model_No__c = 'Pro001';
            Orderdet3.Box_Piece__c ='盒';
            Orderdet3.Used_date__c= Date.today();
            Orderdet3.Arrive_date__c = Date.today();
            Orderdet3.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet3.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRC';
            //出库
            Consumable_order_details2__c Orderdet4 = new Consumable_order_details2__c();
            Orderdet4.Name = 'OCM_01_001004';
            Orderdet4.Consumable_order_minor__c = Order1.Id;
            Orderdet4.Consumable_Product__c = pro1.Id;
            Orderdet4.Asset_Model_No__c = 'Pro001';
            Orderdet4.Box_Piece__c ='个';
            Orderdet4.Send_Date__c = Date.today();
            Orderdet4.Arrive_date__c = Date.today();
            Orderdet4.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet4.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRN';
            //quxiao
            Consumable_order_details2__c Orderdet5 = new Consumable_order_details2__c();
            Orderdet5.Name = 'OCM_01_001005';
            Orderdet5.Consumable_order_minor__c = Order1.Id;
            Orderdet5.Consumable_Product__c = pro1.Id;
            Orderdet5.Asset_Model_No__c = 'Pro001';
            Orderdet5.Cancellation_Date__c = Date.today();
            Orderdet5.Cancellation_Flag__c = true;
            Orderdet5.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet5.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRZ';
            Orderdet5.Box_Piece__c ='个';
            insert new Consumable_order_details2__c[] {Orderdet1, Orderdet2,Orderdet3,Orderdet4,Orderdet5};
 
            PageReference page = new PageReference('/apex/ArriveGoods?ArrType=ReG');
            System.Test.setCurrentPage(page);
            ArriveGoodsController Controller = new ArriveGoodsController();
            //初始化测试
            System.Test.startTest();
            Controller.init();
            //排序
            Controller.barcode = '01049531702003111115120017181000105ZK250BXJRA\n01049531702003111115120017181000105ZK250BXJRB\n01049531702003111115120017181000105ZK250BXJRC\n01049531702003111115120017181000105ZK250BXJRN\n01049531702003111115120017181000105ZK250BXJRZ\n01049531702003111115120017181000105ZK250BXJRR';
            Controller.SearchPro();
            System.assertEquals(5, controller.ConsumableorderdetailsRecordserror.size());
            // System.assertEquals(0, controller.ShowGoodsofReturnList.size());
            // controller.ShowGoodsofReturnList[0].esd.Return_reason__c = '多发';
            // controller.ShowGoodsofReturnList[1].esd.Return_reason__c = '多发';
            // controller.ShowGoodsofReturnList[0].esd.Rrturn_count__c = 1;
            // Controller.UpdateGoodsOfReturn();
 
            list<String> list1 = new list<String>();
            list1.add(Controller.barcode = '01234567898');
            Controller.inventoryEntryNoESetId(list1);
 
            list1.clear();
            list1.add(Controller.barcode = '012345678901234A67');
            Controller.inventoryEntryNoESetId(list1);
 
            list1.clear();
            list1.add(Controller.barcode = '0123456789012345117AA01');
            Controller.inventoryEntryNoESetId(list1);
 
            list1.clear();
            list1.add(Controller.barcode = '01234567890123456789012349990001');
            Controller.inventoryEntryNoESetId(list1);
 
            list1.clear();
            list1.add(Controller.barcode = '0123456789012345177AA0000000000001');
            Controller.inventoryEntryNoESetId(list1);
 
            list1.clear();
            list1.add(Controller.barcode = '0123456789012345177AA1111111111111');
            Controller.inventoryEntryNoESetId(list1);
 
            list1.clear();
            list1.add(Controller.barcode = '241345');
            Controller.inventoryEntryNoESetId(list1);
 
            list1.clear();
            list1.add(Controller.barcode = '2413456');
            Controller.inventoryEntryNoESetId(list1);
 
            list1.clear();
            list1.add(Controller.barcode = '24134567');
            Controller.inventoryEntryNoESetId(list1);
 
            list1.clear();
            list1.add(Controller.barcode = '241345678');
            Controller.inventoryEntryNoESetId(list1);
 
            list1.clear();
            list1.add(Controller.barcode = '2413456789');
            Controller.inventoryEntryNoESetId(list1);
 
            list1.clear();
            list1.add(Controller.barcode = '24134567890');
            Controller.inventoryEntryNoESetId(list1);
 
            list1.clear();
            list1.add(Controller.barcode = '241345678901');
            Controller.inventoryEntryNoESetId(list1);
 
            list1.clear();
            list1.add(Controller.barcode = '0112345678901231177890121215678901234');
            Controller.inventoryEntryNoESetId(list1);
 
            list1.clear();
            list1.add(Controller.barcode = '0112345678901231106789012105678901234');
            Controller.inventoryEntryNoESetId(list1);
            System.Test.stopTest();
            // String[] azzz = new String[]{'1','2'};
            // system.debug(azzz[3]);
        }
    }
 
 
}