高章伟
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
@isTest
private class ConsumableOrdertosapTest
{
    static testMethod void ConsumableTest_updOrder(){
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectCotac = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '契約'];
        if (rectCotac.size() == 0) {
            return;
        }
        Id pricebookId = ControllerUtil.getStandardPricebook().Id;
        Profile prof = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证'];
        // 产品
        Product2 product = new Product2( Name='テスト商品');
        product.SFDA_Status__c = '有効';
        product.Intra_Trade_List_RMB_1__c = 100;
        product.Intra_Trade_List_RMB_Date1__c = date.today();
        product.Intra_Trade_Cost_RMB_1__c = 200;
        product.Intra_Trade_Cost_RMB_Date1__c = date.today();
        product.Manual_Entry__c = false;
        product.Asset_Model_No__c = '11111';
        product.ProductCode = 'OTV-SP1H-NA-12E';
        product.Product_Status__c = '正常销售';
        product.SFDA_Approbated_Status__c = '有效';
        insert product;
        // 価格表エントリを作成する
        PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=product.Id);
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = 'CNY';
        insert new PricebookEntry[] {entry};
        Product2__c pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='Test001',Product2__c = product.Id);
        insert new Product2__c[] {pro1};
        Account myAccount2 = new Account(Name='Testaccount002',Dealer_discount__c =20,RecordTypeId = rectCo[0].Id,Product_Limit_Date__c = 'Test01|2|4,Test02|3|5');
        insert myAccount2;
 
 
        Contact core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=myAccount2.id);
        insert core;
 
        //医疗器械经营许可证
        License_Information__c linc = new License_Information__c( name='Test20181204',
                                                LicenseType__c = '医疗器械经营许可证',
                                                BusinessLicense__c = '20180522',
                                                ValidFrom__c = date.newinstance(2018, 05, 22),
                                                ValidTo__c = date.newinstance(2088, 05, 22),
                                                Scope3__c = '6815;6822;6823;6825',
                                                LicenseAndAccount__c = myAccount2.Id
                                                );
        insert linc;
        //System.assertEquals('123',linc.ScopeKey__c);
        //产品注册证
        Product_Register__c prc = new Product_Register__c(Name = '国械注进20162220210',
                                                MedPrdClass__c = '3',
                                                ValidFrom__c = date.newinstance(2018, 07, 22),
                                                ValidTo__c = date.newinstance(2028, 07, 22),
                                                RegisterNoClass_Old__c = '6815',
                                                RegisterNoClass_New__c = '6815',
                                                RegisterNoStatus__c = '有效'
                                                );
        insert prc;
        //新旧关系对照表
        Product_Register_contrast__c prcc = new Product_Register_contrast__c(
                                                Name = 'Test20181204',
                                                Register_new__c = '314',
                                                Register_old__c = '36815'
                                                );
        insert prcc;
        //产品-产品注册证关系
        Product_Register_Link__c  prlc = new Product_Register_Link__c(
                                                Product2__c = product.Id,
                                                Product_Register__c = prc.Id
                                                ); 
        insert prlc;
 
 
 
        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){
             Account contact = new Account(name='Testaccount002',
                                    RecordTypeId = rectCotac[0].Id,
                                    Contract_Decide_Start_Date__c = Date.today().addDays(-1),
                                    Contract_Decide_End_Date__c =Date.today().addDays(1),
                                    Contract_Start_Date__c = Date.today().addDays(-1),
                                    Contract_End_Date__c =Date.today().addDays(1),
                                    Agent_Ref__c =myAccount2.Id,
                                    ET_SP_Dealer__c = true,
                                    ParentId =myAccount2.Id,Business_Assistant__c = UserInfo.getUserId());
            insert contact;
 
            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.Order_effective_contact__c = contact.Id;
            Order1.Consumable_pdf_insert_day__c = Date.today();
            Order1.RecordTypeid = System.Label.RT_ConOrder_Order;
            insert  Order1;
 
            List<Consumable_order__c> abc = [select Order_effective_contact__c, SalesManager__c from Consumable_order__c where Id = :Order1.Id];
            System.assertEquals(1, abc.size());
            System.assertEquals(contact.Id, abc[0].Order_effective_contact__c);
 
            //其他订单明细
            //fahuo
            Consumable_orderdetails__c Orderdet = new Consumable_orderdetails__c();
            Orderdet.Name = 'OCM_01_00101';
            Orderdet.Consumable_order__c = Order1.Id;
            Orderdet.RecordTypeId = System.Label.RT_ConOrderDetail1_Order;
            Orderdet.Consumable_Product__c = pro1.Id;
            Orderdet.Consumable_count__c = 1;
            Orderdet.Intra_Trade_List_RMB__c = 10;
            insert Orderdet;
            //Order1.Order_status__c = '已提交';
            System.Test.startTest();
            Order1.Order_status__c = '批准';
            update Order1;
            System.Test.stopTest();
        //}
    }
    static testMethod void ConsumableTest_cancelOrder(){
         StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectCotac = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '契約'];
        if (rectCotac.size() == 0) {
            return;
        }
        Id pricebookId = ControllerUtil.getStandardPricebook().Id;
        Profile prof = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证'];
        // 产品
        Product2 product = new Product2( Name='テスト商品');
        product.SFDA_Status__c = '有効';
        product.Intra_Trade_List_RMB_1__c = 100;
        product.Intra_Trade_List_RMB_Date1__c = date.today();
        product.Intra_Trade_Cost_RMB_1__c = 200;
        product.Intra_Trade_Cost_RMB_Date1__c = date.today();
        product.Manual_Entry__c = false;
        product.Asset_Model_No__c = '11111';
        product.ProductCode = 'OTV-SP1H-NA-12E';
        product.Product_Status__c = '正常销售';
        product.SFDA_Approbated_Status__c = '有效';
        insert product;
        // 価格表エントリを作成する
        PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=product.Id);
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = 'CNY';
        insert new PricebookEntry[] {entry};
        Product2__c pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='Test001',Product2__c = product.Id);
        insert new Product2__c[] {pro1};
        Account myAccount2 = new Account(Name='Testaccount002',Dealer_discount__c =20,RecordTypeId = rectCo[0].Id,Product_Limit_Date__c = 'Test01|2|4,Test02|3|5');
        insert myAccount2;
 
 
        Contact core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=myAccount2.id);
        insert core;
 
        //医疗器械经营许可证
        License_Information__c linc = new License_Information__c( name='Test20181204',
                                                LicenseType__c = '医疗器械经营许可证',
                                                BusinessLicense__c = '20180522',
                                                ValidFrom__c = date.newinstance(2018, 05, 22),
                                                ValidTo__c = date.newinstance(2088, 05, 22),
                                                Scope3__c = '6815;6822;6823;6825',
                                                LicenseAndAccount__c = myAccount2.Id
                                                );
        insert linc;
        //System.assertEquals('123',linc.ScopeKey__c);
        //产品注册证
        Product_Register__c prc = new Product_Register__c(Name = '国械注进20162220210',
                                                MedPrdClass__c = '3',
                                                ValidFrom__c = date.newinstance(2018, 07, 22),
                                                ValidTo__c = date.newinstance(2028, 07, 22),
                                                RegisterNoClass_Old__c = '6815',
                                                RegisterNoClass_New__c = '6815',
                                                RegisterNoStatus__c = '有效'
                                                );
        insert prc;
        //新旧关系对照表
        Product_Register_contrast__c prcc = new Product_Register_contrast__c(
                                                Name = 'Test20181204',
                                                Register_new__c = '314',
                                                Register_old__c = '36815'
                                                );
        insert prcc;
        //产品-产品注册证关系
        Product_Register_Link__c  prlc = new Product_Register_Link__c(
                                                Product2__c = product.Id,
                                                Product_Register__c = prc.Id
                                                ); 
        insert prlc;
 
 
 
        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;
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
        Account contact = new Account(name='Testaccount002',
                                    RecordTypeId = rectCotac[0].Id,
                                    Contract_Decide_Start_Date__c = Date.today().addDays(-1),
                                    Contract_Decide_End_Date__c =Date.today().addDays(1),
                                    Contract_Start_Date__c = Date.today().addDays(-1),
                                    Contract_End_Date__c =Date.today().addDays(1),
                                    Agent_Ref__c =myAccount2.Id,
                                    ET_SP_Dealer__c = true,
                                    ParentId =myAccount2.Id,Business_Assistant__c = UserInfo.getUserId());
            insert contact;
 
            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.Order_effective_contact__c = contact.Id;
            Order1.Consumable_pdf_insert_day__c = Date.today();
            Order1.RecordTypeid = System.Label.RT_ConOrder_Order;
            insert  Order1;
 
            List<Consumable_order__c> abc = [select Order_effective_contact__c, SalesManager__c from Consumable_order__c where Id = :Order1.Id];
            System.assertEquals(1, abc.size());
            System.assertEquals(contact.Id, abc[0].Order_effective_contact__c);
 
            //其他订单明细
            //fahuo
            Consumable_orderdetails__c Orderdet = new Consumable_orderdetails__c();
            Orderdet.Name = 'OCM_01_00101';
            Orderdet.Consumable_order__c = Order1.Id;
            Orderdet.RecordTypeId = System.Label.RT_ConOrderDetail1_Order;
            Orderdet.Consumable_Product__c = pro1.Id;
            Orderdet.Consumable_count__c = 1;
            Orderdet.Intra_Trade_List_RMB__c = 10;
            insert Orderdet;
            //system.runAs(hpOwner){
            //Order1.Order_status__c = '已提交';
            System.Test.startTest();
            Order1.Order_status__c = '批准';
            update Order1;
            Opportunity[] coc1 = [select id,Name,SAP_Send_OK__c from Opportunity];
            if(coc1.size() > 0){
                System.assertEquals(1, coc1.size());
                System.assertEquals(true, coc1[0].SAP_Send_OK__c);
                //Opportunity opp = new Opportunity();
                //opp.Id = coc1[0].Id;
                //opp.SAP_Send_OK__c = false;
                //update opp;
                //Order1.Order_status__c = '已提交';
                //update Order1;
            }
            System.Test.stopTest();
        //}
    }
}