liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
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
@isTest
private class lexPCLLostReportLwcControllerTest {
    
    @TestSetup
    static void makeData(){
        PCLLostProduct2AssetHandlerTest.setUp();
    } 
    static testMethod void testInitCreate(){
        List<Lost_cancel_report__c> report = [select Id from Lost_cancel_report__c];
        delete report;
        Opportunity opp = [select Id from Opportunity limit 1];
        Test.startTest();
        lexPCLLostReportLwcController.init('' + opp.Id,'','Create','失单','');
        Test.stopTest();
    }
    static testMethod void testInitCreate1(){
        Opportunity opp = [select Id from Opportunity limit 1];
        Test.startTest();
        lexPCLLostReportLwcController.init('' + opp.Id,'','Create','失单','');
        Test.stopTest();
    }
    static testMethod void testInitView(){
        Lost_cancel_report__c report = [select Id from Lost_cancel_report__c where LostType__c = '失单'];
        Test.startTest();
        lexPCLLostReportLwcController.init('','' + report.Id,'View','','');
        Test.stopTest();
    }
    static testMethod void testOther(){
        Lost_cancel_report__c report = [select Id from Lost_cancel_report__c where LostType__c = '失单'];
        Test.startTest();
        lexPCLLostReportLwcController.getUserProfileId();
        lexPCLLostReportLwcController.getPickList('PCLLostProduct__c','ProductCategory__c');
        lexPCLLostReportLwcController.searchBrands();
        lexPCLLostReportLwcController.searchBatchIfForProduct('');
        lexPCLLostReportLwcController.getNewLostBrand(0);
        lexPCLLostReportLwcController.getNewLostProduct(0);
        Test.stopTest();
    }
    static testMethod void testSave(){
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        Account myAccount2 = new Account(name='Testaccount002',Dealer_discount__c =20,RecordTypeId = rectCo[0].Id,AgentCode_Ext__c = '9999900');
        insert myAccount2;
        // Lost_cancel_report__c report = [select Id from Lost_cancel_report__c where LostType__c = '失单'];
        Account depart1 = [select Id from Account limit 1];
        LostReport conTest2 = new LostReport();
        conTest2.lostReport.LostType__c = '失单';
        conTest2.lostReport.Opportunity__c = [select Id from Opportunity limit 1].Id;
        conTest2.LostBrands[0].lostBrand.LostPrice__c = 12;
        conTest2.LostBrands[0].lostBrand.Lost_reason_main__c = '价格';
        conTest2.LostBrands[0].LostProducts[0].LostProductss.Quantity__c =3;
        conTest2.LostBrands[0].lostBrand.Agency__c = myAccount2.Id;
        conTest2.LostBrands[0].lostBrand.Lost_By_Company__c = '其他';
        conTest2.LostBrands[0].lostBrand.Lost_By_Company_Mannual__c = 'dddddd';
        conTest2.LostBrands[0].LostProducts[0].lineNo2 = 0;
        conTest2.LostBrands[0].LostProducts[0].LostProductss = new PCLLostProduct__c(Quantity__c = 3);
 
        Test.startTest();
        Map<String,String> maps =  lexPCLLostReportLwcController.dataEntry(JSON.serialize(conTest2),new List<Id>(),new List<Id>());
        lexPCLLostReportLwcController.searchProduct(conTest2.LostBrands[0].LostProducts[0].LostProductss.Id);
        System.debug('chenjingwu=>'+ maps.get('error'));
 
        Test.stopTest();
    }
 
    static testMethod void testSubmit(){
        Lost_cancel_report__c report = [select Id from Lost_cancel_report__c where LostType__c = '失单' limit 1];
        Account depart1 = [select Id from Account where RecordTypeId = '01210000000QemG' limit 1];
        LostReport conTest2 = new LostReport();
        conTest2.lostReport.LostType__c = '失单';
        conTest2.lostReport.Opportunity__c = [select Id from Opportunity limit 1].Id;
        conTest2.LostBrands[0].lostBrand.LostPrice__c = 12;
        conTest2.LostBrands[0].lostBrand.Lost_reason_main__c = '价格';
        conTest2.LostBrands[0].LostProducts[0].LostProductss.Quantity__c =3;
        conTest2.LostBrands[0].lostBrand.Agency__c = depart1.Id;
        conTest2.LostBrands[0].lostBrand.Lost_By_Company__c = '其他';
        conTest2.LostBrands[0].lostBrand.Lost_By_Company_Mannual__c = 'dddddd';
        conTest2.LostBrands[0].LostProducts[0].lineNo2 = 0;
        conTest2.LostBrands[0].LostProducts[0].LostProductss = new PCLLostProduct__c(Quantity__c = 3);
 
        Test.startTest();
        lexPCLLostReportLwcController.submit('草案',false,report.Id);
        Test.stopTest();
    }
 
