高章伟
2022-03-10 1312ba82d4c880bdb5357d28e0d4af5b285f610f
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
@isTest
private class OrdergoodsControllerTest {
    public String ProModel;
    static testMethod void testMethod1() {
        // 客户记录类型
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '办事处'];
        if (rectCo.size() == 0) {
            throw new ControllerUtil.myException('not found 办事处 recodetype');
        }
        Account account2 = new Account();
        account2.Name = 'test1经销商';
        account2.RecordTypeId = '01210000000Qem1';
        insert account2;
        // 客户
        Account account = new Account();
        account.RecordTypeId = rectCo[0].Id;
        account.Phone = '13888888888';
        account.Name = 'Katsu テスト';
        account.Quolified_Approve_Status__c = 'Draft';
        account.If_Need_Quolified__c = true;
        account.ParentId = account2.Id;
        insert account;
 
        Product2 product = new Product2();
        product.Name = 'test01';
        product.ProductCode = 'n011';
        product.Packing_list_manual__c = 5;
        product.SFDA_Expiration_Date__c = Date.today().addDays(1);
        product.Asset_Model_No__c = 'n01';
        product.Whether_Sample__c = true;
        product.StorageStatusNo__c = 10;
        product.SFDA_Status__c = '有効';
        insert product;
        product.StorageStatusNo__c = 20;
        update product;
        Product2 product1 = new Product2();
        product1.Name = 'test012';
        product1.ProductCode = 'n01112';
        product1.Packing_list_manual__c = 5;
        product1.SFDA_Expiration_Date__c = Date.today().addDays(1);
        product1.Asset_Model_No__c = 'n011';
        product1.Whether_Sample__c = true;
        product1.StorageStatusNo__c = 10;
        product1.SFDA_Status__c = '有効';
        insert product1;
        product1.StorageStatusNo__c = 20;
        update product1;
        Product2 product2 = new Product2();
        product2.Name = 'test01222';
        product2.ProductCode = 'n0111212';
        product2.Packing_list_manual__c = 5;
        product2.SFDA_Expiration_Date__c = Date.today().addDays(1);
        product2.Asset_Model_No__c = 'n0311';
        product2.Whether_Sample__c = true;
        product2.StorageStatusNo__c = 10;
        product2.SFDA_Status__c = '有効';
        insert product2;
        product2.StorageStatusNo__c = 20;
        update product2;
 
        // 订货单
        Sample_order_list__c samOrder = new Sample_order_list__c();
        samOrder.Status__c          = ''; 
        samOrder.DeliveryAddress__c = '';
        samOrder.DeliveryPhone__c   = '12312312';
        samOrder.DeliveryContact__c = 'thh';
        samOrder.ReceivePart__c     = '办事处';
        samOrder.Account__c         = account.Id;
        insert samOrder;
        Sample_order_list__c samOrder2 = new Sample_order_list__c();
        samOrder2.Status__c          = ''; 
        samOrder2.DeliveryAddress__c = '123213';
        samOrder2.DeliveryPhone__c   = '';
        samOrder2.DeliveryContact__c = 'thh';
        samOrder2.ReceivePart__c     = '办事处';
        samOrder2.Account__c         = account.Id;
        insert samOrder2;
        Sample_order_list__c samOrder3 = new Sample_order_list__c();
        samOrder3.Status__c          = ''; 
        samOrder3.DeliveryAddress__c = '123213';
        samOrder3.DeliveryPhone__c   = '12312312';
        samOrder3.DeliveryContact__c = '';
        samOrder3.ReceivePart__c     = '办事处';
        samOrder3.Account__c         = account.Id;
        insert samOrder3;
        Sample_order_list__c samOrder1 = new Sample_order_list__c();
        samOrder1.Status__c          = '暂存'; 
        samOrder1.DeliveryAddress__c = '12312';
        samOrder1.DeliveryPhone__c   = '12312312';
        samOrder1.DeliveryContact__c = 'thh';
        samOrder1.ReceivePart__c     = '办事处';
        samOrder1.Account__c         = account.Id;
        insert samOrder1;
 
        // 订货单明细
        Sample_order_list_detail__c samDetail = new Sample_order_list_detail__c();
        samDetail.Product__c           = product.Id;
        samDetail.Pro_model__c         = 'n01';
        samDetail.ItemQuantity__c      = 100;
        samDetail.Standards__c         = 1;
        samDetail.Sample_order_list__c = samOrder.Id;
        insert samDetail;
        Sample_order_list_detail__c samDetail1 = new Sample_order_list_detail__c();
        samDetail1.Product__c           = product1.Id;
        samDetail1.Pro_model__c         = 'n011';
        samDetail1.ItemQuantity__c      = 100;
        samDetail1.Standards__c         = 1;
        samDetail1.Sample_order_list__c = samOrder1.Id;
        insert samDetail1;
 
