@isTest private class SetContractEstimatePriceHandlerTest { static testMethod void test_method_one() { // 病院を作る Account hospital = new Account(); hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id; hospital.Name = 'test hospital'; insert hospital; // 戦略科室を得る List strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI']; // 診療科を作る Account dep = new Account(); dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id; dep.Name = 'test dep'; dep.ParentId = strategicDep[0].Id; dep.Department_Class__c = strategicDep[0].Id; dep.Hospital__c = hospital.Id; insert dep; // 製品を作る Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false, Asset_Model_No__c='MODEL1'); insert productA; Product2 productB = new Product2( Name='テスト商品2', Maintenance_Price_Year__c = 10000, Manual_Entry__c = false, Asset_Model_No__c='MODEL2'); insert productB; Product2 productC = new Product2( Name='テスト商品3', Maintenance_Price_Year__c = 11000, Manual_Entry__c = false, Asset_Model_No__c='MODEL1'); insert productC; Asset asset = new Asset(); asset.Name = 'asset01'; asset.AccountId = dep.Id; asset.Department_Class__c = strategicDep[0].Id; asset.Hospital__c = hospital.Id; asset.SerialNumber = '00001'; asset.Product2Id = productA.Id; asset.InstallDate = Date.today(); insert asset; Asset asset2 = new Asset(); asset2.Name = 'asset02'; asset2.AccountId = dep.Id; asset2.Department_Class__c = strategicDep[0].Id; asset2.Hospital__c = hospital.Id; asset2.SerialNumber = '00002'; asset2.Product2Id = productB.Id; asset2.InstallDate = Date.today(); insert asset2; Asset asset3 = new Asset(); asset3.Name = 'asset03'; asset3.AccountId = dep.Id; asset3.Department_Class__c = strategicDep[0].Id; asset3.Hospital__c = hospital.Id; asset3.SerialNumber = '00003'; asset3.Product2Id = productC.Id; asset3.InstallDate = Date.today(); insert asset3; // 维修合同を作成する Maintenance_Contract__c contract = new Maintenance_Contract__c(); contract.Name = 'tect contract'; contract.Hospital__c = hospital.Id; contract.Department_Class__c = strategicDep[0].Id; contract.Department__c = dep.Id; insert contract; // 维修合同报价を作成する Maintenance_Contract_Estimate__c contactEsti1 = new Maintenance_Contract_Estimate__c( Name = 'contract estimate 1', Contract_Esti_Start_Date__c = Date.today(), Contract_Range__c = 2, Maintenance_Contract__c = contract.Id ); insert contactEsti1; contract.Estimation_Id__c = contactEsti1.Id; update contract; Maintenance_Contract_Asset_Estimate__c mcae1 = new Maintenance_Contract_Asset_Estimate__c(); mcae1.Product_Manual__c = productA.Id; mcae1.Maintenance_Contract_Estimate__c = contactEsti1.Id; mcae1.Estimate_List_Price__c = 1000; mcae1.Check_Result__c = 'OK'; insert mcae1; Maintenance_Contract_Asset_Estimate__c mcae2 = new Maintenance_Contract_Asset_Estimate__c(); mcae2.Asset__c = asset2.Id; mcae2.Maintenance_Contract_Estimate__c = contactEsti1.Id; mcae2.Estimate_List_Price__c = 1000; mcae2.Check_Result__c = 'OK'; insert mcae2; // 维修合同/保有设备を作成する Maintenance_Contract_Asset__c mca1 = new Maintenance_Contract_Asset__c(); mca1.Asset__c = asset.Id; mca1.Estimate_List_Price__c = 100; mca1.Maintenance_Contract__c = contract.Id; insert mca1; // 维修合同/保有设备を作成する Maintenance_Contract_Asset__c mca2 = new Maintenance_Contract_Asset__c(); mca2.Asset__c = asset2.Id; mca2.Estimate_List_Price__c = 100; mca2.Maintenance_Contract__c = contract.Id; insert mca2; // 维修合同/保有设备を作成する Maintenance_Contract_Asset__c mca3 = new Maintenance_Contract_Asset__c(); mca3.Asset__c = asset3.Id; mca3.Estimate_List_Price__c = 100; mca3.Maintenance_Contract__c = contract.Id; insert mca3; update mca1; } }