@isTest public class InventoryControllerTest { // private static RecordType rectCoO ; // private static Account olympus; // private static Account myAccount1; // private static Contact core; // private static user MyUser_Test; // static void creatdata(){ // Profile prof1 = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证(ET Email)']; // List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店']; // if (rectCo.size() == 0) { // return; // } // rectCoO = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; // olympus = new Account(RecordTypeId = rectCoO.Id, AgentCode_Ext__c = '9999900', Name = 'olympus'); // insert olympus; // myAccount1 = new Account(name='Testaccount001',Dealer_discount__c =10,RecordTypeId = rectCo[0].Id,AgentCode_Ext__c = '8888888'); // insert myAccount1; // core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=myAccount1.id); // insert core; // MyUser_Test = New User(ContactId = core.id,Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof1.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com'); // // List MyUser_Test = [select id,Alias,Email,LastName,UserName from User where Alias = '精琢技术']; // insert MyUser_Test; // } static testMethod void InventoryControllerTest_PartBar(){ Profile prof1 = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证(ET Email)']; List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店']; if (rectCo.size() == 0) { return; } StaticParameter.EscapeOrderDetail2Trigger = true; StaticParameter.EscapeConsumableOrderDetail2Trigger = true; // creatdata(); RecordType rectCoO = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; Account olympus = new Account(RecordTypeId = rectCoO.Id, AgentCode_Ext__c = '9999900', Name = 'olympus'); insert olympus; Account myAccount1 = new Account(name='Testaccount001',Dealer_discount__c =10,RecordTypeId = rectCo[0].Id,AgentCode_Ext__c = '8888888'); insert myAccount1; Contact core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=myAccount1.id); insert core; // user MyUser_Test = New User(ContactId = core.id,Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof1.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com'); // List MyUser_Test = [select id,Alias,Email,LastName,UserName,Contact.accountid,Contact.account.Name from User where Id = '00510000006xOSq']; // insert MyUser_Test; user MyUser_Test =new user(); System.runAs(new User(Id = UserInfo.getUserId())){ MyUser_Test = New User(ContactId = core.id,Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof1.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com'); insert MyUser_Test; } system.runAs(MyUser_Test){ //产品数据 //Product2 prod01 = new Product2(Name='Test01',ProductCode='Test01',Asset_Model_No__c = 'Test01',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1); // Product2 prod02 = new Product2(Name='Test02',ProductCode='Test02',Asset_Model_No__c = 'Test02',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1); // Product2 prod03 = new Product2(Name='Test03',ProductCode='Test03',Asset_Model_No__c = 'Test03',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1); // Product2 prod04 = new Product2(Name='Test04',ProductCode='Test04',Asset_Model_No__c = 'Test04',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1); // Product2 prod05 = new Product2(Name='Test05',ProductCode='Test05',Asset_Model_No__c = 'Test05',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1); // Product2 prod06 = new Product2(Name='Test06',ProductCode='Test06',Asset_Model_No__c = 'Test06',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1); Product2 prod07 = new Product2(Name='Test07',ProductCode='Test07',Asset_Model_No__c = 'Test07',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1,Category5__c='竞争对手'); Product2 prod08 = new Product2(Name='Test08',ProductCode='Test08',Asset_Model_No__c = 'Test08',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1,Category5__c='竞争对手'); Product2 prod09 = new Product2(Name='Test09',ProductCode='Test09',Asset_Model_No__c = 'Test09',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1,Category5__c='竞争对手'); //insert new Product2[] {prod01,prod02,prod03,prod04,prod05,prod06,prod07,prod08,prod09}; insert new Product2[] {prod07,prod08,prod09}; //Product2__c pro1 = new Product2__c(Name='MH-364:帽',Product2__c = prod01.Id); //Product2__c pro2 = new Product2__c(Name='MH-462:透明黏膜吸套',Product2__c = prod02.Id); //Product2__c pro5 = new Product2__c(Name='MH-155:白平衡帽',Product2__c = prod03.Id); //Product2__c pro3 = new Product2__c(Name='MB-677:BNC电缆',Product2__c = prod04.Id); //Product2__c pro4 = new Product2__c(Name='70236110:金刚砂锥状钻头,70度',Product2__c = prod05.Id); //Product2__c pro6 = new Product2__c(Name='MAJ-643R:水囊鞘管',Product2__c = prod06.Id); //制作产品 Product2__c proG = new Product2__c(Name='MH-155:白平衡帽',OT_CODE_Text__c='Test001',Product2__c = prod07.Id); insert proG; Product2__c proH = new Product2__c(Name='MB-677:BNC电缆',OT_CODE_Text__c='Test002',Product2__c = prod08.Id); insert proH; Product2__c proF = new Product2__c(Name='TooMAJ-643R:水囊鞘管003',OT_CODE_Text__c='Test003',Product2__c = prod09.Id); insert proF; //Product2__c proD = new Product2__c(Name='70236110:金刚砂锥状钻头,70度',OT_CODE_Text__c='Test003',Product2__c = prod09.Id); //insert proD; //insert new Product2__c[] {pro1, pro2,pro3,pro4, pro5, pro6}; //预制头明细 Consumable_order__c CreateId = new Consumable_order__c(); CreateId.Name = 'testMing'; CreateId.Order_status__c = '草案中'; CreateId.RecordTypeid = System.Label.RT_ConOrder_Order; // CreateId.Dealer_Info__c = MyUser_Test[0].Contact.accountId; CreateId.Dealer_Info__c = myAccount1.id; CreateId.Inventory_date__c = Date.today(); CreateId.Order_type__c = '盘点'; CreateId.Order_ProType__c = 'ET'; insert CreateId; ConsumableAssetHander.isRunning=true; //制作Consumable_order_details__c-------ProductCount Consumable_order_details2__c dataForProductCount9 = new Consumable_order_details2__c(); dataForProductCount9.Bar_Code__c = '1234567890'; dataForProductCount9.Sterilization_limit__c = Date.today().addDays(2); dataForProductCount9.Arrive_date__c = Date.today(); dataForProductCount9.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery; dataForProductCount9.Consumable_Product__c = proG.id; dataForProductCount9.Asset_Model_No__c = proG.Asset_Model_No__c; dataForProductCount9.Box_Piece__c = '盒'; dataForProductCount9.Consumable_order_minor__c = CreateId.id; dataForProductCount9.Send_Date__c = null; dataForProductCount9.Used_date__c = null; dataForProductCount9.Lose_Flag__c = false; insert dataForProductCount9; Consumable_order_details2__c dataForProductCount7 = new Consumable_order_details2__c(); dataForProductCount7.Bar_Code__c = '1234567892'; dataForProductCount7.Sterilization_limit__c = Date.today().addDays(2); dataForProductCount7.Arrive_date__c = Date.today(); dataForProductCount7.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery; dataForProductCount7.Consumable_Product__c = proH.id; dataForProductCount7.Asset_Model_No__c = proH.Asset_Model_No__c; dataForProductCount7.Box_Piece__c = '盒'; dataForProductCount7.Consumable_order_minor__c = CreateId.id; dataForProductCount7.Send_Date__c = null; dataForProductCount7.Used_date__c = null; dataForProductCount7.Lose_Flag__c = false; insert dataForProductCount7; Consumable_order_details2__c dataForProductCount = new Consumable_order_details2__c(); dataForProductCount.Bar_Code__c = '1234567882'; dataForProductCount.Sterilization_limit__c = Date.today().addDays(2); dataForProductCount.Arrive_date__c = Date.today(); dataForProductCount.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery; dataForProductCount.Consumable_Product__c = proG.id; dataForProductCount.Asset_Model_No__c = proG.Asset_Model_No__c; dataForProductCount.Box_Piece__c = '盒'; dataForProductCount.Consumable_order_minor__c = CreateId.id; dataForProductCount.Send_Date__c = null; dataForProductCount.Used_date__c = null; dataForProductCount.Lose_Flag__c = true; insert dataForProductCount; Consumable_order_details2__c dataForProductCount4 = new Consumable_order_details2__c(); dataForProductCount4.Bar_Code__c = '1234567884'; dataForProductCount4.Sterilization_limit__c = Date.today().addDays(2); dataForProductCount4.Arrive_date__c = Date.today(); dataForProductCount4.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery; dataForProductCount4.Consumable_Product__c = proF.id; dataForProductCount4.Asset_Model_No__c = proF.Asset_Model_No__c; dataForProductCount4.Box_Piece__c = '个'; dataForProductCount4.Consumable_order_minor__c = CreateId.id; //dataForProductCount4.Lose_Flag__c = true; dataForProductCount4.RemoveBox_No__c = 1; insert dataForProductCount4; Consumable_order_details2__c dataForProductCount5 = new Consumable_order_details2__c(); dataForProductCount5.Bar_Code__c = '1234567885'; dataForProductCount5.Sterilization_limit__c = Date.today().addDays(2); dataForProductCount5.Arrive_date__c = Date.today(); dataForProductCount5.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery; dataForProductCount5.Consumable_Product__c = proH.id; dataForProductCount5.Asset_Model_No__c = proH.Asset_Model_No__c; dataForProductCount5.Box_Piece__c = '个'; dataForProductCount5.Consumable_order_minor__c = CreateId.id; dataForProductCount5.Lose_Flag__c = true; dataForProductCount5.RemoveBox_No__c = 1; insert dataForProductCount5; List productCount_Res = [select Id, Name FROM Consumable_order_details2__c WHERE Dealer_Arrive__c = true AND Dealer_Shipment__c = false AND Dealer_Saled__c = false AND Lose_Flag__c = false AND Bar_Code__c !=null AND Dealer_Info_text__c = :myAccount1.Name]; // AND Dealer_Info_text__c = :MyUser_Test[0].Contact.account.Name]; // system.assertEquals(8,productCount_Res.size()); PageReference page = new Pagereference('/Inventory'); page.setRedirect(true); System.Test.setCurrentPage(page); InventoryController OwnTest = new InventoryController(); System.Test.startTest(); OwnTest.init(); OwnTest.barcode = ''; OwnTest.searchConsumableorderdetails(); //OwnTest.save(); OwnTest.barcode = ''; OwnTest.ConsumableorderdetailsRecordsview[0][0].check = true; OwnTest.searchConsumableorderdetails(); //system.assertEquals(100,OwnTest.ConsumableorderdetailsRecordsview[0].size()); //OwnTest.save(); OwnTest.barcode = '1234567895\n1234567890\n12345678511\n1234567856\n1234567855\n1234567886\n12345678551\n1234567890\n1234567883\n1234567882\n1234567881\n1234567884\nn123456788412\n1234567885\n123456788512\n1234567891\n1234567892\n1234567893\n1234567894'; //OwnTest.ConsumableorderdetailsRecordsview[0][0].check = true; //OwnTest.ConsumableorderdetailsRecordsview[0][0].DiffReason = '123'; //OwnTest.ConsumableorderdetailsRecordsview[0][1].check = true; //OwnTest.ConsumableorderdetailsRecordsview[0][1].DiffReason = null; //OwnTest.ConsumableorderdetailsRecordsview[0][2].check = false; OwnTest.searchConsumableorderdetails(); OwnTest.save(); //system.assertEquals(4,OwnTest.consumableorderdetailsRecordserrordummy.size()); OwnTest.doClick(); OwnTest.ProS(); System.Test.stopTest(); } } static testMethod void InventoryControllerTest_PartPan(){ Profile prof1 = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证(ET Email)']; List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店']; if (rectCo.size() == 0) { return; } RecordType rectCoO = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; Account olympus = new Account(RecordTypeId = rectCoO.Id, AgentCode_Ext__c = '9999900', Name = 'olympus'); insert olympus; //Product2 prod01 = new Product2(Name='Test01',ProductCode='Test01',Asset_Model_No__c = 'Test01',SFDA_Status__c = '有効',Dealer_special_Object__c = true); // Product2 prod02 = new Product2(Name='Test02',ProductCode='Test02',Asset_Model_No__c = 'Test02',SFDA_Status__c = '有効',Dealer_special_Object__c = true); // Product2 prod03 = new Product2(Name='Test03',ProductCode='Test03',Asset_Model_No__c = 'Test03',SFDA_Status__c = '有効',Dealer_special_Object__c = true); // Product2 prod04 = new Product2(Name='Test04',ProductCode='Test04',Asset_Model_No__c = 'Test04',SFDA_Status__c = '有効',Dealer_special_Object__c = true); // Product2 prod05 = new Product2(Name='Test05',ProductCode='Test05',Asset_Model_No__c = 'Test05',SFDA_Status__c = '有効',Dealer_special_Object__c = true); // Product2 prod06 = new Product2(Name='Test06',ProductCode='Test06',Asset_Model_No__c = 'Test06',SFDA_Status__c = '有効',Dealer_special_Object__c = true); Product2 prod07 = new Product2(Name='Test07',ProductCode='Test07',Asset_Model_No__c = 'Test07',SFDA_Status__c = '有効',Dealer_special_Object__c = true); Product2 prod08 = new Product2(Name='Test08',ProductCode='Test08',Asset_Model_No__c = 'Test08',SFDA_Status__c = '有効',Dealer_special_Object__c = true); Product2 prod09 = new Product2(Name='Test09',ProductCode='Test09',Asset_Model_No__c = 'Test09',SFDA_Status__c = '有効',Dealer_special_Object__c = true); insert new Product2[] {prod07,prod08,prod09}; //Product2__c pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='Test001',Product2__c = prod01.Id); //Product2__c pro2 = new Product2__c(Name='Pro002',OT_CODE_Text__c='Test002',Product2__c = prod02.Id); //Product2__c pro5 = new Product2__c(Name='Pro003',OT_CODE_Text__c='Test003',Product2__c = prod03.Id); //Product2__c pro3 = new Product2__c(Name='Pro004',OT_CODE_Text__c='Test004',Product2__c = prod04.Id); //Product2__c pro4 = new Product2__c(Name='Pro005',OT_CODE_Text__c='Test005',Product2__c = prod05.Id); //Product2__c pro6 = new Product2__c(Name='Pro006',OT_CODE_Text__c='Test006',Product2__c = prod06.Id); //insert new Product2__c[] {pro4, pro5,pro6,pro1, pro2, pro3}; //制作产品 Product2__c proG = new Product2__c(Name='Too001',OT_CODE_Text__c='Test001',Product2__c = prod07.Id); insert proG; Product2__c proH = new Product2__c(Name='Too002',OT_CODE_Text__c='Test002',Product2__c = prod08.Id); insert proH; Product2__c proF = new Product2__c(Name='Too003',OT_CODE_Text__c='Test001',Product2__c = prod09.Id); insert proF; //Product2__c proD = new Product2__c(Name='Too003',OT_CODE_Text__c='Test001',Product2__c = prod09.Id); //insert proD; Account myAccount1 = new Account(name='Testaccount001',Dealer_discount__c =10,RecordTypeId = rectCo[0].Id); //Account myAccount2 = new Account(name='Testaccount002',Dealer_discount__c =20,RecordTypeId = rectCo[0].Id); insert myAccount1; //insert myAccount2; Contact core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=myAccount1.id); insert core; // user MyUser_Test = New User(ContactId = core.id,Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof1.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com'); // insert MyUser_Test; user MyUser_Test =new user(); System.runAs(new User(Id = UserInfo.getUserId())){ MyUser_Test = New User(ContactId = core.id,Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof1.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com'); insert MyUser_Test; } system.runAs(MyUser_Test){ InventoryController OwnTest = new InventoryController(); OwnTest.size = 2; OwnTest.init(); OwnTest.setCon.next(); OwnTest.refreshPageSize(); OwnTest.ConsumableorderdetailsRecordsview.sort(); system.assertEquals(0,OwnTest.consumableorderdetailsCount); OwnTest.save(); } } static testMethod void InventoryControllerTest_ge(){ Profile prof1 = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证(ET Email)']; List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店']; if (rectCo.size() == 0) { return; } StaticParameter.EscapeConsumableOrderDetail2Trigger = true; RecordType rectCoO = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; Account olympus = new Account(RecordTypeId = rectCoO.Id, AgentCode_Ext__c = '9999900', Name = 'olympus'); insert olympus; Account myAccount1 = new Account(name='Testaccount001',Dealer_discount__c =10,RecordTypeId = rectCo[0].Id,AgentCode_Ext__c = '8888888'); insert myAccount1; Contact core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=myAccount1.id); insert core; // user MyUser_Test = New User(ContactId = core.id,Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof1.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com'); // insert MyUser_Test; user MyUser_Test =new user(); System.runAs(new User(Id = UserInfo.getUserId())){ MyUser_Test = New User(ContactId = core.id,Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof1.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com'); insert MyUser_Test; } system.runAs(MyUser_Test){ //产品数据 //Product2 prod01 = new Product2(Name='Test01',ProductCode='Test01',Asset_Model_No__c = 'Test01',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1); // Product2 prod02 = new Product2(Name='Test02',ProductCode='Test02',Asset_Model_No__c = 'Test02',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1); // Product2 prod03 = new Product2(Name='Test03',ProductCode='Test03',Asset_Model_No__c = 'Test03',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1); // Product2 prod04 = new Product2(Name='Test04',ProductCode='Test04',Asset_Model_No__c = 'Test04',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1); // Product2 prod05 = new Product2(Name='Test05',ProductCode='Test05',Asset_Model_No__c = 'Test05',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1); // Product2 prod06 = new Product2(Name='Test06',ProductCode='Test06',Asset_Model_No__c = 'Test06',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1); Product2 prod07 = new Product2(Name='Test07',ProductCode='Test07',Asset_Model_No__c = 'Test07',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1,Category5__c='竞争对手'); Product2 prod08 = new Product2(Name='Test08',ProductCode='Test08',Asset_Model_No__c = 'Test08',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1,Category5__c='竞争对手'); Product2 prod09 = new Product2(Name='Test09',ProductCode='Test09',Asset_Model_No__c = 'Test09',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1,Category5__c='竞争对手'); insert new Product2[] {prod07,prod08,prod09}; //Product2__c pro1 = new Product2__c(Name='MH-364:帽',Product2__c = prod01.Id); //Product2__c pro2 = new Product2__c(Name='MH-462:透明黏膜吸套',Product2__c = prod02.Id); //Product2__c pro5 = new Product2__c(Name='MH-155:白平衡帽',Product2__c = prod03.Id); //Product2__c pro3 = new Product2__c(Name='MB-677:BNC电缆',Product2__c = prod04.Id); //Product2__c pro4 = new Product2__c(Name='70236110:金刚砂锥状钻头,70度',Product2__c = prod05.Id); //Product2__c pro6 = new Product2__c(Name='MAJ-643R:水囊鞘管',Product2__c = prod06.Id); //制作产品 Product2__c proG = new Product2__c(Name='MH-155:白平衡帽',OT_CODE_Text__c='Test001',Product2__c = prod07.Id); insert proG; Product2__c proH = new Product2__c(Name='MB-677:BNC电缆',OT_CODE_Text__c='Test002',Product2__c = prod08.Id); insert proH; Product2__c proF = new Product2__c(Name='TooMAJ-643R:水囊鞘管003',OT_CODE_Text__c='Test003',Product2__c = prod09.Id); insert proF; //Product2__c proD = new Product2__c(Name='70236110:金刚砂锥状钻头,70度',OT_CODE_Text__c='Test003',Product2__c = prod09.Id); //insert proD; //insert new Product2__c[] {pro1, pro2,pro3,pro4, pro5, pro6}; //预制头明细 Consumable_order__c CreateId = new Consumable_order__c(); CreateId.Name = 'testMing'; CreateId.Order_status__c = '草案中'; CreateId.RecordTypeid = System.Label.RT_ConOrder_Order; CreateId.Dealer_Info__c = myAccount1.id; CreateId.Inventory_date__c = Date.today(); CreateId.Order_type__c = '盘点'; CreateId.Order_ProType__c = 'ET'; insert CreateId; //制作Consumable_order_details__c-------ProductCount Consumable_order_details2__c dataForProductCount9 = new Consumable_order_details2__c(); dataForProductCount9.Bar_Code__c = '1234567890'; dataForProductCount9.Sterilization_limit__c = Date.today().addDays(2); dataForProductCount9.Arrive_date__c = Date.today(); dataForProductCount9.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery; dataForProductCount9.Consumable_Product__c = proG.id; dataForProductCount9.Asset_Model_No__c = proG.Asset_Model_No__c; dataForProductCount9.Box_Piece__c = '个'; dataForProductCount9.RemoveBox_No__c = 1; insert dataForProductCount9; Consumable_order_details2__c dataForProductCount8 = new Consumable_order_details2__c(); dataForProductCount8.Bar_Code__c = '1234567891'; dataForProductCount8.Sterilization_limit__c = Date.today().addDays(2); dataForProductCount8.Arrive_date__c = Date.today(); dataForProductCount8.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery; dataForProductCount8.Consumable_Product__c = proG.id; dataForProductCount8.Asset_Model_No__c = proG.Asset_Model_No__c; insert dataForProductCount8; Consumable_order_details2__c dataForProductCount7 = new Consumable_order_details2__c(); dataForProductCount7.Bar_Code__c = '1234567892'; dataForProductCount7.Sterilization_limit__c = Date.today().addDays(2); dataForProductCount7.Arrive_date__c = Date.today(); dataForProductCount7.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery; dataForProductCount7.Consumable_Product__c = proH.id; dataForProductCount7.Asset_Model_No__c = proH.Asset_Model_No__c; dataForProductCount7.Box_Piece__c = '个'; dataForProductCount7.Consumable_order_minor__c = CreateId.id; dataForProductCount7.Send_Date__c = null; dataForProductCount7.Used_date__c = null; dataForProductCount7.Lose_Flag__c = false; dataForProductCount7.RemoveBox_No__c = 1; insert dataForProductCount7; /*Consumable_order_details2__c dataForProduct1 = new Consumable_order_details2__c(); dataForProduct1.Bar_Code__c = '1234567893'; dataForProduct1.Arrive_date__c = Date.today(); dataForProduct1.Sterilization_limit__c = Date.today().addDays(2); dataForProduct1.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery; dataForProduct1.Consumable_Product__c = proG.id; dataForProduct1.Box_Piece__c = '个'; dataForProduct1.Consumable_order_minor__c = CreateId.id; dataForProduct1.Send_Date__c = null; dataForProduct1.Used_date__c = null; dataForProduct1.Lose_Flag__c = false; dataForProduct1.RemoveBox_No__c = 1; insert dataForProduct1;*/ Consumable_order_details2__c dataForProduct = new Consumable_order_details2__c(); dataForProduct.Bar_Code__c = '1234567894'; dataForProduct.Sterilization_limit__c = Date.today().addDays(2); dataForProduct.Arrive_date__c = Date.today(); dataForProduct.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery; dataForProduct.Consumable_Product__c = proF.id; dataForProduct.Asset_Model_No__c = proF.Asset_Model_No__c; dataForProduct.Box_Piece__c = '个'; dataForProduct.Consumable_order_minor__c = CreateId.id; dataForProduct.Send_Date__c = null; dataForProduct.Used_date__c = null; dataForProduct.Lose_Flag__c = false; dataForProduct.RemoveBox_No__c = 1; insert dataForProduct; Consumable_order_details2__c dataForProductCount3 = new Consumable_order_details2__c(); dataForProductCount3.Bar_Code__c = '1234567883'; dataForProductCount3.Sterilization_limit__c = Date.today().addDays(2); dataForProductCount3.Arrive_date__c = Date.today(); dataForProductCount3.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery; dataForProductCount3.Consumable_Product__c = proG.id; dataForProductCount3.Asset_Model_No__c = proG.Asset_Model_No__c; dataForProductCount3.Consumable_order_minor__c = CreateId.id; dataForProductCount3.Lose_Flag__c = true; //dataForProductCount3.RemoveBox_No__c = 1; insert dataForProductCount3; PageReference page = new Pagereference('/Inventory'); page.setRedirect(true); System.Test.setCurrentPage(page); InventoryController OwnTest = new InventoryController(); //OwnTest.init(); System.Test.startTest(); OwnTest.size = 2; OwnTest.init(); OwnTest.barcode = '1234567816\n12345678951\n123456785512\n12345678561\n12345678551\n12345678861\n12345678901\n12345678831\n12345678821\n12345678811\n12345678841\n12345678851\n12345678911\n12345678921\n12345678931\n12345678941\n1234567856'; /*OwnTest.ConsumableorderdetailsRecordsview[0][0].check = true; OwnTest.ConsumableorderdetailsRecordsview[0][0].DiffReason = '123'; OwnTest.ConsumableorderdetailsRecordsview[0][1].check = true; OwnTest.ConsumableorderdetailsRecordsview[0][1].DiffReason = null; OwnTest.ConsumableorderdetailsRecordsview[0][2].check = false;*/ OwnTest.searchConsumableorderdetails(); System.assertEquals(2, OwnTest.ConsumableorderdetailsRecordsview[0].size()); OwnTest.ConsumableorderdetailsRecordsview[0][0].check = true; OwnTest.ConsumableorderdetailsRecordsview[0][0].DiffReason = '123'; OwnTest.save(); OwnTest.refreshPageSize(); OwnTest.makepagerecords(); OwnTest.setCon.next(); System.Test.stopTest(); } } static testMethod void InventoryControllerTest_xunhui(){ Profile prof1 = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证(ET Email)']; List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店']; if (rectCo.size() == 0) { return; } StaticParameter.EscapeOrderDetail2Trigger = true; StaticParameter.EscapeConsumableOrderDetail2Trigger = true; RecordType rectCoO = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; Account olympus = new Account(RecordTypeId = rectCoO.Id, AgentCode_Ext__c = '9999900', Name = 'olympus'); insert olympus; Account myAccount1 = new Account(name='Testaccount001',Dealer_discount__c =10,RecordTypeId = rectCo[0].Id,AgentCode_Ext__c = '8888888'); insert myAccount1; Contact core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=myAccount1.id); insert core; // user MyUser_Test = New User(ContactId = core.id,Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof1.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com'); // insert MyUser_Test; user MyUser_Test =new user(); System.runAs(new User(Id = UserInfo.getUserId())){ MyUser_Test = New User(ContactId = core.id,Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof1.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com'); insert MyUser_Test; } system.runAs(MyUser_Test){ //产品数据 //Product2 prod01 = new Product2(Name='Test01',ProductCode='Test01',Asset_Model_No__c = 'Test01',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1); // Product2 prod02 = new Product2(Name='Test02',ProductCode='Test02',Asset_Model_No__c = 'Test02',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1); // Product2 prod03 = new Product2(Name='Test03',ProductCode='Test03',Asset_Model_No__c = 'Test03',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1); // Product2 prod04 = new Product2(Name='Test04',ProductCode='Test04',Asset_Model_No__c = 'Test04',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1); // Product2 prod05 = new Product2(Name='Test05',ProductCode='Test05',Asset_Model_No__c = 'Test05',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1); // Product2 prod06 = new Product2(Name='Test06',ProductCode='Test06',Asset_Model_No__c = 'Test06',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1); Product2 prod07 = new Product2(Name='Test07',ProductCode='Test07',Asset_Model_No__c = 'Test07',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1,Category5__c='竞争对手'); Product2 prod08 = new Product2(Name='Test08',ProductCode='Test08',Asset_Model_No__c = 'Test08',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1,Category5__c='竞争对手'); Product2 prod09 = new Product2(Name='Test09',ProductCode='Test09',Asset_Model_No__c = 'Test09',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1,Category5__c='竞争对手'); insert new Product2[] {prod07,prod08,prod09}; //Product2__c pro1 = new Product2__c(Name='MH-364:帽',Product2__c = prod01.Id); //Product2__c pro2 = new Product2__c(Name='MH-462:透明黏膜吸套',Product2__c = prod02.Id); //Product2__c pro5 = new Product2__c(Name='MH-155:白平衡帽',Product2__c = prod03.Id); //Product2__c pro3 = new Product2__c(Name='MB-677:BNC电缆',Product2__c = prod04.Id); //Product2__c pro4 = new Product2__c(Name='70236110:金刚砂锥状钻头,70度',Product2__c = prod05.Id); //Product2__c pro6 = new Product2__c(Name='MAJ-643R:水囊鞘管',Product2__c = prod06.Id); //制作产品 Product2__c proG = new Product2__c(Name='MH-155:白平衡帽',OT_CODE_Text__c='Test001',Product2__c = prod07.Id); insert proG; Product2__c proH = new Product2__c(Name='MB-677:BNC电缆',OT_CODE_Text__c='Test002',Product2__c = prod08.Id); insert proH; Product2__c proF = new Product2__c(Name='TooMAJ-643R:水囊鞘管003',OT_CODE_Text__c='Test003',Product2__c = prod09.Id); insert proF; //Product2__c proD = new Product2__c(Name='70236110:金刚砂锥状钻头,70度',OT_CODE_Text__c='Test003',Product2__c = prod09.Id); //insert proD; //insert new Product2__c[] {pro1, pro2,pro3,pro4, pro5, pro6}; //预制头明细 Consumable_order__c CreateId = new Consumable_order__c(); CreateId.Name = 'testMing'; CreateId.Order_status__c = '草案中'; CreateId.RecordTypeid = System.Label.RT_ConOrder_Order; CreateId.Dealer_Info__c = myAccount1.id; CreateId.Inventory_date__c = Date.today(); CreateId.Order_type__c = '盘点'; CreateId.Order_ProType__c = 'ET'; insert CreateId; //制作Consumable_order_details__c-------ProductCount Consumable_order_details2__c dataForProductCount9 = new Consumable_order_details2__c(); dataForProductCount9.Bar_Code__c = '1234567890'; dataForProductCount9.Sterilization_limit__c = Date.today().addDays(2); dataForProductCount9.Arrive_date__c = Date.today(); dataForProductCount9.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery; dataForProductCount9.Consumable_Product__c = proG.id; dataForProductCount9.Asset_Model_No__c = proG.Asset_Model_No__c; dataForProductCount9.Box_Piece__c = '盒'; dataForProductCount9.Consumable_order_minor__c = CreateId.id; dataForProductCount9.Send_Date__c = null; dataForProductCount9.Used_date__c = null; dataForProductCount9.Lose_Flag__c = false; dataForProductCount9.RemoveBox_No__c = 1; insert dataForProductCount9; Consumable_order_details2__c dataForProductCount8 = new Consumable_order_details2__c(); dataForProductCount8.Bar_Code__c = '1234567891'; dataForProductCount8.Sterilization_limit__c = Date.today().addDays(2); dataForProductCount8.Arrive_date__c = Date.today(); dataForProductCount8.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery; dataForProductCount8.Consumable_Product__c = proG.id; dataForProductCount8.Asset_Model_No__c = proG.Asset_Model_No__c; dataForProductCount8.Box_Piece__c = '盒'; dataForProductCount8.Consumable_order_minor__c = CreateId.id; dataForProductCount8.Send_Date__c = null; dataForProductCount8.Used_date__c = null; dataForProductCount8.Lose_Flag__c = false; dataForProductCount8.RemoveBox_No__c = 1; insert dataForProductCount8; Consumable_order_details2__c dataForProductCount7 = new Consumable_order_details2__c(); dataForProductCount7.Bar_Code__c = '1234567892'; dataForProductCount7.Sterilization_limit__c = Date.today().addDays(2); dataForProductCount7.Arrive_date__c = Date.today(); dataForProductCount7.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery; dataForProductCount7.Consumable_Product__c = proH.id; dataForProductCount7.Asset_Model_No__c = proH.Asset_Model_No__c; dataForProductCount7.Box_Piece__c = '个'; dataForProductCount7.Consumable_order_minor__c = CreateId.id; dataForProductCount7.Send_Date__c = null; dataForProductCount7.Used_date__c = null; dataForProductCount7.Lose_Flag__c = false; dataForProductCount7.RemoveBox_No__c = 1; insert dataForProductCount7; Consumable_order_details2__c dataForProductCount6 = new Consumable_order_details2__c(); dataForProductCount6.Bar_Code__c = '1234567893'; dataForProductCount6.Sterilization_limit__c = Date.today().addDays(2); dataForProductCount6.Arrive_date__c = Date.today(); dataForProductCount6.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery; dataForProductCount6.Consumable_Product__c = proH.id; dataForProductCount6.Asset_Model_No__c = proH.Asset_Model_No__c; dataForProductCount6.Box_Piece__c = '个'; dataForProductCount6.Consumable_order_minor__c = CreateId.id; dataForProductCount6.Send_Date__c = null; dataForProductCount6.Used_date__c = null; dataForProductCount6.Lose_Flag__c = false; dataForProductCount6.RemoveBox_No__c = 1; insert dataForProductCount6; Consumable_order_details2__c dataForProductCount5 = new Consumable_order_details2__c(); dataForProductCount5.Bar_Code__c = '1234567894'; dataForProductCount5.Sterilization_limit__c = Date.today().addDays(2); dataForProductCount5.Arrive_date__c = Date.today(); dataForProductCount5.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery; dataForProductCount5.Consumable_Product__c = proH.id; dataForProductCount5.Asset_Model_No__c = proH.Asset_Model_No__c; dataForProductCount5.Box_Piece__c = '个'; dataForProductCount5.Consumable_order_minor__c = CreateId.id; dataForProductCount5.Send_Date__c = null; dataForProductCount5.Used_date__c = null; dataForProductCount5.Lose_Flag__c = false; dataForProductCount5.RemoveBox_No__c = 1; insert dataForProductCount5; PageReference page = new Pagereference('/Inventory'); page.setRedirect(true); System.Test.setCurrentPage(page); InventoryController OwnTest = new InventoryController(); System.Test.startTest(); OwnTest.init(); OwnTest.barcode = ''; OwnTest.ConsumableorderdetailsRecordsview[0][0].check = true; OwnTest.ConsumableorderdetailsRecordsview[0][1].check = true; OwnTest.searchConsumableorderdetails(); OwnTest.save(); OwnTest = new InventoryController(); OwnTest.init(); OwnTest.barcode = '1234567890\n1234567891\n1234567892\n1234567893\n1234567814'; //OwnTest.ConsumableorderdetailsRecordsview[0][0].check = true; //OwnTest.ConsumableorderdetailsRecordsview[0][1].check = true; OwnTest.searchConsumableorderdetails(); OwnTest.save(); System.Test.stopTest(); } } }