高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
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
@isTest
private class OpportunityTriggerTest {
 
  @isTest static void test_method_one() {
 
    User user = new User(Test_staff__c = true);
        user.LastName = '_サンブリッジ';
        user.FirstName = 'う';
        user.Alias = 'う';
        user.Email = 'olympusTest03@sunbridge.com';
        user.Username = 'olympusTest03@sunbridge.com';
        user.CommunityNickname = 'う';
        user.IsActive = true;
        user.EmailEncodingKey = 'ISO-2022-JP';
        user.TimeZoneSidKey = 'Asia/Tokyo';
        user.LocaleSidKey = 'ja_JP';
        user.LanguageLocaleKey = 'ja';
        user.ProfileId = System.Label.ProfileId_SystemAdmin;
        user.Job_Category__c = '销售推广';
        user.Province__c = '上海市';
        user.Use_Start_Date__c = Date.today().addMonths(-6);
        user.SalesManager__c = UserInfo.getUserId();
        user.BuchangApprovalManagerSales__c = UserInfo.getUserId();
        user.JingliApprovalManager__c = UserInfo.getUserId();
        user.BuchangApprovalManager__c = UserInfo.getUserId();
        user.ZongjianApprovalManager__c = UserInfo.getUserId();
 
    List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            return;
        }
 
 
        StaticParameter.EscapeOpportunityBefUpdTrigger = true;
        StaticParameter.EscapeSyncOpportunityTrigger = true;
        StaticParameter.EscapeNFM007Trigger = true;
        StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true;
        StaticParameter.EscapeSyncOpportunityTrigger = true;
 