    static testMethod void testSubmit1(){
        Lost_cancel_report__c report = [select Id from Lost_cancel_report__c where LostType__c = '失单' limit 1];
        Account depart1 = [select Id from Account where RecordTypeId = '01210000000QemG' limit 1];
        LostReport conTest2 = new LostReport();
        conTest2.lostReport.LostType__c = '失单';
        conTest2.lostReport.Opportunity__c = [select Id from Opportunity limit 1].Id;
        conTest2.LostBrands[0].lostBrand.LostPrice__c = 12;
        conTest2.LostBrands[0].lostBrand.Lost_reason_main__c = '价格';
        conTest2.LostBrands[0].LostProducts[0].LostProductss.Quantity__c =3;
        conTest2.LostBrands[0].lostBrand.Agency__c = depart1.Id;
        conTest2.LostBrands[0].lostBrand.Lost_By_Company__c = '其他';
        conTest2.LostBrands[0].lostBrand.Lost_By_Company_Mannual__c = 'dddddd';
        conTest2.LostBrands[0].LostProducts[0].lineNo2 = 0;
        conTest2.LostBrands[0].LostProducts[0].LostProductss = new PCLLostProduct__c(Quantity__c = 3);
 
        Test.startTest();
        lexPCLLostReportLwcController.submit('草案',false,report.Id);
        lexPCLLostReportLwcController.submit('草案',false,report.Id);
        Test.stopTest();
    }
 
    static testMethod void TestSubmitForApproval2(){
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        Account myAccount2 = new Account(name='Testaccount002',Dealer_discount__c =20,RecordTypeId = rectCo[0].Id,AgentCode_Ext__c = '9999900');
        insert myAccount2;
        // Lost_cancel_report__c report = [select Id from Lost_cancel_report__c where LostType__c = '失单'];
        Account depart1 = [select Id from Account limit 1];
        LostReport conTest2 = new LostReport();
        conTest2.lostReport.LostType__c = '失单';
        conTest2.lostReport.Opportunity__c = [select Id from Opportunity limit 1].Id;
        conTest2.LostBrands[0].lostBrand.LostPrice__c = 12;
        conTest2.LostBrands[0].lostBrand.Lost_reason_main__c = '价格';
        conTest2.LostBrands[0].LostProducts[0].LostProductss.Quantity__c =3;
        conTest2.LostBrands[0].lostBrand.Agency__c = myAccount2.Id;
        conTest2.LostBrands[0].lostBrand.Lost_By_Company__c = '其他';
        conTest2.LostBrands[0].lostBrand.Lost_By_Company_Mannual__c = 'dddddd';
        conTest2.LostBrands[0].LostProducts[0].lineNo2 = 0;
        conTest2.LostBrands[0].LostProducts[0].LostProductss = new PCLLostProduct__c(Quantity__c = 3);
 
        Test.startTest();
        Map<String,String> maps =  lexPCLLostReportLwcController.dataEntry(JSON.serialize(conTest2),new List<Id>(),new List<Id>());
        LostReport re = (LostReport)JSON.deserialize(maps.get('LostReport'), LostReport.class);
        lexPCLLostReportLwcController.submit('草案',false,re.lostReport.Id);
        lexPCLLostReportLwcController.submitForApproval(re.lostReport.Id,'','Approve');
        lexPCLLostReportLwcController.submitForApproval(re.lostReport.Id,'','Removed');
        Test.stopTest();
    }
    static testMethod void TestSubmitForApproval1(){
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        Account myAccount2 = new Account(name='Testaccount002',Dealer_discount__c =20,RecordTypeId = rectCo[0].Id,AgentCode_Ext__c = '9999900');
        insert myAccount2;
        // Lost_cancel_report__c report = [select Id from Lost_cancel_report__c where LostType__c = '失单'];
        Account depart1 = [select Id from Account limit 1];
        LostReport conTest2 = new LostReport();
        conTest2.lostReport.LostType__c = '失单';
        conTest2.lostReport.Opportunity__c = [select Id from Opportunity limit 1].Id;
        conTest2.LostBrands[0].lostBrand.LostPrice__c = 12;
        conTest2.LostBrands[0].lostBrand.Lost_reason_main__c = '价格';
        conTest2.LostBrands[0].LostProducts[0].LostProductss.Quantity__c =3;
        conTest2.LostBrands[0].lostBrand.Agency__c = myAccount2.Id;
        conTest2.LostBrands[0].lostBrand.Lost_By_Company__c = '其他';
        conTest2.LostBrands[0].lostBrand.Lost_By_Company_Mannual__c = 'dddddd';
        conTest2.LostBrands[0].LostProducts[0].lineNo2 = 0;
        conTest2.LostBrands[0].LostProducts[0].LostProductss = new PCLLostProduct__c(Quantity__c = 3);
 
        Test.startTest();
        Map<String,String> maps =  lexPCLLostReportLwcController.dataEntry(JSON.serialize(conTest2),new List<Id>(),new List<Id>());
        LostReport re = (LostReport)JSON.deserialize(maps.get('LostReport'), LostReport.class);
        lexPCLLostReportLwcController.submit('草案',false,re.lostReport.Id);
        lexPCLLostReportLwcController.submitForApproval(re.lostReport.Id,'','Reject');
        Test.stopTest();
    }
 
