@isTest private class MoreMaintenanceContractControllerTest { private static Id pricebookId = ControllerUtil.getStandardPricebook().Id; static Account createHospital( String hospitalName) { StaticParameter.EscapeNFM001AgencyContractTrigger = true; StaticParameter.EscapeNFM001Trigger = true; // 病院を作る Account hospital = new Account(); hospital.recordtypeId = [Select Id FROM RecordType WHERE DeveloperName = 'HP'].id; hospital.Name = hospitalName; insert hospital; StaticParameter.EscapeAccountTrigger = true; return hospital; } static List selectStrategicDep( Account hospital) { // 戦略科室を得る List 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; // dep.State_Text__c = '上海市'; 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'; asset.Quantity = 3; // asset.Extend_Gurantee_DateTo_Text__c =Date.today().addDays(30); // asset.IS_Extend_Gurantee_Txt__c =true; // asset.Order_No__c = 'BJ_2020'; insert asset; return asset; } static Maintenance_Contract_Asset__c createMiddleTable( Asset asset, Maintenance_Contract__c contract) { // 中間テーブルを設ける Maintenance_Contract_Asset__c middleTable = new Maintenance_Contract_Asset__c(); middleTable.Asset__c = asset.Id; middleTable.Maintenance_Contract__c = contract.id; insert middleTable; return middleTable; } static testMethod void testMethod1() { //维修合同 // 病院、戦略科室、診療科の情報を作成します 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 contract1 = new Maintenance_Contract__c(); contract1.Name = 'tect contract1'; contract1.status__c = '契約'; contract1.Maintenance_Contract_No__c = 'Kami_Contract_No'; contract1.Contract_Conclusion_Date__c = Date.today(); contract1.Hospital__c = hospital.Id; contract1.Department_Class__c = strategicDep[0].Id; contract1.Department__c = dep.Id; contract1.Contract_Start_Date__c = Date.today().addDays( -10); // 10日前 contract1.Contract_End_Date__c = Date.today().addDays( 5); // 5日後 contract1.SalesOfficeCode_selection__c = '北京RC'; contract1.hospitalQuotationTextSum__c = 0.00; contract1.RecordTypeId = Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Contract').getRecordTypeId(); insert contract1; Maintenance_Contract_Asset__c middleTable1 = createMiddleTable( asset, contract1); // 修理を作成する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.Delivered_Product__c = asset.Id; repair01.SERVICE_CONTRACT_JUDEGE_DAY__C = Date.today().addDays( -11); // 维修合同判断日がサービス契約開始日の前日 repair01.Repair_Start_Date__c = Date.today().addDays(-10); repair01.Repair_Final_Inspection_Date__c = Date.today().addDays(-3); repair01.Repair_List_Price__c = 100.00; repair01.RepairOrder_Complete_Day__c = Date.today().addDays(-1); repair01.Maintenance_Contract__c = contract1.Id; insert repair01; List Mc1_1 = [Select Id,Name,RecordType.DeveloperName from Maintenance_Contract__c where RecordType.DeveloperName='NewMaintenance_Contract']; system.assertEquals(1,Mc1_1.size()); PageReference page = new PageReference('/apex/MoreMaintenanceContractPop?Id=' +Mc1_1[0].Id+'&RecordTypeName='+Mc1_1[0].RecordType.DeveloperName); page.setRedirect(true); System.Test.setCurrentPage(page); MoreMaintenanceContractPopController mcp = new MoreMaintenanceContractPopController(); PageReference page1 = new PageReference('/apex/MoreMaintenanceContract?Id=' +Mc1_1[0].Id+'&RecordTypeName='+Mc1_1[0].RecordType.DeveloperName); page1.setRedirect(true); System.Test.setCurrentPage(page1); MoreMaintenanceContractController Mc1 = new MoreMaintenanceContractController(); Mc1.init(); Mc1.proportion = 100; Mc1.RefreshPrice(); Mc1.repairL[0].rr.hospitalQuotationText__c = 100.00; Mc1.GoFlag = 0; Mc1.HQSum(); Mc1.Save(); /*System.Test.StartTest(); ControllerUtil.insMBMCList = true; Id execBTId = Database.executeBatch(new MoreMaintenanceContractBatch(), 2); System.Test.StopTest();*/ } static testMethod void testMethod2() { //维修合同 // 病院、戦略科室、診療科の情報を作成します 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 contract2 = new Maintenance_Contract__c(); contract2.Name = 'tect contract2'; contract2.status__c = '契約'; contract2.Maintenance_Contract_No__c = 'Kami_Contract_No'; contract2.Contract_Conclusion_Date__c = Date.today(); contract2.Hospital__c = hospital.Id; contract2.Department_Class__c = strategicDep[0].Id; contract2.Department__c = dep.Id; contract2.Contract_Start_Date__c = Date.today().addDays( -10); // 10日前 contract2.Contract_End_Date__c = Date.today().addDays( 5); // 5日後 contract2.SalesOfficeCode_selection__c = '北京RC'; contract2.hospitalQuotationTextSum__c = 0.00; contract2.RecordTypeId = Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('VM_Contract').getRecordTypeId(); insert contract2; Maintenance_Contract_Asset__c middleTable2 = createMiddleTable( asset, contract2); // 修理を作成する02 Repair__c repair02 = new Repair__c(); repair02.Account__c = dep.Id; repair02.Department_Class__c = strategicDep[0].Id; repair02.Hospital__c = hospital.Id; repair02.Delivered_Product__c = asset.Id; repair02.SERVICE_CONTRACT_JUDEGE_DAY__C = Date.today().addDays( -11); // 维修合同判断日がサービス契約開始日の前日 repair02.Repair_Start_Date__c = Date.today().addDays(-10); repair02.Repair_Final_Inspection_Date__c = Date.today().addDays(-3); repair02.Repair_List_Price__c = 100.00; repair02.RepairOrder_Complete_Day__c = Date.today().addDays(-1); //repair02.VM_Maintenance_Contract__c = contract2.Id; insert repair02; List Mc2_2 = [Select Id,Name,RecordType.DeveloperName from Maintenance_Contract__c where RecordType.DeveloperName='VM_Contract']; PageReference page2 = new PageReference('/apex/MoreMaintenanceContract?Id=' +Mc2_2[0].Id+'&RecordTypeName='+Mc2_2[0].RecordType.DeveloperName); page2.setRedirect(true); System.Test.setCurrentPage(page2); MoreMaintenanceContractController Mc2 = new MoreMaintenanceContractController(); Mc2.init(); //List repairList = [Select Id, Name,Status1__c,Delivered_Product__c,Delivered_Product__r.Name,SerialNumber__c,Repair_List_Price_formula__c,Repair_Rank__c, // hospitalQuotationText__c from Repair__c where VM_Maintenance_Contract__c =:Mc2_2[0].Id and Status1__c !='0.取消' and Status1__c != '0.删除']; //VM_Maintenance_Contract__c =:Mc2_2[0].Id and //system.assertEquals(1,repairList.size()); Mc2.proportion = 100; Mc2.RefreshPrice(); //Mc2.repairL[0].rr.hospitalQuotationText__c = 100.00; Mc2.GoFlag = 0; Mc2.Save(); } }