高章伟
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
@isTest
private class SyncRepairFromMCAETriggerTest {
    private static Id pricebookId = ControllerUtil.getStandardPricebook().Id;
    static Account createHospital( String hospitalName) {
        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE DeveloperName = 'HP'].id;
        hospital.Name = hospitalName;
        insert hospital;
        return hospital;
    }
        
    static List<Account> selectStrategicDep( Account hospital) {
        // 戦略科室を得る
        List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
        return strategicDep;
    }
    
    static Account createDep( Account hospital, Account strategicDep) {
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE DeveloperName = 'Department_GI'].id;
        dep.Name = 'test dep';
        dep.ParentId = strategicDep.Id;
        dep.Department_Class__c = strategicDep.Id;
        dep.Hospital__c = hospital.Id;
        insert dep;
        return dep;
    }
    
    static Asset createAsset( Account hospital, Account strategicDep, Account dep) {
        // 製品を作る
        Product2 productA = new Product2( Name='テスト商品');
        insert productA;
        
        // 価格表エントリを作成する     
        PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=productA.Id);
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = 'CNY';
        entry.Product2Id = productA.Id;
        insert entry;
        
        // 納入機器を作成する
        Asset asset = new Asset();
        asset.Name = 'テスト機器';
        asset.AccountId = dep.Id;
        asset.Department_Class__c = strategicDep.Id;
        asset.Hospital__c = hospital.Id;
        asset.SerialNumber = 'testserial';
        insert asset;
        
        return asset;
    }
    
    static Maintenance_Contract__c createMaintenanceContract( Account hospital, Account strategicDep, Account dep) {
        Maintenance_Contract__c contract = new Maintenance_Contract__c();
        contract.Name = 'tect contract';
        contract.status__c ='契約';
        contract.Maintenance_Contract_No__c = 'Kami_Contract_No';
        contract.Contract_Conclusion_Date__c = Date.today();
        contract.Hospital__c = hospital.Id;
        contract.Department_Class__c = strategicDep.Id;
        contract.Department__c = dep.Id;
        contract.Contract_Start_Date__c = Date.today().addDays( -10);   // 10日前
        contract.Contract_End_Date__c = Date.today().addDays( 5);       // 5日後
        contract.SalesOfficeCode_selection__c = '北京RC';
        insert contract;
        return contract;
    }
    static testMethod void test_method_one() {
        // Implement test code
        // 病院、戦略科室、診療科の情報を作成します
        Account hospital = createHospital( 'test hospital');
        Account[] strategicDep = selectStrategicDep( hospital);
        Account dep = createDep( hospital, strategicDep[0]);
        
        // 納入機器を作る
        Asset asset = createAsset( hospital, strategicDep[0], dep);
 
        // 维修合同を作成する
        Maintenance_Contract__c contract = createMaintenanceContract( hospital, strategicDep[0], dep);
 
        // 维修合同报价作成
        Maintenance_Contract_Estimate__c contactEsti = new Maintenance_Contract_Estimate__c(
            Name = 'contract estimate 1',
            Maintenance_Contract__c = contract.Id,
            Contract_Esti_Start_Date__c = Date.today(),
            Contract_Start_Date__c = Date.today(),
            Contract_Range__c = 12,
            IsSyncing__c = True,
            Maintenance_Price__c = 1500,
            Estimate_Trial_Money__c = 1500,
            NotUse_Oxygenated_Water__c = true
        );
        insert contactEsti;
 
        // 维修合同更新
        contract.Estimation_Id__c = contactEsti.Id;
        update contract;
 
        Maintenance_Contract_Asset_Estimate__c mcae1 = new Maintenance_Contract_Asset_Estimate__c(
            Asset__c = asset.Id,
            Maintenance_Contract_Estimate__c = contactEsti.Id,
            Estimate_List_Price__c = 100,
            Comment__c = '一二三四五六七八九十一二三四五'
        );
        insert mcae1;
 
        ControllerUtil.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
        StaticParameter.EscapeNFM007Trigger = true;
        StaticParameter.EscapeOpportunityBefUpdTrigger = true;
        StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true;
        StaticParameter.EscapeSyncOpportunityTrigger = true;
        StaticParameter.EscapeMaintenanceContractAfterUpdateTrigger = true;
        StaticParameter.EscapeSyncOpportunityTrigger = true;
        StaticParameter.EscapeSyncProduct2Trigger = true;
        StaticParameter.EscapeLeadTrigger = true;
        StaticParameter.EscapeAccountTrigger = true;
        StaticParameter.EscapeConsumableOrderDetail2Trigger = true;
        StaticParameter.EscapeOrderDetail2Trigger = true;
        StaticParameter.EscapeNFM010UpsertStatuAchievementsTrigger = true;
 
        // 修理を作成する01
        Repair__c repair01 = new Repair__c();
        repair01.Account__c = dep.Id;
        repair01.Department_Class__c = strategicDep[0].Id;
        repair01.Hospital__c = hospital.Id;
        repair01.Maintenance_Contract__c = contract.Id;
        repair01.Delivered_Product__c = asset.Id;
        repair01.Status__c = '2.维修报价阶段';
        repair01.Repair_Detail__c = '12';
        repair01.SERVICE_CONTRACT_JUDEGE_DAY__C = Date.today().addDays(0);  // 维修合同判断日がサービス契約の中間辺りの日付
        insert repair01;
        
        Asset asset02 = createAsset( hospital, strategicDep[0], dep);
//System.Test.startTest();
        Repair__c repair02 = new Repair__c();
        repair02.Account__c = dep.Id;
        repair02.Department_Class__c = strategicDep[0].Id;
        repair02.Hospital__c = hospital.Id;
        repair02.Maintenance_Contract__c = contract.Id;
        repair02.Delivered_Product__c = asset02.Id;
        repair02.Status__c = '2.维修报价阶段';
        repair02.SERVICE_CONTRACT_JUDEGE_DAY__C = Date.today().addDays(0);  // 维修合同判断日がサービス契約の中間辺りの日付
        insert repair02;
//        System.Test.stopTest();
    }
}