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
@isTest
private class QuoteTriggerTest {
 
    @isTest static void test_method_one() {
        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        Account accIE = new Account(
            Name = '*',
            RecordTypeId = rectIE[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c='Customer BS',
            FacilityName__c='abc',
            PostCode__c = '123456'
        );
        insert accIE;
 
        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;
 
        User user = new User();
        user.LastName = 'test';
        user.FirstName = 'test';
        user.Alias = 'test';
        user.Email = 'test@test.com';
        user.Username = 'test111@test222.com';
        user.CommunityNickname = 'test20201015';
        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;
 
        User user2 = new User();
        user2.LastName = 'test2';
        user2.FirstName = 'test2';
        user2.Alias = 'test2';
        user2.Email = 'test2@test2.com';
        user2.Username = 'test222@test233666.com';
        user2.CommunityNickname = 'test2';
        user2.IsActive = true;
        user2.EmailEncodingKey = 'ISO-2022-JP';
        user2.TimeZoneSidKey = 'Asia/Tokyo';
        user2.LocaleSidKey = 'ja_JP';
        user2.LanguageLocaleKey = 'ja';
        user2.ProfileId = System.Label.RT_BS_No_Price;
        user2.ContactId = con.Id;
        insert user2;
 
        PriceBook2 pricebook =new PriceBook2(
            Name = 'IE',
            ProductSegment__c = 'BS',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine'
        );
        insert pricebook;
 
        List<RecordType> rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity'];
        Opportunity opp = new Opportunity(
            Name = 'test opp',
            AccountId = accIE.Id,
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            StageName = 'Prospect Created',
            CancelReason__c = 'Inquiry repeat',
            Cancel_reason_D__c = 'Inquiry repeat',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'BS',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            Machine_Parts__c = 'Machine'
        );
        insert opp;
 
        OpportunityTeamMember otm1 = new OpportunityTeamMember();
        otm1.opportunityId = opp.Id;
        otm1.userId = user.Id;
        otm1.teamMemberRole = 'Sales Manager';
        insert otm1;
 
        OpportunityTeamMember otm2 = new OpportunityTeamMember();
        otm2.opportunityId = opp.Id;
        otm2.userId = user2.Id;
        otm2.teamMemberRole = 'Sales Manager';
        insert otm2;
 
        List<OpportunityTeamMember> otmList = [select Id from OpportunityTeamMember where opportunityId = :opp.Id];
        System.assertEquals(2, otmList.size());
 
        Quote quo = new Quote(
            Name = 'quo',
            OpportunityId = opp.Id,
            Pricebook2Id = pricebook.Id,
            PaymentTerms__c = 'ZZTT'
        );
        insert quo;
 
        List<OpportunityTeamMember> otmList2 = [select Id from OpportunityTeamMember where opportunityId = :opp.Id];
        //System.assertEquals(1, otmList2.size());
 
        quo.PaymentTerms__c = 'Z9TT';
 
        update quo;
    }
 
   
      @isTest static void test_init1() {
        Id pricebookId = Test.getStandardPricebookId();
 
        Pricebook2 pricebook = new Pricebook2(
            Name = 'BS',
            ProductSegment__c = 'BS',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine',
            isActive = true
        );
        insert pricebook;
 
        Product2 product1 = new Product2();
        product1.Name = 'product1';
        product1.ProductCode = 'N5679000';
        product1.Product_ECCode__c = 'product1';
        product1.IsActive = true;
 
        Product2 product2 = new Product2();
        product2.Name = 'product2';
        product2.ProductCode = 'product2';
        product2.Product_ECCode__c = 'product2';
        product2.IsActive = true;
 
        Product2 product3 = new Product2();
        product3.Name = 'product3';
        product3.ProductCode = 'product3';
        product3.Product_ECCode__c = 'product3';
        product3.IsActive = true;
 
        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,
            UnitPrice = 30,
            IsActive = true,
            UseStandardPrice = false,
            CurrencyIsoCode = 'CNY'
        );
 
        PricebookEntry entry2 = new PricebookEntry(
            Pricebook2Id = pricebook.Id,
            Product2Id = product2.Id,
            UnitPrice = 30,
            IsActive = true,
            UseStandardPrice = false,
            CurrencyIsoCode = 'CNY'
        );
 
        PricebookEntry entry3 = new PricebookEntry(
            Pricebook2Id = pricebook.Id,
            Product2Id = product3.Id,
            UnitPrice = 30,
            IsActive = true,
            UseStandardPrice = false,
            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 user = new Account(
            Name = '*',
            FacilityName__c = 'user',
            PostCode__c = '123456',
            RecordTypeId = rectIE[0].Id
        );
        insert user;
 
        Opportunity opp = new Opportunity(
            Name = 'test opp',
            AccountId = user.Id,
            StageName = 'Prospect Created',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'BS',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            Machine_Parts__c = 'Machine',
            Pricebook2Id = pricebook.Id
        );
        insert opp;
 
        OpportunityLineItem oli1 = new OpportunityLineItem(
            OpportunityId = opp.Id,
            PricebookEntryId = entry1.Id,
            Quantity = 1,
            UnitPrice = 30
        );
 
        OpportunityLineItem oli2 = new OpportunityLineItem(
            OpportunityId = opp.Id,
            PricebookEntryId = entry2.Id,
            Quantity = 2,
            UnitPrice = 30
        );
 
        OpportunityLineItem oli3 = new OpportunityLineItem(
            OpportunityId = opp.Id,
            PricebookEntryId = entry3.Id,
            Quantity = 3,
            UnitPrice = 30
        );
 
        insert new OpportunityLineItem[] {oli1, oli2, oli3};
 
        PageReference page = new PageReference('/apex/NewQuoteService?oppid=' + opp.Id + '&openType=service');
        System.Test.setCurrentPage(page);
        NewQuoteEntryController controller = new NewQuoteEntryController();
 
        controller.init();
 
        controller.quo.Name = '报价1';
        controller.quo.PaymentTerms__c = 'Z0LC';
        controller.quo.Shipment_Term__c = 'CIP';
        controller.quo.Shipment_Term2__c = 'BEIJING';
        controller.quo.DeliveryLeadTime__c = 90;
        controller.quo.Warranty__c = 1;
        controller.quo.ExpirationDate = Date.today();
        controller.quo.Custom_Price_Total_Text__c = 1000;
 
/*        controller.activities[0].pageObject.PricebookEntryId = entry1.Id;
        controller.activities[0].pageObject.Set__c = 'set01';
        controller.activities[0].pageObject.UnitPrice = 11;
        controller.activities[0].pageObject.Quantity = 1
        controller.activities[0].pageObject.Discount = 0;
        controller.activities[0].pageObject.Custom_Price__c = 20;
        controller.activities[0].pageObject.Description = 'test1';*/
        
        controller.Save();
 
        //system.assertEquals('',controller.errormessage);
 
        controller.excelImport();
 
        controller.OppReflection();
 
        controller.BackBtn();
        System.Test.StartTest();
        controller.Decide();
        List<Quote> QuoteList = [select Id from Quote]; 
        //update QuoteList[0];
        if(QuoteList.size() > 0){
            update QuoteList[0];
        }
        System.Test.StopTest();
    }
 
 
}