@isTest
|
private class SampleInventoryControllerTest {
|
static testMethod void testSample_01() {
|
// 客户记录类型
|
List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '办事处'];
|
if (rectCo.size() == 0) {
|
throw new ControllerUtil.myException('not found 办事处 recodetype');
|
}
|
List<RecordType> rectCo1 = [select Id from RecordType where IsActive = true and SobjectType = 'Sample_order_list_detail__c' and Name = '盘点'];
|
if (rectCo.size() == 0) {
|
throw new ControllerUtil.myException('not found 盘点 recodetype');
|
}
|
// 客户
|
Account account2 = new Account();
|
account2.Name = 'test1经销商';
|
account2.RecordTypeId = '01210000000Qem1';
|
insert account2;
|
Account Agency = new Account();
|
Agency.RecordTypeId = rectCo[0].Id;
|
Agency.Name = 'Katsu テスト';
|
Agency.Quolified_Approve_Status__c = 'Draft';
|
Agency.If_Need_Quolified__c = true;
|
Agency.ParentId = account2.Id;
|
insert Agency;
|
// 产品
|
Product2 product = new Product2();
|
product.Name = 'test01';
|
product.ProductCode = 'n011';
|
product.Packing_list_manual__c = 5;
|
product.SFDA_Expiration_Date__c = Date.today().addDays(1);
|
product.Asset_Model_No__c = 'n01';
|
product.Whether_Sample__c = true;
|
product.SFDA_Status__c = '有効';
|
insert product;
|
|
Product2 product1 = new Product2();
|
product1.Name = 'test02';
|
product1.ProductCode = 'n022';
|
product1.Packing_list_manual__c = 5;
|
product1.SFDA_Expiration_Date__c = Date.today().addDays(-1);
|
product1.Asset_Model_No__c = 'n011';
|
product1.Whether_Sample__c = true;
|
product1.SFDA_Status__c = '失効(期限内生産済在庫対応)';
|
insert product1;
|
|
Product2 product2 = new Product2();
|
product2.Name = 'test022';
|
product2.ProductCode = 'n02212';
|
product2.Packing_list_manual__c = 5;
|
product2.SFDA_Expiration_Date__c = Date.today().addDays(-1);
|
product2.Asset_Model_No__c = 'n0111';
|
product2.Whether_Sample__c = true;
|
product2.SFDA_Status__c = '失効(期限内生産済在庫対応)';
|
insert product2;
|
|
// 盘点表头
|
Inventory_Header_New__c IHN = new Inventory_Header_New__c();
|
IHN.Account__c = Agency.Id;
|
insert IHN;
|
|
// 盘点明细
|
Sample_order_list_detail__c samOrderDetail = new Sample_order_list_detail__c();
|
samOrderDetail.Product__c = product.Id;
|
samOrderDetail.Standards__c = 1;
|
samOrderDetail.ItemQuantity__c = 1;
|
samOrderDetail.Inventory_Check__c = 10;
|
samOrderDetail.RecordTypeId = rectCo1[0].Id;
|
samOrderDetail.Inventory_Header__c = IHN.Id;
|
insert samOrderDetail;
|
|
//样本库存表
|
Sample_inventory_sheet__c samInventorySheet = new Sample_inventory_sheet__c();
|
samInventorySheet.ProductCode__c = product.ProductCode;
|
samInventorySheet.Agency__c = Agency.Id;
|
samInventorySheet.Inventory__c = 150;
|
samInventorySheet.ValidTo__c = Date.today().addDays(1);
|
samInventorySheet.Pro_Model__c = product.Asset_Model_No__c;
|
insert samInventorySheet;
|
|
Sample_inventory_sheet__c samInventorySheet1 = new Sample_inventory_sheet__c();
|
samInventorySheet1.ProductCode__c = product1.ProductCode;
|
samInventorySheet1.Agency__c = Agency.Id;
|
samInventorySheet1.Inventory__c = 1;
|
samInventorySheet1.ValidTo__c = Date.today().addDays(1);
|
samInventorySheet1.Pro_Model__c = product1.Asset_Model_No__c;
|
insert samInventorySheet1;
|
|
//进初始化生成数据的方法
|
Sample_inventory_sheet__c samInventorySheet2 = new Sample_inventory_sheet__c();
|
samInventorySheet2.ProductCode__c = product1.ProductCode;
|
samInventorySheet2.Agency__c = Agency.Id;
|
samInventorySheet2.Inventory__c = 150;
|
samInventorySheet2.ValidTo__c = Date.today().addDays(1);
|
samInventorySheet2.Pro_Model__c = product1.Asset_Model_No__c;
|
insert samInventorySheet2;
|
Sample_inventory_sheet__c samInventorySheet4 = new Sample_inventory_sheet__c();
|
samInventorySheet4.ProductCode__c = product1.ProductCode;
|
samInventorySheet4.Agency__c = Agency.Id;
|
samInventorySheet4.Inventory__c = 150;
|
samInventorySheet4.ValidTo__c = Date.today().addDays(-1);
|
samInventorySheet4.Pro_Model__c = product1.Asset_Model_No__c;
|
insert samInventorySheet4;
|
|
Sample_inventory_sheet__c samInventorySheet3 = new Sample_inventory_sheet__c();
|
samInventorySheet3.ProductCode__c = product2.ProductCode;
|
samInventorySheet3.Agency__c = Agency.Id;
|
samInventorySheet3.Inventory__c = 150;
|
samInventorySheet3.ValidTo__c = Date.today().addDays(-2);
|
samInventorySheet3.Pro_Model__c = product2.Asset_Model_No__c;
|
insert samInventorySheet3;
|
|
//样本库存记录表
|
Sample_stock_log_sheet__c SSLS = new Sample_stock_log_sheet__c();
|
SSLS.Sample_order_list_detail__c = samOrderDetail.Id;
|
SSLS.Agency__c = Agency.Id;
|
insert SSLS;
|
|
PageReference page = new PageReference('/apex/SampleInventory?accid=' + Agency.Id);
|
System.Test.setCurrentPage(page);
|
// ApexPages.currentPage().getParameters().put('accid', Agency.Id);
|
System.Test.StartTest();
|
SampleInventoryController samController = new SampleInventoryController();
|
samController.init();
|
samController.SIInfo[0].IFCount = true;
|
samController.SIInfo[0].Check = 149;
|
samController.SIInfo[1].IFCount = true;
|
samController.SIInfo[1].Check = 100;
|
samController.SIInfo[2].IFCount = true;
|
samController.SIInfo[2].Check = 100;
|
samController.InventoryConfirm();
|
System.Test.StopTest();
|
}
|
|
}
|