高章伟
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
@isTest
private class LostCancelReportHandlerTest {
 
 
    @isTest static void test_method_one() {
        // recode type を取得
        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');
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            throw new ControllerUtil.myException('not found 戦略科室分類 recodetype');
        }
        List<RecordType> rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name IN ('診療科 消化科', '診療科 呼吸科') order by Name desc];
        if (rectDpt.size() == 0) {
            throw new ControllerUtil.myException('not found 診療科 recodetype');
        }
        List<RecordType> rectLost = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Lost_cancel_report__c' and DeveloperName IN ('PCL_Lost_report', 'PCL_Cancel_report') order by DeveloperName desc];
        if (rectLost.size() == 0) {
            throw new ControllerUtil.myException('not found Lost_cancel_report recodetype');
        }
 
        // insert
        Account company1 = new Account();
        company1.RecordTypeId = rectCo[0].Id;
        company1.Name         = '病院テスト1';
        insert company1;
 
        List<Account> dc1s = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = : company1.Id order by Department_Class_Label__c];
 
        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[0].Id;
        depart1.Name         = '*';
        depart1.Department_Name__c  = '診療科1';
        depart1.ParentId            = dc1s[0].Id;
        depart1.Department_Class__c = dc1s[0].Id;
        depart1.Hospital__c         = company1.Id;
        insert depart1;
 
        // 商談
        Opportunity opp1 = new Opportunity(Name='aiueo', StageName='contact', CloseDate=Date.today(),
                                           Hospital__c = company1.Id,
                                           Department_Class__c = dc1s[0].Id,
                                           AccountId = depart1.Id
                                           );
        insert opp1;
 
        // 失单
        Lost_cancel_report__c lcr1 = new Lost_cancel_report__c(
            Opportunity__c = opp1.Id,
            RecordTypeId = rectLost[0].Id
            );
        insert lcr1;
 
        //test
        lcr1.Report_Status__c = '批准';
        update lcr1;
 
        Opportunity opptest = [SELECT Id, Lost_Cancel_Report__c FROM Opportunity WHERE Id =: opp1.Id];
 
        // System.assertEquals(lcr1.Id, opptest.Lost_Cancel_Report__c);
    }
 
    // add tcm 20211212 start
    @isTest static void test_method_two() {
        // recode type を取得
        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');
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            throw new ControllerUtil.myException('not found 戦略科室分類 recodetype');
        }
        List<RecordType> rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name IN ('診療科 消化科', '診療科 呼吸科') order by Name desc];
        if (rectDpt.size() == 0) {
            throw new ControllerUtil.myException('not found 診療科 recodetype');
        }
        List<RecordType> rectLost = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Lost_cancel_report__c' and DeveloperName IN ('PCL_Lost_report', 'PCL_Cancel_report') order by DeveloperName desc];
        if (rectLost.size() == 0) {
            throw new ControllerUtil.myException('not found Lost_cancel_report recodetype');
        }
 
        // insert
        Account company1 = new Account();
        company1.RecordTypeId = rectCo[0].Id;
        company1.Name = '病院テスト1';
        insert company1;
 
        List<Account> dc1s = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = : company1.Id order by Department_Class_Label__c];
 
        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[0].Id;
        depart1.Name = '*';
        depart1.Department_Name__c  = '診療科1';
        depart1.ParentId= dc1s[0].Id;
        depart1.Department_Class__c = dc1s[0].Id;
        depart1.Hospital__c= company1.Id;
        insert depart1;
 
        Account depart2 = new Account();
        depart2.RecordTypeId = rectDpt[0].Id;
        depart2.Name = '*111';
        depart2.Department_Name__c  = '診療科2';
        depart2.ParentId= dc1s[0].Id;
        depart2.Department_Class__c = dc1s[0].Id;
        depart2.Hospital__c= company1.Id;
        insert depart2;
 
        // 询价
        Opportunity opp1 = new Opportunity(Name='opp1', StageName='oppName', CloseDate=Date.today(),Hospital__c = company1.Id,Department_Class__c = dc1s[0].Id,AccountId = depart1.Id);
        insert opp1;
 
        // 失单
        Lost_cancel_report__c lcr1 = new Lost_cancel_report__c(Opportunity__c = opp1.Id,RecordTypeId = rectLost[0].Id);
        insert lcr1;
 
 
        //失单品牌1
        PCLLostBrand__c pcllb1=new PCLLostBrand__c();
        pcllb1.LostPrice__c=1332;
        pcllb1.Lost_Reason_Sub__c='价格';   //原因次
        pcllb1.Lost_reason_main__c='价格';     //原因主
        pcllb1.Lost_By_Company__c='蛇牌';       //品牌(主)
        pcllb1.Agency__c=depart1.Id;            //经销商
        pcllb1.Lost_cancel_report__c=lcr1.Id;
 
        //失单品牌2
        PCLLostBrand__c pcllb2=pcllb1.clone();
        pcllb2.Lost_By_Company__c='其他';       //品牌(主)
        pcllb2.Lost_By_Company_Mannual__c='失单品牌';   //手动品牌
        pcllb2.Agency__c=depart2.Id;            //经销商
        pcllb2.AgencyMannual__c='手动经销商';
        insert new List<PCLLostBrand__c> {pcllb1,pcllb2};
 
 
        // 产品
        Product2 pro1 = new Product2(Name='name01',    Brand_Name__c='蛇牌',Category5__c='竞争对手',IsActive=true,Family='SP',Fixture_Model_No__c='n01',Serial_Lot_No__c='S/N tracing',Fixture_Model_No_T__c = 'n01',ProductCode_Ext__c='pc01',Manual_Entry__c=false);
        Product2 pro2 = new Product2(Name='name02',    Brand_Name__c='其他',Category5__c='竞争对手',IsActive=true,Family='SP2',Fixture_Model_No__c='n02',Serial_Lot_No__c='S/N tracing',Fixture_Model_No_T__c = 'n02',ProductCode_Ext__c='pc02',Manual_Entry__c=false);
        // Product2 pro3 = new Product2(Name='name03',Lost_By_Company__c='其他',IsActive=true,Family='SP3',Fixture_Model_No__c='n03',Serial_Lot_No__c='S/N tracing',Fixture_Model_No_T__c = 'n03',ProductCode_Ext__c='pc03',Manual_Entry__c=false);
        insert new List<Product2> {pro1,pro2};
 
 
 
 
        //失单型号
        PCLLostProduct__c pcllp1=new PCLLostProduct__c();
        pcllp1.Quantity__c=2;
        pcllp1.LostBrandName__c='蛇牌';
        pcllp1.ProductClass__c='主机';
        pcllp1.ProductCategory__c='4K';
        pcllp1.LostProduct__c=pro1.Id;     //产品Id
        pcllp1.LostProductMannual__c='失单对手型号(手动)';   //失单对手型号(手动)
        pcllp1.PCLLostBrand__c=pcllb1.Id;     //询价失单品牌
 
        PCLLostProduct__c pcllp2=pcllp1.clone();
        pcllp2.LostBrandName__c='其他';
        pcllp2.ProductClass__c='主机';
        pcllp2.ProductCategory__c='4K';
        pcllp2.LostProduct__c=pro2.Id;     //产品Id
        pcllp2.PCLLostBrand__c=pcllb2.Id;     //询价失单品牌
 
        // PCLLostProduct__c pcllp3=pcllp1.clone();
        // pcllp3.LostBrandName__c='其他';
        // pcllp3.LostProduct__c=pro3.Id;     //产品Id
        // pcllp3.PCLLostBrand__c=pcllb2.Id;     //询价失单品牌
 
        insert new List<PCLLostProduct__c> {pcllp1,pcllp2};
 
 
        //test
        lcr1.Report_Status__c = '批准';
        update lcr1;
 
    }
    // add tcm 20211212 end
 
}