@isTest private class BeforeUpsertReportHandlerTest { static testMethod void testMethod1() { RecordType rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity' ]; // 病院を作る 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; // 戦略科室を得る Account[] strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_OTH']; // 診療科を作る Account dep = new Account(); dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id; dep.Name = 'test dep'; dep.AgentCode_Ext__c = '9999998'; dep.ParentId = strategicDep[0].Id; dep.Department_Class__c = strategicDep[0].Id; dep.Hospital__c = hospital.Id; insert dep; Opportunity opp1 = new Opportunity( Name='testOpp1', StageName='引合', CloseDate=Date.today(), AccountId=dep.Id, Competitor__c ='A', Click_Close_Date__c = null, RecordType = rectOpp, Hospital__c = dep.Id ); insert opp1; OPDPlan__c oPDPlan0 = new OPDPlan__c(); oPDPlan0.Status__c = '草案中'; oPDPlan0.OPDPlan_ImplementDate__c = Date.today().addDays(1); oPDPlan0.NoOpp_Reason__c = 'HCP对应'; oPDPlan0.Related_Opportunity1_ID__c =opp1.id; oPDPlan0.Account_Laboratory__c =dep.Id; insert oPDPlan0; Report__c rep1 = new Report__c(); rep1.Report_OPDPlan__c = oPDPlan0.id; rep1.CurrencyIsoCode = 'CNY'; rep1.Status__c = ''; rep1.Purpose1__c = 'OPD'; rep1.Purpose2__c = '引合追及活動'; rep1.Reason__c = '実施背景'; rep1.Appeal_Point__c = '実施目的・訴求点'; rep1.Strategic_Department_Class__c = '1.消化科'; rep1.Technical_Category1__c = '消化道检查'; rep1.Technical_Category2__c = '普通胃镜检查'; rep1.Patient_Status__c = '患者状況'; rep1.Operation_Process__c = '手術プロセス'; rep1.Operation_Task__c = '手術上の課題'; rep1.Product_Evaluation_Advantage__c = '製品評価利点'; rep1.Product_Evaluation_Faults__c = '製品評価欠点'; rep1.OPD_Summarize__c = 'OPD実施総括'; rep1.Activity_Plan__c = '今後の活動計画'; rep1.Opportunity_Situation__c = '引合無'; rep1.OPD_ProductCategory1__c ='3D System'; rep1.OPD_ProductCategory2__c ='OR Imaging Products'; rep1.Hospital_Reference__c = hospital.Id; rep1.Department_Class_Ref__c = strategicDep[0].Id; rep1.Hospital_Department__c = dep.Id; rep1.Status__c = '草案中'; rep1.Date__c= Date.today().addDays(-1); insert rep1; } static testMethod void testMethod2() { RecordType rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity' ]; // 病院を作る 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; // 戦略科室を得る Account[] strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_OTH']; // 診療科を作る Account dep = new Account(); dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id; dep.Name = 'test dep'; dep.AgentCode_Ext__c = '9999998'; dep.ParentId = strategicDep[0].Id; dep.Department_Class__c = strategicDep[0].Id; dep.Hospital__c = hospital.Id; insert dep; Opportunity opp1 = new Opportunity( Name='testOpp1', StageName='引合', CloseDate=Date.today(), AccountId=dep.Id, Competitor__c ='A', Click_Close_Date__c = null, RecordType = rectOpp ); insert opp1; OPDPlan__c oPDPlan0 = new OPDPlan__c(); oPDPlan0.Status__c = '草案中'; oPDPlan0.OPDPlan_ImplementDate__c = Date.today().addDays(1); oPDPlan0.NoOpp_Reason__c = 'HCP对应'; insert oPDPlan0; // 产品 Product2 pro5 = new Product2(Name='name05',IsActive=true,Family='SP', Fixture_Model_No__c='n05',Serial_Lot_No__c='S/N tracing', Fixture_Model_No_T__c = 'n05', ProductCode_Ext__c='pc05',Manual_Entry__c=false,ProductCode='N2032430'); insert pro5; // 保有设备 Asset asset = new Asset(Asset_Owner__c = 'Olympus'); asset.RecordTypeId = System.Label.Asset_RecordType; asset.SerialNumber = 'asset'; asset.Name = 'asset'; asset.AccountId = dep.Id; asset.Department_Class__c = strategicDep[0].Id; asset.Hospital__c = hospital.Id; asset.Product2Id = pro5.Id; asset.Quantity = 1; asset.Status = '有库存'; asset.Manage_type__c = '个体管理'; asset.Internal_asset_location__c = '北京 备品中心'; asset.Loaner_accsessary__c = true; asset.Delete_Flag__c = false; asset.Freeze_sign__c = false; asset.Out_of_wh__c = 0; insert asset; Rental_Apply__c raObj1 = new Rental_Apply__c(); raObj1.Rental_Start_Date__c = Date.today().addDays(1); raObj1.Request_return_day__c=Date.today().addDays(5); raObj1.DataMigration_Flag__c = true; raObj1.demo_purpose2__c = 'ceshi'; raObj1.Follow_UP_Opp__c = opp1.Id; insert raObj1; Rental_Apply__c raObj = new Rental_Apply__c(); raObj.Rental_Start_Date__c = Date.today().addDays(1); raObj.Request_return_day__c=Date.today().addDays(5); raObj.DataMigration_Flag__c = true; raObj.demo_purpose2__c = '试用(有询价)'; raObj.Old_Rental_Apply__c = raObj1.id; raObj.Follow_UP_Opp__c = opp1.Id; raObj.Status__c = '草案中'; raObj.OPDPlan__c = oPDPlan0.id; insert raObj; // 借出备品配套一览 Rental_Apply_Equipment_Set__c raesObj = new Rental_Apply_Equipment_Set__c(); raesObj.Rental_Apply__c = raObj.Id; raesObj.Cancel_Select__c = false; raesObj.Shipment_request_time__c = Date.toDay(); raesObj.Rental_Start_Date__c = Date.toDay(); raesObj.Rental_End_Date__c = Date.toDay(); raesObj.IndexFromUniqueKey__c = 1; raesObj.UniqueKey__c = '1::1'; raesObj.DataMigration_Flag__c =true; insert raesObj; // 借出备品配套一览明细 Rental_Apply_Equipment_Set_Detail__c raesdObj1 = new Rental_Apply_Equipment_Set_Detail__c(); raesdObj1.Rental_Apply__c = raObj.Id; // raesdObj1.Rental_Num__c = 1; raesdObj1.Queue_Number__c = null; raesdObj1.Is_Body__c = true; raesdObj1.IndexFromUniqueKey__c = 1; raesdObj1.UniqueKey__c = '1:'+ raesObj.Id + ':1'; raesdObj1.Salesdepartment_before__c = '1.华北营业本部'; raesdObj1.Internal_asset_location_before__c = '北京 备品中心'; raesdObj1.Product_category_text__c = 'GI'; raesdObj1.Equipment_Type_text__c = '产品试用'; raesdObj1.Rental_Apply_Equipment_Set__c = raesObj.Id; raesdObj1.Fixture_Model_No_text__c ='n05'; raesdObj1.Asset__c = asset.Id; insert raesdObj1; raesObj.First_RAESD__c = raesdObj1.Id; update raesObj; Report__c rep1 = new Report__c(); rep1.CurrencyIsoCode = 'CNY'; // rep1.RecordTypeId = rectOPD[0].Id; rep1.Status__c = ''; rep1.Loaner_request_no1__c = raObj.Id; rep1.Purpose1__c = 'OPD'; rep1.Purpose2__c = '引合追及活動'; rep1.Reason__c = '実施背景'; rep1.Appeal_Point__c = '実施目的・訴求点'; rep1.Strategic_Department_Class__c = '1.消化科'; rep1.Technical_Category1__c = '消化道检查'; rep1.Technical_Category2__c = '普通胃镜检查'; rep1.Patient_Status__c = '患者状況'; rep1.Operation_Process__c = '手術プロセス'; rep1.Operation_Task__c = '手術上の課題'; rep1.Product_Evaluation_Advantage__c = '製品評価利点'; rep1.Product_Evaluation_Faults__c = '製品評価欠点'; rep1.OPD_Summarize__c = 'OPD実施総括'; rep1.Activity_Plan__c = '今後の活動計画'; rep1.Opportunity_Situation__c = '引合無'; rep1.OPD_ProductCategory1__c ='3D System'; rep1.OPD_ProductCategory2__c ='OR Imaging Products'; rep1.Hospital_Reference__c = hospital.Id; rep1.Department_Class_Ref__c = strategicDep[0].Id; rep1.Hospital_Department__c = dep.Id; rep1.Status__c = '草案中'; rep1.Date__c= Date.today().addDays(-1); insert rep1; } static testMethod void testMethod3() { // 病院を作る 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; // 戦略科室を得る Account[] strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_OTH']; // 診療科を作る Account dep = new Account(); dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id; dep.Name = 'test dep'; dep.AgentCode_Ext__c = '9999998'; dep.ParentId = strategicDep[0].Id; dep.Department_Class__c = strategicDep[0].Id; dep.Hospital__c = hospital.Id; insert dep; Consum_Apply__c ca = new Consum_Apply__c(); ca.DataMigration_Flag__c = true; insert ca; Consum_Apply_Equipment_Set__c caes = new Consum_Apply_Equipment_Set__c(); caes.Consum_Apply__c = ca.Id; caes.Consum_Start_Date__c = Date.today().addDays(20); caes.DataMigration_Flag__c = true; insert caes; Consum_Apply_Equipment_Set_Detail__c caesd = new Consum_Apply_Equipment_Set_Detail__c(); caesd.DataMigration_Flag__c = true; caesd.Consum_Apply__c = ca.Id; caesd.Consum_Apply_Equipment_Set__c = caes.Id; caesd.Consum_Start_Date__c = caes.Consum_Start_Date__c; caesd.Trial_User__c = '我'; caesd.Follower_User__c = UserInfo.getUserId(); insert caesd; // 草案中 // 耗材备品配套一览 Consum_Apply_Equipment_Set__c caesObj = new Consum_Apply_Equipment_Set__c(); caesObj.Consum_Apply__c = ca.Id; caesObj.Cancel_Select__c = false; caesObj.Consum_Start_Date__c = Date.toDay().addDays(20); caesObj.IndexFromUniqueKey__c = 1; caesObj.UniqueKey__c = '1::1'; caesObj.DataMigration_Flag__c =true; caesObj.Model_No__c ='n05'; insert caesObj; // 产品 Product2 pro5 = new Product2(Name='name05',IsActive=true,Family='SP', Fixture_Model_No__c='n05',Serial_Lot_No__c='S/N tracing', Fixture_Model_No_T__c = 'n05', ProductCode_Ext__c='pc05',Manual_Entry__c=false); insert pro5; Report__c rep1 = new Report__c(); rep1.CurrencyIsoCode = 'CNY'; rep1.Status__c = ''; rep1.Consum_Apply__c = ca.Id; rep1.Technical_Category1__c ='消化道检查'; rep1.Technical_Category2__c ='普通胃镜检查'; rep1.Practitioner1_Part__c ='主刀'; rep1.Purpose1__c ='SIS-ET'; rep1.Purpose2__c = '引合追及活動'; rep1.Reason__c = '実施背景'; rep1.Appeal_Point__c = '実施目的・訴求点'; rep1.Strategic_Department_Class__c = '1.消化科'; rep1.Technical_Category1__c = '消化道检查'; rep1.Technical_Category2__c = '普通胃镜检查'; rep1.Patient_Status__c = '患者状況'; rep1.Operation_Process__c = '手術プロセス'; rep1.Operation_Task__c = '手術上の課題'; rep1.Product_Evaluation_Advantage__c = '製品評価利点'; rep1.Product_Evaluation_Faults__c = '製品評価欠点'; rep1.OPD_Summarize__c = 'OPD実施総括'; rep1.Activity_Plan__c = '今後の活動計画'; rep1.Opportunity_Situation__c = '引合無'; rep1.Operation_From__c =Date.today(); rep1.Operation_To__c =Date.today().addDays(2); rep1.sex__c ='男'; rep1.Product_Evaluation_Advantage1__c ='不起雾'; rep1.Product_Evaluation_Faults1__c ='起雾'; rep1.This_OPD_Summarize__c ='效果良好'; rep1.Medical_History__c ='家族'; rep1.age__c ='66'; rep1.OPD_ProductCategory1__c ='3D System'; rep1.OPD_ProductCategory2__c ='OR Imaging Products'; rep1.Hospital_Department__c = dep.Id; rep1.Status__c = '草案中'; rep1.Date__c= Date.today().addDays(-1); insert rep1; } }