    static testMethod void TestSubmitForApproval5(){
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        Account myAccount2 = new Account(name='Testaccount002',Dealer_discount__c =20,RecordTypeId = rectCo[0].Id,AgentCode_Ext__c = '9999900');
        insert myAccount2;
        // Lost_cancel_report__c report = [select Id from Lost_cancel_report__c where LostType__c = '失单'];
        Account depart1 = [select Id from Account limit 1];
        LostReport conTest2 = new LostReport();
        conTest2.lostReport.LostType__c = '失单';
        conTest2.lostReport.Opportunity__c = [select Id from Opportunity limit 1].Id;
        conTest2.LostBrands[0].lostBrand.LostPrice__c = 12;
        conTest2.LostBrands[0].lostBrand.Lost_reason_main__c = '价格';
        conTest2.LostBrands[0].LostProducts[0].LostProductss.Quantity__c =3;
        conTest2.LostBrands[0].lostBrand.Agency__c = myAccount2.Id;
        conTest2.LostBrands[0].lostBrand.Lost_By_Company__c = '其他';
        conTest2.LostBrands[0].lostBrand.Lost_By_Company_Mannual__c = 'dddddd';
        conTest2.LostBrands[0].LostProducts[0].lineNo2 = 0;
        conTest2.LostBrands[0].LostProducts[0].LostProductss = new PCLLostProduct__c(Quantity__c = 3);
 
        Test.startTest();
        lexPCLLostReportLwcController.submit('草案',false,conTest2.lostReport.Id);
        lexPCLLostReportLwcController.submitForApproval(conTest2.lostReport.Id,'','Reject');
        Test.stopTest();
    }
 
    static testMethod void TestSubmitForApproval3(){
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        Account myAccount2 = new Account(name='Testaccount002',Dealer_discount__c =20,RecordTypeId = rectCo[0].Id,AgentCode_Ext__c = '9999900');
        insert myAccount2;
        // Lost_cancel_report__c report = [select Id from Lost_cancel_report__c where LostType__c = '失单'];
        Account depart1 = [select Id from Account limit 1];
        LostReport conTest2 = new LostReport();
        conTest2.lostReport.LostType__c = '失单';
        conTest2.lostReport.Opportunity__c = [select Id from Opportunity limit 1].Id;
        conTest2.LostBrands[0].lostBrand.LostPrice__c = 12;
        conTest2.LostBrands[0].lostBrand.Lost_reason_main__c = '价格';
        conTest2.LostBrands[0].LostProducts[0].LostProductss.Quantity__c =3;
        conTest2.LostBrands[0].lostBrand.Agency__c = myAccount2.Id;
        conTest2.LostBrands[0].lostBrand.Lost_By_Company__c = '其他';
        conTest2.LostBrands[0].lostBrand.Lost_By_Company_Mannual__c = 'dddddd';
        conTest2.LostBrands[0].LostProducts[0].lineNo2 = 0;
        conTest2.LostBrands[0].LostProducts[0].LostProductss = new PCLLostProduct__c(Quantity__c = 3);
 
        Test.startTest();
        Map<String,String> maps =  lexPCLLostReportLwcController.dataEntry(JSON.serialize(conTest2),new List<Id>(),new List<Id>());
        LostReport re = (LostReport)JSON.deserialize(maps.get('LostReport'), LostReport.class);
        lexPCLLostReportLwcController.submit('草案',false,re.lostReport.Id);
        lexPCLLostReportLwcController.reassignStep(re.lostReport.Id,UserInfo.getUserId());
        Test.stopTest();
    }
 
