@isTest
private class LexConsumableOrderTest {
    static testMethod void testMethod1() {
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        // Profile prof = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证(ET Email)'];
        Profile prof = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证(ET)'];


        Account myAccount2 = new Account(name='Testaccount002',Dealer_discount__c =20,RecordTypeId = rectCo[0].Id,AgentCode_Ext__c = '9999900');
        Account myAccount1 = new Account(name='Testaccount001',Dealer_discount__c =30,RecordTypeId = rectCo[0].Id);
        insert new account[]{myAccount1,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 = prof.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com',UserPro_Type__c = 'ET');
        System.runAs(new User(Id = UserInfo.getUserId())){
            insert MyUser_Test;
        }

        // User MyUser_Test = [select id,Contact.accountid from User WHERE ProfileId = :prof.Id and IsActive = true and UserPro_Type__c = 'ET' limit 1 ];
        // Product2 prod01 = new Product2(Name='Test01',ProductCode='Test01',Asset_Model_No__c = 'Test01',SFDA_Status__c = '有効',JANCODE__c = '04953170200311',Dealer_special_Object__c = true,Manual_Entry__c = false);
        // Product2 prod02 = new Product2(Name='Test02',ProductCode='Test02',Asset_Model_No__c = 'Test02',SFDA_Status__c = '有効',JANCODE__c = '04953170200312',Dealer_special_Object__c = true,Manual_Entry__c = false);
        // insert new Product2[] {prod01,prod02};
        system.runAs(MyUser_Test){
            Product2 prod01 = new Product2(Name='Test01',ProductCode='Test01',Asset_Model_No__c = 'Test01',SFDA_Status__c = '有効',JANCODE__c = '04953170200311',Dealer_special_Object__c = true,Manual_Entry__c = false);
            Product2 prod02 = new Product2(Name='Test02',ProductCode='Test02',Asset_Model_No__c = 'Test02',SFDA_Status__c = '有効',JANCODE__c = '04953170200312',Dealer_special_Object__c = true,Manual_Entry__c = false);
            insert new Product2[] {prod01,prod02};
            Product2__c pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='N3047730',Product2__c = prod01.Id);
            Product2__c pro2 = new Product2__c(Name='Pro002',OT_CODE_Text__c='N3047731',Product2__c = prod02.Id);
            insert new Product2__c[] {pro1, pro2};
            //订单

            Consumable_order__c Order1 = new Consumable_order__c();
            Order1.Name = 'OCM_01_001';
            Order1.Order_status__c = '批准';
            Order1.Order_type__c = '订单';
            Order1.Dealer_Info__c = myAccount1.id;
            Order1.RecordTypeid = System.Label.RT_ConOrder_Delivery;
            Order1.Order_ProType__c = 'ET';
            insert Order1;

            //订单明细
            //fahuo
            Consumable_orderdetails__c Orderdet = new Consumable_orderdetails__c();
            Orderdet.Name = 'OCM_01_00101';
            Orderdet.Consumable_order__c = Order1.Id;
            Orderdet.RecordTypeId = System.Label.RT_ConOrderDetail1_Order;
            Orderdet.Consumable_Product__c = pro1.Id;
            Orderdet.Consumable_count__c = 4;
            insert Orderdet;
            Consumable_order_details2__c Orderdet1 = new Consumable_order_details2__c();
            Orderdet1.Name = 'OCM_01_001001';
            Orderdet1.Consumable_order_minor__c = Order1.Id;
            Orderdet1.Consumable_Product__c = pro1.Id;
            Orderdet1.Asset_Model_No__c = 'Test01';
            Orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet1.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRF';
            Orderdet1.TracingCode__c = 'BXJRF';
            Orderdet1.SerialLotNo__c = '5ZK';

            insert Orderdet1;
        LexConsumableOrder.initConsumableOrder(Order1.Id);
        LexConsumableOrder.initConsumableOrder('123xx123');
        LexConsumableOrder.updateConsumableOrder(Order1.Id,System.Label.RT_ConOrder_Delivery);
        LexConsumableOrder.updateConsumableOrder('123123xx123',System.Label.RT_ConOrder_Delivery);
        LexConsumableOrder.selectDeteails(Orderdet.Id);
        LexConsumableOrder.selectDeteails('123123xx123');
        LexConsumableOrder.create(Orderdet1);
    	}
    }
}