        System.runAs(new User(Id = Userinfo.getUserId())) {
            insert user;
        // テストデータ
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name         = 'NFM007TestCompany';
        upsert company;
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM007TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
 
        Opportunity opp = new Opportunity();
        opp.AccountId           = depart.Id;
        opp.Department_Class__c = section.Id;
        opp.Hospital__c         = company.Id;
        opp.SAP_Send_OK__c      = false;
        opp.Name                = 'GZ-SP-NFM007_1';
        opp.Trade__c            = '内貿';
        opp.StageName           = '引合';
        opp.CloseDate           = date.newinstance(2022, 11, 30);
        opp.Stock_apply_status__c = '申请中';
        insert opp;
 
        System.Test.startTest();
 
        Opportunity_File__c ofile = new Opportunity_File__c();
        ofile.Name = 'test file';
        ofile.Opportunity__c = opp.Id;
        insert ofile;
 
        Attachment att = new Attachment(
            Name = 'ORDER-123456.pdf',
            parentId = ofile.Id,
            Body = EncodingUtil.base64Decode('test')
        );
        insert att;
        
        Opportunity_File__c ofile2 = new Opportunity_File__c();
        ofile2.Name = 'test file2';
        ofile2.Opportunity__c = opp.Id;
        insert ofile2;
 
        Attachment att2 = new Attachment(
            Name = 'ORDER-123456.pdf',
            parentId = ofile2.Id,
            Body = EncodingUtil.base64Decode('test')
        );
        insert att2;
        
        delete ofile2;
        delete att;
 
        opp.Stock_apply_status__c = '批准';
        update opp;
 
        List<Opportunity_File__c> checkList = [select id, Is_Locked__c from Opportunity_File__c where id = :ofile.Id];
        System.assertEquals(true, checkList[0].Is_Locked__c);
 
        Attachment att3 = new Attachment(
            Name = 'ORDER-123456.pdf',
            parentId = company.Id,
            Body = EncodingUtil.base64Decode('test')
        );
        insert att3;
        delete att3;
        
        Rental_Apply__c rentalApply = new Rental_Apply__c();
        // '引当完了' -> 已批准
        rentalApply.Status__c = FixtureUtil.raStatusMap.get(FixtureUtil.RaStatus.Yi_Pi_Zhun.ordinal());
        // rentalApply.applyUser__c = UserInfo.getUserId();
        rentalApply.applyUser__c = user.Id;
        rentalApply.direct_send__c = '直送';
        rentalApply.direct_shippment_address__c = 'test';
        rentalApply.Request_return_day__c = Date.today() + 30;
 
        rentalApply.demo_purpose1__c = '其他';
        rentalApply.demo_purpose2__c = '其他';
        /* 这个用户没权限 用它赋值会造成报错  暂时注释掉 精琢技术 wql 2021/05/26 */
        //rentalApply.Person_In_Charge__c = user.Id;
        rentalApply.Hope_Lonaer_date_Num__c = 6;
        insert rentalApply;
        
        Attachment att4 = new Attachment(
            Name = 'ORDER-123456.pdf',
            parentId = rentalApply.Id,
            Body = EncodingUtil.base64Decode('test')
        );
        insert att4;
        delete att4;
        
        Consumable_order__c co = new Consumable_order__c();
        insert co;
        
        Attachment att5 = new Attachment(
            Name = 'ORDER-123456.pdf',
            parentId = co.Id,
            Body = EncodingUtil.base64Decode('test')
        );
        insert att5;
        //delete att5;
        
        System.Test.stopTest();
    }
}
 
  @isTest static void test_Change_Quote() {
    List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            return;
        }
 
        // テストデータ
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name         = 'NFM007TestCompany';
        upsert company;
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM007TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
 
        //販売店
        RecordType recHanbaiten = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name='販売店' limit 1];
        Account sellerA = new Account(Name = '販売店A');
        sellerA.RecordTypeId = recHanbaiten.id;
        sellerA.Delete_Flag__c = false;
        insert sellerA;
 
        Account sellerB = new Account(Name = '販売店B');
        sellerB.RecordTypeId = recHanbaiten.id;
        sellerB.Delete_Flag__c = false;
        insert sellerB;
 
        Oly_TriggerHandler.bypass('PowerBIBaseHandler');
        StaticParameter.EscapeSyncOpportunityTrigger = true;
        StaticParameter.EscapeNFM007Trigger = true;
        StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true;
        Oly_TriggerHandler.bypass('AgencyOppUpdHandler');
        StaticParameter.EscapeSyncOpportunityTrigger = true;
 
        System.Test.startTest();
 
        Opportunity opp = new Opportunity();
        opp.AccountId           = depart.Id;
        opp.Department_Class__c = section.Id;
        opp.Hospital__c         = company.Id;
        opp.SAP_Send_OK__c      = false;
        opp.Name                = 'GZ-SP-NFM007_1';
        opp.Trade__c            = '内貿';
        opp.StageName           = '引合';
        opp.CloseDate           = date.newinstance(2022, 11, 30);
        opp.Stock_apply_status__c = '申请中';
        insert opp;
 
        Quote q = new Quote(
            Name = 'quote',
            OpportunityId = opp.Id,
            Agency1__c = sellerA.Id,
            Quote_No__c = 'Quote_No_1'
        );
        insert q;
 
        opp.Agency1__c = sellerA.Id;
        opp.Estimation_No__c = q.Quote_No__c;
        update opp;
 
        opp.Agency1__c = sellerB.Id;
        update opp;
        
        System.Test.stopTest();
  }
 
  //2021-05-13 mzy  QLM
  @isTest static void test_Change_Opp() {
    List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            return;
        }
 
        // テストデータ
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name         = 'NFM007TestCompany';
        upsert company;
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM007TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
 
        //販売店
        RecordType recHanbaiten = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name='販売店' limit 1];
        Account sellerA = new Account(Name = '販売店A');
        sellerA.RecordTypeId = recHanbaiten.id;
        sellerA.Delete_Flag__c = false;
        insert sellerA;
 
        Account sellerB = new Account(Name = '販売店B');
        sellerB.RecordTypeId = recHanbaiten.id;
        sellerB.Delete_Flag__c = false;
        insert sellerB;
 
        Oly_TriggerHandler.bypass('PowerBIBaseHandler');
        StaticParameter.EscapeSyncOpportunityTrigger = true;
        StaticParameter.EscapeNFM007Trigger = true;
        StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true;
        Oly_TriggerHandler.bypass('AgencyOppUpdHandler');
        StaticParameter.EscapeSyncOpportunityTrigger = true;
 
        System.Test.startTest();
 
        //win
        Opportunity opp1 = new Opportunity(
            Name = 'test opp1',
            StageName = '完了',
            CurrencyIsoCode = 'USD',
            CloseDate = Date.today(),
            AccountId = depart.Id,
            Closing_Bid_Date__c = Date.today().addDays(-5),
            Hospital__c = company.Id,
            Competitor__c = 'A'
        );
        insert opp1;
 
        opp1.SAP_Send_OK__c = true;
        opp1.Authorized_DB_No__c = '123';
        opp1.Contract_DB_SalesDept_complite_day__c = Date.today();
        opp1.NotesApprovedNo__c = '123';
        update opp1;
 
        //招标项目
        Tender_information__c te1 = new Tender_information__c();
        te1.Name = 'TestZhaoBiao';
        insert te1;
 
        opp1.Bidding_Project_Name_Bid__c = te1.Id;
        update opp1;
 
        //失单
        opp1.StageName = '敗戦';
        update opp1;
 
 
 
        //新建询价时,赋值招投标项目,打上标识
        Opportunity opp2 = new Opportunity(
            Name = 'test opp1',
            StageName = '引合',
            CurrencyIsoCode = 'USD',
            CloseDate = Date.today(),
            AccountId = depart.Id,
            Closing_Bid_Date__c = Date.today().addDays(-5),
            Hospital__c = company.Id,
            Competitor__c = 'A',
            Bidding_Project_Name_Bid__c = te1.Id
        );
        insert opp2;
 
 
        System.Test.stopTest();
 
  }
  //2021-05-13 mzy  QLM
 
}