高章伟
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
@isTest
private class ConsumableAssetHanderTest{
    static Account company;   //医院
    static Account section1;  //科室ET
    static Account agent;  //经销商
    static Account contact;  //契约
    static Account olympus;  //Olympus社内 其他 经销商资产
    static void initHpData() {
        RecordType rectagent = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        RecordType rectContract = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '契約'];
        RecordType rect9900 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 その他'];
        RecordType rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        RecordType rectDpt1 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類ET'];
        //RecordType rectDpt2 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        company = new Account(RecordTypeId = rectCo.Id, Name = 'NFM110TestCompany');
        olympus = new Account(RecordTypeId = rectCo.Id, AgentCode_Ext__c = '9999900', Name = 'olympus');
        insert new Account[] {company, olympus};
        company = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id =:company.Id];
        section1 = [select Management_Code__c, Management_Code_Auto__c, Name, Id, Department_Class_Label__c from Account where ParentId =:company.Id and RecordType.name = '戦略科室分類ET'];
        //
        agent = new Account(name='Testaccount001',
                                        Dealer_discount__c =20,
                                        Ban_On_Use_Date__c = Date.today().addDays(1),
                                        Business_Paper_Expiration_Date__c = Date.today().addDays(1),
                                        Tax_Practice_Expiration_Date__c = Date.today().addDays(1),
                                        Medical_Equipment_Expiration_Date__c = Date.today().addDays(1),
                                        RecordTypeId = rectagent.Id);
        insert agent;
        //经销商有效合同
        contact = new Account(name='Testaccount002',
                                            RecordTypeId = rectContract.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 =agent.Id,
                                            ET_SP_Dealer__c = true,
                                            ParentId =agent.Id);
        insert contact;
    }
 
 
 
    @isTest
    static void saleOrshipment(){
        initHpData();
        //产品信息
        Product2 prod01 = new Product2(Name='Test01',ProductCode='Test01',Asset_Model_No__c = 'Test01',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c=12, Manual_Entry__c = false);
        insert new Product2[]{prod01};
        Product2__c pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='Test001',Product2__c = prod01.Id);
        insert new Product2__c[] {pro1};
        //出库单信息
        Consumable_order__c saleOrder = new Consumable_order__c();
        saleOrder.Name = 'OCM_02_005';
        saleOrder.Order_status__c = '批准';
        saleOrder.Order_type__c = '传票';
        saleOrder.RecordTypeid = System.Label.RT_ConOrder_Order;
        saleOrder.Dealer_Info__c = agent.Id;
        saleOrder.Order_ForHospital__c = company.Id;
        saleOrder.SummonsForDirction__c ='直接销售给医院';
        saleOrder.IsShipment__c = true;
        insert  saleOrder;
 
        //销售
        Consumable_order_details2__c saledet1 = new Consumable_order_details2__c();
        saledet1.Name = 'OCM_01_001001';
        saledet1.Consumable_Sale_order__c = saleOrder.Id;
        saledet1.Consumable_ZS_order__c = saleOrder.Id;
        saledet1.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
        saledet1.Bar_Code__c = '0114953170032070111804001082K250BBBBB';
        saledet1.Consumable_Product__c = pro1.Id;
        saledet1.Used_account__c = contact.Id;
        saledet1.Arrive_date__c = Date.today().addDays(-1);
        saledet1.Delivery_List_RMB__c = 11;
        saledet1.Box_Piece__c = '盒';
        saledet1.TracingCode__c = 'BBBBB';
        saledet1.SerialLotNo__c = '82K';
        insert saledet1;
 
        saledet1.Used_date__c = Date.today();
 
        System.Test.startTest();
        update saledet1;
        List<asset> assList =  [select Id,SerialNumber,Hospital__r.Name from asset  where SerialNumber = '82K(BBBBB)'];
        System.assertEquals(1, assList.size());
        System.Test.stopTest();
 
    }
 
    @isTest
    static void ruturnGoodTest(){
        initHpData();
        //产品信息
        StaticParameter.EscapeConsumableOrderDetail2Trigger = true;
        Product2 prod01 = new Product2(Name='Test01',ProductCode='Test01',Asset_Model_No__c = 'Test01',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c=12, Manual_Entry__c = false);
        insert new Product2[]{prod01};
        Product2__c pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='Test001',Product2__c = prod01.Id);
        insert new Product2__c[] {pro1};
        //出库单信息
        Consumable_order__c saleOrder = new Consumable_order__c();
        saleOrder.Name = 'OCM_02_005';
        saleOrder.Order_status__c = '批准';
        saleOrder.Order_type__c = '传票';
        saleOrder.RecordTypeid = System.Label.RT_ConOrder_Order;
        saleOrder.Dealer_Info__c = agent.Id;
        saleOrder.Order_ForHospital__c = company.Id;
        saleOrder.SummonsForDirction__c ='直接销售给医院';
        saleOrder.IsShipment__c = true;
        insert  saleOrder;
 
        //销售
        Consumable_order_details2__c saledet1 = new Consumable_order_details2__c();
        saledet1.Name = 'OCM_01_001001';
        saledet1.Consumable_Sale_order__c = saleOrder.Id;
        saledet1.Consumable_ZS_order__c = saleOrder.Id;
        saledet1.Consumable_Arrived_order__c = saleOrder.Id;
        saledet1.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
        saledet1.Bar_Code__c = '0114953170032070111804001082K250BBBBB';
        saledet1.Consumable_Product__c = pro1.Id;
        saledet1.Used_account__c = contact.Id;
        saledet1.Arrive_date__c = Date.today().addDays(-1);
        saledet1.Delivery_List_RMB__c = 11;
        saledet1.Box_Piece__c = '个';
        saledet1.TracingCode__c = 'BBBBB';
        saledet1.SerialLotNo__c = '82K';
        saledet1.Used_date__c = Date.today();
        insert saledet1;
 
        saledet1.Return_date__c = Date.today();
 
        System.Test.startTest();
        update saledet1;
        List<asset> assList =  [select Id,SerialNumber,Hospital__r.Name from asset  where SerialNumber = '82K(BBBBB)'];
        System.assertEquals(1, assList.size());
        System.Test.stopTest();
 
    }
 
    @isTest
    static void arrBarcodeChangeTest(){
        initHpData();
        //产品信息
        StaticParameter.EscapeConsumableOrderDetail2Trigger = true;
        Product2 prod01 = new Product2(Name='Test01',ProductCode='Test01',Asset_Model_No__c = 'Test01',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c=12, Manual_Entry__c = false);
        insert new Product2[]{prod01};
        Product2__c pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='Test001',Product2__c = prod01.Id);
        insert new Product2__c[] {pro1};
        //订单
        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 = agent.Id;
        Order1.RecordTypeid = System.Label.RT_ConOrder_Delivery;
        Order1.Total_num__c = 3;
        Order1.OrderNumber_arrived__c =1;
        Order1.Delivery_detail_count__c=1;
        Order1.Order_ProType__c = 'ET';
        insert  Order1;
 
        //经销商到货单
 
        Consumable_order__c arriveOrder = new Consumable_order__c();
        arriveOrder.Name = 'testArrive';
        arriveOrder.Order_status__c = '批准';
        arriveOrder.Deliver_date__c = Date.today();
        arriveOrder.Dealer_Info__c = agent.Id;
        arriveOrder.RecordTypeid = System.Label.RT_ConOrder_Arrive;
        insert  arriveOrder;
 
        //fahuo
        Consumable_order_details2__c saledet1 = new Consumable_order_details2__c();
        saledet1.Name = 'OCM_01_001001';
        saledet1.Consumable_order_minor__c = Order1.Id;
        saledet1.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
        saledet1.Bar_Code__c = '0114953170032070111804001082K250BBBBB';
        saledet1.Consumable_Product__c = pro1.Id;
        saledet1.Used_account__c = contact.Id;
        saledet1.Delivery_List_RMB__c = 11;
        saledet1.Box_Piece__c = '盒';
        saledet1.TracingCode__c = 'BBBBB';
        saledet1.SerialLotNo__c = '82K';
        saledet1.Guarantee_period_for_products__c = Date.today().addDays(5);
        saledet1.Sterilization_limit__c = Date.today().addDays(5);
        insert saledet1;
 
        asset ast = new asset();
        ast.Name = 
        ast.Name                             = prod01.Name;
        ast.Product2Id                       = prod01.Id;
        ast.SerialNumber                     = saledet1.SerialLotNo__c + '(' + saledet1.TracingCode__c + ')';
        ast.SLMark__c                        = 'Serial Number';         // 固定 dnInfo.SorLMark;
        ast.Guarantee_period_for_products__c = saledet1.Guarantee_period_for_products__c;
        ast.TracingCode__c                   = saledet1.TracingCode__c;
        ast.Guaranteen_end__c                = saledet1.Sterilization_limit__c;
        ast.Barcode__c                       = saledet1.Bar_Code__c;
        ast.Product_Serial_No__c             = pro1.OT_CODE_Text__c + ':' + saledet1.SerialLotNo__c  + '(' + saledet1.TracingCode__c + ')';
        ast.Asset_Owner__c                   = '经销商资产';
        ast.AccountId                        = olympus.Id;
        ast.Department_Class__c              = contact.Id;
        ast.Asset_owner_delaer_name__c       = agent.Id;
        ast.Hospital__c                      = agent.Id;
 
        insert ast;
 
        System.Test.startTest();
        List<asset> assList =  [select Id,SerialNumber,Hospital__r.Name from asset  where SerialNumber = '82K(BBBBB)'];
        System.assertEquals(1, assList.size());
        saledet1.Consumable_Arrived_order__c = arriveOrder.Id;
        saledet1.Arrive_date__c = Date.today();
        saledet1.Bar_Code__c = '0114953170032070101804001082K250BBBBB';
        update saledet1;
        assList =  [select Id,SerialNumber,Barcode__c from asset  where SerialNumber = '82K(BBBBB)'];
        System.assertEquals('0114953170032070101804001082K250BBBBB', assList[0].Barcode__c);
        System.Test.stopTest();
 
    }
}