高章伟
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
@isTest
private class DiscountProductApplicationApproveTest {
    static Account myAccount2;          //经销商
    static Account contract;            //经销商合同
    static Product2__c pro1;            //产品检索1
    static Product2__c pro2;            //产品检索2
    static Product2__c pro3;            //产品检索3
    static Product2__c pro4;            //产品检索4
    static Product2__c pro5;            //产品检索5
 
    static void initData(){
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        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;
 
        List<RecordType> rectCo1 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '契約'];
        if (rectCo1.size() == 0) {
            return;
        }
        contract = new Account(Name ='contractName',ParentId = myAccount2.id,Agent_Ref__c =myAccount2.id, Contract_Department_Class__c = 'ET',ET_SP_Dealer__c = true,Contract_Decide_Start_Date__c=Date.today().addDays(-2),
        Contract_Decide_End_Date__c = Date.today().addDays(2),Dealer_discount__c = 0.8,RecordTypeId = rectCo1[0].Id);
        insert contract;
        Product2 prod01 = new Product2(Name='Test01',
                            ProductCode='Test01',
                            Asset_Model_No__c = 'Test01',
                            SFDA_Status__c = '有効',
                            Product_Status__c = '正常销售',
                            SFDA_Approbated_Status__c = '有效',
                            Category3__c = 'CDS',
                            Category4__c = 'OER',
                            Category5__c = '其它',
                            Dealer_special_Object__c = true,
                            SFDA_Approbation_No__c = 'Test001',
                            Packing_list_manual__c = 1,
                            SFDA_Expiration_Date__c= Date.today(),
                            Intra_Trade_List_RMB_1__c = 1000,
                            Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_Date2__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1),
                            ENG_DeaerProFlag__c = true 
                            );
 
        Product2 prod02 = new Product2(Name='Test02',
                            ProductCode='Test02',
                            Asset_Model_No__c = 'Test02',
                            SFDA_Status__c = '有効',
                            Product_Status__c = '正常销售',
                            SFDA_Approbated_Status__c = '有效',
                            Category3__c = 'ENT',
                            Category4__c = 'Celon',
                            Category5__c = 'Celon',
                            Dealer_special_Object__c = true,
                            SFDA_Approbation_No__c = 'Test002',
                            Packing_list_manual__c = 1,
                            SFDA_Expiration_Date__c= Date.today(),
                            Intra_Trade_List_RMB_1__c = 1000,
                            Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_Date2__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1),
                            ENG_DeaerProFlag__c = true 
 
                            );
 
        Product2 prod03 = new Product2(Name='Test03',
                            ProductCode='Test03',
                            Asset_Model_No__c = 'Test03',
                            SFDA_Status__c = '有効',
                            Dealer_special_Object__c = true,
                            Product_Status__c = '正常销售',
                            SFDA_Approbated_Status__c = '有效',
                            Category3__c = 'US',
                            Category4__c = 'ALOKA',
                            Category5__c = '体外超声',
                            Intra_Trade_List_RMB_1__c = 1000,
                            Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1),
                            ENG_DeaerProFlag__c = true 
                            );
 
        Product2 prod04 = new Product2(Name='Test04',
            ProductCode='Test04',Asset_Model_No__c = 'Test04',
                            SFDA_Status__c = '有効',
                            Dealer_special_Object__c = true,
                            Product_Status__c = '正常销售',
                            SFDA_Approbated_Status__c = '有效',
                            Category3__c = 'OCS',
                            Category4__c = '附属品',
                            Category5__c = 'OCS',
                            Intra_Trade_List_RMB_1__c = 1000,
                            Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1),
                            ENG_DeaerProFlag__c = true 
                            );
        Product2 prod05 = new Product2(Name='Test05',
                            ProductCode='Test05',
                            Asset_Model_No__c = 'Test05',
                            SFDA_Status__c = '有効',
                            Dealer_special_Object__c = true,
                            Product_Status__c = '正常销售',
                            SFDA_Approbated_Status__c = '有效',
                            Category3__c = '光源',
                            Category4__c = 'CLV',
                            Category5__c = 'S45',
                            Intra_Trade_List_RMB_1__c = 1000,
                            Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1),
                            ENG_DeaerProFlag__c = true 
                            );
        insert new Product2[] {prod01,prod02,prod03, prod04, prod05};
        pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='Test001',Product2__c = prod01.Id);
        pro2 = new Product2__c(Name='Pro002',OT_CODE_Text__c='Test002',Product2__c = prod02.Id);
        pro3 = new Product2__c(Name='Pro003',OT_CODE_Text__c='Test003',Product2__c = prod03.Id);
        pro4 = new Product2__c(Name='Pro004',OT_CODE_Text__c='Test004',Product2__c = prod04.Id);
        pro5 = new Product2__c(Name='Pro005',OT_CODE_Text__c='Test005',Product2__c = prod05.Id);
        insert new Product2__c[] {pro1,pro2,pro3,pro4, pro5};
    }
    static testMethod void testMethod1() {
        initData();
        //1.创建'医院特价'的特价产品申请
        //创建医院
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        hospital.Is_Active__c = '有効';
        hospital.Attribute_Type__c = '卫生部';
        hospital.Speciality_Type__c = '综合医院';
        hospital.Grade__c = '一级';
        hospital.OCM_Category__c = 'SLTV';
        hospital.Is_Medical__c = '医疗机构';
        hospital.Town__c = '东京';
        insert hospital;
        Id HosTypeId = [select Id from RecordType where IsActive = true and DeveloperName = 'HospitalSpecials'].Id;
        DiscountProductApplication__c dpc = new DiscountProductApplication__c();
        dpc.AimsAccount__c = hospital.Id;
        dpc.RawAccount__c = myAccount2.Id;
        dpc.ApplicationStatus__c = '草案中';
        dpc.RecordTypeId = HosTypeId;
        insert dpc;
 
        DiscountProductApplicationDetail__c dpadc1 = new DiscountProductApplicationDetail__c();
        dpadc1.DiscountProductApplication__c = dpc.Id;                        
        dpadc1.ProductDiscount__c = 12345;
        dpadc1.Product2__c = pro1.Id;
        DiscountProductApplicationDetail__c dpadc2 = new DiscountProductApplicationDetail__c();
        dpadc2.DiscountProductApplication__c = dpc.Id;                        
        dpadc2.ProductDiscount__c = 8888;
        dpadc2.Product2__c = pro2.Id;
        insert new DiscountProductApplicationDetail__c[] {dpadc1,dpadc2};
 
        dpc.ApplicationStatus__c = '批准';
        update dpc;
 
        dpc = new DiscountProductApplication__c();
        //测试'产品特价'
        Id ProductTypeId = [select Id from RecordType where IsActive = true and DeveloperName = 'ProductDiscount'].Id;
        dpc.RecordTypeId = ProductTypeId;
        dpc.Dealer_Contact__c = contract.Id;
        dpc.ApplicationStatus__c = '草案中';
        dpc.RecordTypeId = ProductTypeId;
        insert dpc;
 
        dpadc1 = new DiscountProductApplicationDetail__c();
        dpadc1.DiscountProductApplication__c = dpc.Id;                        
        dpadc1.ProductDiscount__c = 12345;
        dpadc1.Product2__c = pro1.Id;
        dpadc2 = new DiscountProductApplicationDetail__c();
        dpadc2.DiscountProductApplication__c = dpc.Id;                        
        dpadc2.ProductDiscount__c = 8888;
        dpadc2.Product2__c = pro2.Id;
        insert new DiscountProductApplicationDetail__c[] {dpadc1,dpadc2};
 
        dpc.ApplicationStatus__c = '批准';
        update dpc;
    }
}