高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
@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');
        }
        // 客户
        Account Agency = new Account();
        Agency.RecordTypeId = rectCo[0].Id;
        Agency.Name = 'Katsu テスト';
        Agency.Quolified_Approve_Status__c = 'Draft';
        Agency.If_Need_Quolified__c = true;
        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        = '0121m000000xWyw';
        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();
    }
        
}