高章伟
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
@isTest
private class OpportunitySpecialApplyHandlerTest {
    
    static void initHpData() {
 
    }
    @isTest static void test_method_one() {
        ControllerUtil.EscapeNFM001Trigger = true;
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectCo1 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Agency'];
        if (rectCo1.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            return;
        }
        List<RecordType> rectSpec = [select Id from RecordType where IsActive = true and SobjectType = 'OpportunitySpecialApply__c' and Name = '注残特殊对应'];
        if (rectDpt.size() == 0) {
            return;
        }
        // テストデータ
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name         = 'TestCompany';
        upsert company;
 
        Account company1 = new Account();
        company1.RecordTypeId = rectCo1[0].Id;
        company1.Name         = 'TestCompany1';
        upsert company1;
 
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
 
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
 
        System.Test.startTest();
        Opportunity opp = new Opportunity();
        opp.AccountId           = depart.Id;
        opp.Department_Class__c = section.Id;
        opp.Hospital__c         = company.Id;
        opp.Name                = 'GZ-SP-NFM007_1';
        opp.Trade__c            = '内貿';
        opp.StageName           = '引合';
        opp.CloseDate           = date.today().adddays(1);
        opp.Agency1__c          = company1.Id;
        insert opp;
        
        //注残
        Statu_Achievements__c Sac2 = new Statu_Achievements__c();
        Sac2.name = 'zhucan_two';
        Sac2.Opportunity__c = opp.id;
        Sac2.DeliveryDate__c = Date.today();
        Sac2.ContractNO__c = 'ContractNO1';
        Sac2.ContractAmount__c = 1;
        insert Sac2;
 
        OpportunitySpecialApply__c spec = new OpportunitySpecialApply__c();
        spec.Status__c = '草案中';
        spec.Apply_Content__c = '删除本月订货预测';
        spec.Apply_Reason__c = 'NMPA影响';
        spec.Opportunity__c = opp.Id;
        spec.Achievements__c = Sac2.Id;
        spec.Approval_Date__c = Date.today();
        insert spec;
 
        spec.Status__c = '已批准';
        spec.Approval_Date__c = date.today();
        update spec;
 
        //注残
        Statu_Achievements__c Sac = new Statu_Achievements__c();
        Sac.name = 'zhucan_one';
        Sac.Opportunity__c = opp.id;
        Sac.DeliveryDate__c = Date.today();
        Sac.ContractNO__c = 'ContractNO1';
        Sac.ContractAmount__c = 1;
        insert Sac;
 
        OpportunitySpecialApply__c spec1 = new OpportunitySpecialApply__c();
        spec1.Status__c = '草案中';
        spec1.Apply_Content__c = '新增本月发货预测';
        spec1.Apply_Reason__c = 'NMPA影响';
        spec1.Opportunity__c = opp.Id;
        spec1.Achievements__c = Sac.Id;
        spec1.RecordTypeId = rectSpec[0].Id;
        spec1.Approval_Date__c = Date.today();
        insert spec1;
 
        spec1.Status__c = '已批准';
        spec1.Approval_Date__c = date.today();
        update spec1;
 
 
        OpportunitySpecialApply__c spec3 = new OpportunitySpecialApply__c();
        spec3.Status__c = '草案中';
        spec3.Apply_Content__c = '新增本月发货预测';
        spec3.Apply_Reason__c = 'NMPA影响';
        spec3.Opportunity__c = opp.Id;
        spec3.Achievements__c = Sac.Id;
        spec3.RecordTypeId = rectSpec[0].Id;
        spec3.Approval_Date__c = Date.today();
        spec3.Status__c = '已批准';
        insert spec3;
 
        OpportunitySpecialApply__c spec4 = new OpportunitySpecialApply__c();
        spec4.Status__c = '草案中';
        spec4.Apply_Content__c = '删除本月发货预测';
        spec4.Apply_Reason__c = 'NMPA影响';
        spec4.Opportunity__c = opp.Id;
        spec4.Achievements__c = Sac.Id;
        spec4.RecordTypeId = rectSpec[0].Id;
        spec4.Approval_Date__c = Date.today();
        spec4.Status__c = '已批准';
        insert spec4;
 
        System.Test.StopTest();
    }
    
    
}