高章伟
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
@isTest
private class OverdueStockControllerTest {
    static testMethod void testMethod1() {
        
        Profile prof1 = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证'];
        List<RecordType> 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;
        system.runAs(MyUser_Test){
            //产品数据
            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);
            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);
            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);
            insert new Product2[] {prod07,prod08,prod09};
 
            //制作产品
            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;
 
 
            //订单
            Consumable_order__c order = new Consumable_order__c();
            order.Name = 'testMing';
            order.Order_status__c = '批准';
            order.RecordTypeid = System.Label.RT_ConOrder_Order;
            order.Dealer_Info__c = myAccount1.id;
            order.Inventory_date__c = Date.today();
            order.Order_type__c = '订单';
            order.Order_ProType__c = 'ET';
            insert  order;
 
            //制作Consumable_order_details__c-------ProductCount
            // 销售
            Consumable_order_details2__c dataForProductCount7 = new Consumable_order_details2__c();
            dataForProductCount7.Bar_Code__c               = '123456789298k250AAAAA';
            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.Used_date__c = Date.today();
            dataForProductCount7.Consumable_order_minor__c = order.id;
            insert dataForProductCount7;
            // 在库 过期 盒
            Consumable_order_details2__c dataForProduct = new Consumable_order_details2__c();
            dataForProduct.Bar_Code__c               = '123456789498k250BBBBB';
            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 = order.id;
            insert dataForProduct;
            // 在库 过期 个
            Consumable_order_details2__c dataForProductCount3 = new Consumable_order_details2__c();
            dataForProductCount3.Bar_Code__c               = '123456788398k250CCCCC';
            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.Box_Piece__c              = '个';
            dataForProductCount3.RemoveBox_No__c = 1;
            dataForProductCount3.Consumable_order_minor__c = order.id;
            insert dataForProductCount3;
            
    
             PageReference page = new Pagereference('/OverdueStock');
             page.setRedirect(true);
            System.Test.setCurrentPage(page);
            OverdueStockController OwnTest = new OverdueStockController();
            System.Test.startTest();
            OwnTest.init();
            System.assertEquals(2, OwnTest.codPageRecords.size());
 
            
            OwnTest.barcode = '123456789298k250AAAAA\n123456789498k250BBBBB\n123456788398k250CCCCC';
            OwnTest.searchorderBean();
            System.assertEquals(3, OwnTest.overduePageRecords.size());
 
            OwnTest.save();
            System.Test.stopTest();
        }
    }
}