        // 页面获取的订货单Id
        PageReference ref1 = new PageReference('/apex/Ordergoods?id=' + samOrder.id);
        Test.setCurrentPage(ref1);
        OrdergoodsController controller1 = new OrdergoodsController(new ApexPages.StandardController(samOrder));
        controller1.init();
        controller1.save();
        controller1.confirmBtn();
        PageReference ref3 = new PageReference('/apex/Ordergoods?id=' + samOrder2.id);
        Test.setCurrentPage(ref3);
        OrdergoodsController controller3 = new OrdergoodsController(new ApexPages.StandardController(samOrder2));
        controller3.init();
        controller3.save();
        PageReference ref4 = new PageReference('/apex/Ordergoods?id=' + samOrder3.id);
        Test.setCurrentPage(ref4);
        OrdergoodsController controller5 = new OrdergoodsController(new ApexPages.StandardController(samOrder3));
        controller5.init();
        controller5.save();
        PageReference ref2 = new PageReference('/apex/Ordergoods?id=' + samOrder1.id);
        Test.setCurrentPage(ref2);
        OrdergoodsController controller2 = new OrdergoodsController(new ApexPages.StandardController(samOrder1));
        controller2.init();
        controller2.save();
        controller2.confirmBtn();
 
        // 页面获取的客户Id
        PageReference ref = new PageReference('/apex/Ordergoods?accid=' + account.id);
        Test.setCurrentPage(ref);
        OrdergoodsController controller = new OrdergoodsController(new ApexPages.StandardController(samOrder));
        controller.init();
        //controller.productInfoList[0].check = true;
        //controller.productInfoList[0].SOLDel.ItemQuantity__c = 5;
        // controller.save();
        // controller.confirmBtn();
        //controller.productInfoList = new List<OrdergoodsController.ProductInfo>();
        // controller.productInfoList.add(new OrdergoodsController.ProductInfo(0,product)); 
    }
 
    static testMethod void testMethod2() {
        // 客户记录类型
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '办事处'];
        if (rectCo.size() == 0) {
            throw new ControllerUtil.myException('not found 办事处 recodetype');
        }
        // 客户
        Account account2 = new Account();
        account2.Name = 'test1经销商';
        account2.RecordTypeId = '01210000000Qem1';
        insert account2;
        Account account = new Account();
        account.RecordTypeId = rectCo[0].Id;
        account.Phone = '13888888888';
        account.Name = 'Katsu テスト';
        account.Quolified_Approve_Status__c = 'Draft';
        account.If_Need_Quolified__c = true;
        account.ParentId = account2.Id;
        insert account;
        //查不出任何样本品,SFDA_Status__c会被触发器修改为停止
        Product2 product = new Product2();
        product.Name = 'test01';
        product.ProductCode = 'n011';
        product.Packing_list_manual__c = 5;
        product.SFDA_Expiration_Date__c = Date.today().addDays(1);
        product.Asset_Model_No__c = 'n01';
        product.Whether_Sample__c = true;
        product.StorageStatusNo__c = 10;
        product.SFDA_Status__c = '有効';
        insert product;
        product.StorageStatusNo__c = 20;
        update product;
 
        Sample_order_list__c samOrder = new Sample_order_list__c();
        samOrder.Status__c          = '暂存'; 
        samOrder.DeliveryAddress__c = '12332';
        samOrder.DeliveryPhone__c   = '12312312';
        samOrder.DeliveryContact__c = 'thh';
        samOrder.ReceivePart__c     = '办事处';
        samOrder.Account__c         = account.Id;
        insert samOrder;
 
        //选中保存
        Sample_order_list_detail__c samDetail = new Sample_order_list_detail__c();
        samDetail.Product__c           = product.Id;
        samDetail.Pro_model__c         = 'n01';
        // samDetail.ItemQuantity__c      = 100;
        samDetail.Standards__c         = 1;
        samDetail.Sample_order_list__c = samOrder.Id;
        insert samDetail;
 
        PageReference ref2 = new PageReference('/apex/Ordergoods?id=' + samOrder.id);
        Test.setCurrentPage(ref2);
        OrdergoodsController controller2 = new OrdergoodsController(new ApexPages.StandardController(samOrder));
        controller2.init();
        controller2.save();
        controller2.confirmBtn();
    }
}