    static testMethod void TestSubmitForApproval4(){
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        Account myAccount2 = new Account(name='Testaccount002',Dealer_discount__c =20,RecordTypeId = rectCo[0].Id,AgentCode_Ext__c = '9999900');
        insert myAccount2;
        // Lost_cancel_report__c report = [select Id from Lost_cancel_report__c where LostType__c = '失单'];
        Account depart1 = [select Id from Account limit 1];
        LostReport conTest2 = new LostReport();
        conTest2.lostReport.LostType__c = '失单';
        conTest2.lostReport.Opportunity__c = [select Id from Opportunity limit 1].Id;
        conTest2.LostBrands[0].lostBrand.LostPrice__c = 12;
        conTest2.LostBrands[0].lostBrand.Lost_reason_main__c = '价格';
        conTest2.LostBrands[0].LostProducts[0].LostProductss.Quantity__c =3;
        conTest2.LostBrands[0].lostBrand.Agency__c = myAccount2.Id;
        conTest2.LostBrands[0].lostBrand.Lost_By_Company__c = '其他';
        conTest2.LostBrands[0].lostBrand.Lost_By_Company_Mannual__c = 'dddddd';
        conTest2.LostBrands[0].LostProducts[0].lineNo2 = 0;
        conTest2.LostBrands[0].LostProducts[0].LostProductss = new PCLLostProduct__c(Quantity__c = 3);
 
        Test.startTest();
        Map<String,String> maps =  lexPCLLostReportLwcController.dataEntry(JSON.serialize(conTest2),new List<Id>(),new List<Id>());
        LostReport re = (LostReport)JSON.deserialize(maps.get('LostReport'), LostReport.class);
        lexPCLLostReportLwcController.submit('草案',false,re.lostReport.Id);
        lexPCLLostReportLwcController.init('','' + re.lostReport.Id,'View','','');
        Test.stopTest();
    }
 
    // 页面的数据结构
    public class LostReport {
        @AuraEnabled
        public Lost_cancel_report__c lostReport { get; set; }
        @AuraEnabled
        public list<LostBrand> LostBrands { get; set; }
        @AuraEnabled
        public list<ProcessInstanceHistory> approvalHistorys { get; set; }
        public LostReport(){
            lostReport = new Lost_cancel_report__c();
            LostBrands = new list<LostBrand> {new LostBrand(0)};
            approvalHistorys = new list<ProcessInstanceHistory>();
        }
        public LostReport(Lost_cancel_report__c lostReport){
            this.lostReport = lostReport;
            LostBrands = new list<LostBrand> {new LostBrand(0)};
            approvalHistorys = new list<ProcessInstanceHistory>();
        }
        public LostReport(Lost_cancel_report__c lostReport,  list<LostBrand> LostBrands){
            this.lostReport = lostReport;
            this.LostBrands = LostBrands;
            approvalHistorys = new list<ProcessInstanceHistory>();
        }
    }
 
    public class LostBrand {
        @AuraEnabled
        public PCLLostBrand__c lostBrand;
        @AuraEnabled
        public Integer lineNo;
        @AuraEnabled
        public list<PCLLostProducts> LostProducts;
        @AuraEnabled
        public Integer ProductSize;
        @AuraEnabled
        public Boolean reasonFlag = false;
        @AuraEnabled
        public String brandTitle; 
        public LostBrand( integer lineNo ){
            lostBrand = new PCLLostBrand__c();
            this.lineNo = lineNo;
            this.brandTitle = '失单品牌' + (lineNo + 1);
            LostProducts = new list<PCLLostProducts> {new PCLLostProducts()};
            ProductSize = 1;
            lostBrand = new PCLLostBrand__c();
        }
        public LostBrand( integer lineNo, list<PCLLostProducts> LostProducts ){
            lostBrand = new PCLLostBrand__c();
            this.lineNo = lineNo;
            this.brandTitle = '失单品牌' + (lineNo + 1);
            this.LostProducts = LostProducts;
            ProductSize = LostProducts.size();
        }
        public LostBrand( integer lineNo, list<PCLLostProducts> LostProducts,  PCLLostBrand__c lostBrand){
            this.lostBrand = lostBrand;
            this.lineNo = lineNo;
            this.brandTitle = '失单品牌' + (lineNo + 1);
            this.LostProducts = LostProducts;
            ProductSize = LostProducts.size();
        }
    }
    // add tcm 20211119 start
    public class PCLLostProducts {
        @AuraEnabled
        public Integer lineNo2;
        @AuraEnabled
        public PCLLostProduct__c LostProductss;
        @AuraEnabled
        public Boolean bool;
        @AuraEnabled
        public String productName;
        @AuraEnabled
        public List<Map<String, String>> productOptions = new List<Map<String, String>>();
        public PCLLostProducts() {
            this.lineNo2 = 0;
            this.LostProductss=new PCLLostProduct__c();
        }
 
        public PCLLostProducts(Integer lineNo2) {
            this.lineNo2 = lineNo2;
            this.LostProductss=new PCLLostProduct__c();
        }
 
        public PCLLostProducts(Integer lineNo2,PCLLostProduct__c LostProductss) {
            this.lineNo2 = lineNo2;
            this.LostProductss=LostProductss;
            if (LostProductss.LostProduct__c != null) {
                this.bool = true;
            }
        }
    }
    
}