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
@isTest
private class setOrderShareBatchTest {
    static testMethod void testMethod1() {
        Id pricebookId = Test.getStandardPricebookId();
        Pricebook2 pricebook = new Pricebook2(
            Name = 'IE',
            ProductSegment__c = 'IE',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine',
            isActive = true
        );
        insert pricebook;
        Product2 product1 = new Product2();
        product1.Name = 'product1';
        Product2 product2 = new Product2();
        product2.Name = 'product2';
        Product2 product3 = new Product2();
        product3.Name = 'product3';
        insert new Product2[] {product1,product2,product3};
        PricebookEntry standardPrice1 = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = product1.Id,
            UnitPrice = 0,
            IsActive = true,
            CurrencyIsoCode = 'CNY'
        );
        PricebookEntry standardPrice2 = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = product2.Id,
            UnitPrice = 0,
            IsActive = true,
            CurrencyIsoCode = 'CNY'
        );
        PricebookEntry standardPrice3 = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = product3.Id,
            UnitPrice = 0,
            IsActive = true,
            CurrencyIsoCode = 'CNY'
        );
        insert new PricebookEntry[] {standardPrice1,standardPrice2,standardPrice3};
        PricebookEntry entry1 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product1.Id);
        entry1.UnitPrice = 0;
        entry1.IsActive = true;
        entry1.UseStandardPrice = false;
        entry1.CurrencyIsoCode = 'CNY';
        PricebookEntry entry2 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product2.Id);
        entry2.UnitPrice = 0;
        entry2.IsActive = true;
        entry2.UseStandardPrice = false;
        entry2.CurrencyIsoCode = 'CNY';
        PricebookEntry entry3 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product3.Id);
        entry3.UnitPrice = 0;
        entry3.IsActive = true;
        entry3.UseStandardPrice = false;
        entry3.CurrencyIsoCode = 'CNY';
        insert new PricebookEntry[] {entry1,entry2,entry3};
        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer BS'];
        Account accIE = new Account(
            Name = '*',
            RecordTypeId = rectIE[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c='Customer IE',
            FacilityName__c='abc',
            PostCode__c = '123456',
            DummyDealer__c = true
        );
        insert accIE; 
         List<RecordType> rectDealer = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Dealer'];
    //    List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer BS'];
 
        Account buyer = new Account(
            Name = '*',
            FacilityName__c = 'buyer',
            PostCode__c = '123456',
            RecordTypeId = rectDealer[0].Id,
            ProductSegment__c = 'BS',
            DummyDealer__c = true
        );
 
        Contact con = new Contact();
        con.LastName = 'test';
        con.AccountId = accIE.Id;
        con.MobilePhone = 'MobilePhoneD__c';
        con.OtherPhone = 'OtherPhoneD__c';
        con.Fax = 'FaxD__c';
        con.Email = 'EmailD__c@test.com';
        con.Phone = 'PhoneD__c';
        con.Title = 'TitleD__c';
        con.Address1__c = 'Address1D__c';
        con.Address2__c = 'Address2D__c';
        con.Address3__c = 'Address3D__c';
        con.Postcode__c = '100111';
        con.ContactStatus__c = 'ContactStatusD__c';
        con.CancelReason__c = 'CancelReasonD__c';
        con.StatusD__c = 'Pass';
 
        insert con;
        Date day1 = Date.today();
        List<RecordType> rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity'];
        // 有预定下单日
        Opportunity opp = new Opportunity();
        opp.Name = 'test opp';
        opp.AccountId = accIE.Id;
        opp.Dealer__c = buyer.Id;
        opp.RecordTypeId = rectOpp[0].Id;
        opp.OwnerId = UserInfo.getUserId();
        opp.StageName = 'Phase3';
        opp.CurrencyIsoCode = 'CNY';
        opp.ProductSegment__c = 'IE';
        opp.CloseDate = Date.today();
        opp.NewInquiryDate__c = Date.today().addDays(-2);
        opp.ExpectedOrderDate__c = Date.today().addDays(2);
        opp.ApprovalStatus_D__c = 'Pass';
        opp.LeadSource = 'LeadSource_D__c';
        opp.BudgetAmount__c = 111;
        opp.CancelReasonText__c = 'Cancel_Reason_Text_D__c';
        opp.CancelReason__c = 'Cancel_reason_D__c';
        opp.CompetitorCompany__c = 'Competitor_Company_D__c';
        opp.Competitor_Product__c = 'Competitor_Product_D__c';
        opp.Competitor_Product2__c = 'Competitor_Product2_D__c';
        opp.Competitor_Product3__c = 'Competitor_Product3_D__c';
        opp.Competitor_Product4__c = 'Competitor_Product4_D__c';
        opp.Competitor_Product5__c = 'Competitor_Product5_D__c';
        opp.Competitor_Product6__c = 'Competitor_Product6_D__c';
        opp.Competitor_Product7__c = 'Competitor_Product7_D__c';
        opp.Competitor_Product8__c = 'Competitor_Product8_D__c';
        opp.CompetitorProductCode__c = 'Competitor_Product_Code_D__c';
        opp.CompetitorProductCode2__c = 'Competitor_Product_Code2_D__c';
        opp.CompetitorProductCode3__c = 'Competitor_Product_Code3_D__c';
        opp.CompetitorProductCode4__c = 'Competitor_Product_Code4_D__c';
        opp.CompetitorProductCode5__c = 'Competitor_Product_Code5_D__c';
        opp.CompetitorProductCode6__c = 'Competitor_Product_Code6_D__c';
        opp.CompetitorProductCode7__c = 'Competitor_Product_Code7_D__c';
        opp.CompetitorProductCode8__c = 'Competitor_Product_Code8_D__c';
        opp.DealerSalesStaffName__c = 'Dealer_Sales_Staff_Name_D__c';
        opp.DealerService__c = 'Dealer_Service_D__c';
        opp.ExpectedDeliveryDate__c = day1;
        opp.InquiryResult__c = 'InquiryResultD__c';
        //opp.InquiryResultCancel__c = day1;
        //opp.InquiryResultLost__c = day1;
        opp.InquiryResultOrder__c = day1;
        opp.LostAmount__c = 111;
        opp.LostCompetitorProduct__c = 'Lost_competitor_product_D__c';
        opp.LostReasonText__c = 'LostReasonText_D__c';
        opp.LostReason__c = 'Lostreason_D__c';
        opp.Phase1Date__c = day1;
        opp.Phase2Date__c = day1;
        opp.Phase3Date__c = day1;
        opp.SalesChannel__c = 'Sales_Channel_D__c';
        //opp.SalesChannel__c = 'direct';
        //opp.Machine_Parts__c = 'Parts';
 
        opp.SubDealer__c = 'Sub_Dealer_D__c';
        opp.TradeType__c = 'Trade_Type_D__c';
        //opp.Pricebook2Id = pricebook.Id;
 
        insert opp;
 
        OpportunityContactRole role = new OpportunityContactRole(
            Role  = 'End user',
            IsPrimary = true,
            OpportunityId = opp.Id,
            ContactId = con.Id
            );
        insert role;
         Quote quo = new Quote(
            Name = 'quo',
            OpportunityId = opp.Id,
            //Pricebook2Id = pricebook.Id,
            SetName1__c = 'setname1',
            SetQty1__c = 1,
            SetName2__c = 'setname2',
            SetQty2__c = 2,
            Custom_Price_Total_Text__c = 1000
            //IsSyncing = true
        );
        insert quo;
 
        opp.SyncedQuoteId = quo.Id;
        update opp;
 
        List<productSet__c>  insertproductSets = new  List<productSet__c>();
        productSet__c proSet1 = new productSet__c();
        proSet1.Code__c = 'IXP-7P2';
        proSet1.Name = 'IXP-7P2';
        proSet1.IsValid__c = true;
        proSet1.Name = 'IXP-7P2';
        insertproductSets.add(proSet1);
        productSet__c proSet2 = new productSet__c();
        proSet2.Code__c = 'IXP-7P1SC';
        proSet2.Name = 'IXP-7P1SC';
        proSet2.IsValid__c = true;
        proSet2.Name = 'IXP-7P1SC';
        insertproductSets.add(proSet2);
        productSet__c proSet3 = new productSet__c();
        proSet3.Code__c = 'IXSP-T7LED';
        proSet3.Name = 'IXSP-T7LED';
        proSet3.IsValid__c = true;
        proSet3.Name = 'IXSP-T7LED';
        insertproductSets.add(proSet3);
 
 
        insert insertproductSets;
        User user = new User();
        user.LastName = 'testAccount';
        user.FirstName = 'test';
        user.Alias = '2105';
        user.Email = 'testAccount@test.com';
        user.Username = 'testAccount@test222.com';
        user.CommunityNickname = 'testAccount';
        user.IsActive = true;
        user.EmailEncodingKey = 'ISO-2022-JP';
        user.TimeZoneSidKey = 'Asia/Tokyo';
        user.LocaleSidKey = 'ja_JP';
        user.LanguageLocaleKey = 'ja';
        user.ProfileId = System.Label.SystemAdmin;
        insert user;
 
        AccountTeamMember atm = new AccountTeamMember();
        atm.accountId = accIE.Id;
        atm.userId = user.Id;//'005280000071H0s';
        atm.teamMemberRole = 'Sales Manager';
        atm.ACCOUNTACCESSLEVEL = 'Edit';
        atm.CONTACTACCESSLEVEL = 'Edit';
        atm.OPPORTUNITYACCESSLEVEL = 'None';
        atm.CASEACCESSLEVEL = 'None';
        upsert atm;
 
        List<RecordType> rectOrder = [select id from RecordType where IsActive = true and SobjectType = 'Order'];
        Order odr = new Order(
            Name = '',
            Status = 'Draft',
            AccountId = accIE.Id,
            ApproveStatus__c = 'Draft',
            OpportunityId = opp.Id,
            EffectiveDate = Date.today(),
            RecordTypeId = '01228000000NJt6',
            confirm__c = false,
            SP_21__c = true,
            EndUser__c = con.Id
        );
        insert odr;
        Order odr1 = new Order(
            Name = '',
            Status = 'Draft',
            AccountId = accIE.Id,
            ApproveStatus__c = 'Draft',
            OpportunityId = opp.Id,
            EffectiveDate = Date.today(),
            RecordTypeId = '01228000000NJt6',
            confirm__c = false,
            SP_21__c = true,
            EndUser__c = con.Id
        );
        insert odr1;
        List<String> orderIdList = new List<String>();
        orderIdList.add(odr.Id);
        database.executebatch(new setOrderShareBatch(),10);
        database.executebatch(new setOrderShareBatch(true),10);
        database.executebatch(new setOrderShareBatch(orderIdList),10);
    }
 
    @isTest static void test_method_one() {
        String CRON_EXP = '0 0 0 3 9 ? 2022';
        System.Test.startTest();
        String jobId = system.schedule('setOrderShareBatchScheduleTest', CRON_EXP, new setOrderShareBatchSchedule());
        
        System.Test.StopTest();
    }
}