@isTest
private class ArriveGoodsControllerTest {
    //选择等待入库,包括01 和241
    @isTest
    static void arriveWithID() {
        // // TO DO: implement unit test
        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 List<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 List<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 List<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;

            //发货明细
            //fahuo
            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;

            PageReference page = new PageReference('/apex/ArriveGoods?ESetid=' + Order1.Id);
            System.Test.setCurrentPage(page);
            ArriveGoodsController Controller = new ArriveGoodsController();
            //初始化测试
            System.Test.startTest();
            Controller.init();
            Controller.barcode = '01049531702003111115120017181000105ZK250BXJRF\n01049531702003111115120017181000105ZK250BXJRA\n241N30477301115120017181000105ZK250BXJRI\n241N30477301115120017181000105ZK250\n01049531702003111115120017181000105ZK250';
            Controller.SearchPro();
            // System.assertEquals(1, Controller.ConsumableorderdetailsRecords.size());
            // System.assertEquals(2, Controller.consumableInventory.size());
            Controller.ArriveGoodsConfim();
            List<Consumable_order_details2__c> ins = [
                SELECT Id, Name
                FROM Consumable_order_details2__c
            ];
            // System.assertEquals(3, ins.size());
            System.Test.stopTest();
        }
    }

    //产品直接入库,包括01 和241
    @isTest
    static void arriveWithoutID() {
        // // TO DO: implement unit test
        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 List<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',ProductCode_Ext__c = 'Test01',SFDA_Status__c = '有効',JANCODE__c = '04953170200311',Dealer_special_Object__c = true,Manual_Entry__c = false);
        // Product2 prod02 = new Product2(Name='Test02',ProductCode='N3047731',ProductCode_Ext__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 List<Product2>{ prod01, prod02 };
            Product2__c pro1 = new Product2__c(Name = 'Pro001', OT_CODE_Text__c = 'Test01', Product2__c = prod01.Id);
            Product2__c pro2 = new Product2__c(Name = 'Pro002', OT_CODE_Text__c = 'N3047731', Product2__c = prod02.Id);
            insert new List<Product2__c>{ pro1, pro2 };
            PageReference page = new PageReference('/apex/ArriveGoods?ArrType=Arr');
            System.Test.setCurrentPage(page);
            ArriveGoodsController Controller = new ArriveGoodsController();
            //初始化测试
            System.Test.startTest();
            Controller.init();
            //排序
            Controller.barcode = '';
            Controller.SearchPro();
            Controller.barcode = '01049531702003111115120017181000105ZK250BXJRF\n241N30477311115120017181000105ZK250BXJRA\n241Test021115120017181000105ZK250\n01049531702003111115120017181000105ZK250';
            Controller.SearchPro();
            Controller.ArriveGoodsConfim();
            List<Consumable_order_details2__c> ins = [
                SELECT Id, Name
                FROM Consumable_order_details2__c
                WHERE Bar_Code__c IN ('01049531702003111115120017181000105ZK250BXJRF', '241N30477311115120017181000105ZK250BXJRA')
            ];
            // System.assertEquals(2, ins.size());
            System.Test.stopTest();
        }
    }
    //整体到货
    @isTest
    static void ArriveTest() {
        // // TO DO: implement unit test
        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)'
        ];

        Oly_TriggerHandler.bypass('ConsumableAssetHander');
        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 List<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 List<Product2>{ prod01, prod02 };
            Product2__c pro1 = new Product2__c(Name = 'Pro001', OT_CODE_Text__c = 'Test001', Product2__c = prod01.Id);
            insert new List<Product2__c>{ pro1 };
            // Account myAccount1 = new Account(name='Testaccount001',Dealer_discount__c =30,RecordTypeId = rectCo[0].Id);
            // insert myAccount1;
            Consumable_order__c Order2 = new Consumable_order__c();
            Order2.Name = 'OCM_02_001';
            Order2.Order_status__c = '批准';
            Order2.Order_type__c = '订单';
            Order2.Dealer_Info__c = myAccount1.Id;
            Order2.RecordTypeid = System.Label.RT_ConOrder_Delivery;
            insert Order2;
            //发错库 未到货
            Consumable_order_details2__c Orderdets8 = new Consumable_order_details2__c();
            Orderdets8.Name = 'OCM_01_001011';
            Orderdets8.Consumable_order_minor__c = Order2.Id;
            Orderdets8.Consumable_Product__c = pro1.Id;
            Orderdets8.Asset_Model_No__c = 'Test01';
            Orderdets8.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdets8.Bar_Code__c = '01049531702003111115120017181000105ZK250BXsys';
            Orderdets8.Box_Piece__c = '盒';
            Orderdets8.TracingCode__c = 'BXsys';
            Orderdets8.SerialLotNo__c = '5ZK';
            insert Orderdets8;

            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.Order_ProType__c = 'ET';
            Order1.RecordTypeid = System.Label.RT_ConOrder_Delivery;
            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_001002';
            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 = '01049531702003111115120017181000105ZK250BXJRA';
            Orderdet1.Box_Piece__c = '盒';
            Orderdet1.TracingCode__c = 'BXJRA';
            Orderdet1.SerialLotNo__c = '5ZK';
            //没到货
            Consumable_order_details2__c Orderdet2 = new Consumable_order_details2__c();
            Orderdet2.Name = 'OCM_01_001003';
            Orderdet2.Consumable_order_minor__c = Order1.Id;
            Orderdet2.Consumable_Product__c = pro1.Id;
            Orderdet2.Asset_Model_No__c = 'Test01';
            Orderdet2.Consumable_Arrived_order__c = Order1.Id;
            Orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet2.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRB';
            Orderdet2.Box_Piece__c = '盒';
            Orderdet2.TracingCode__c = 'BXJRB';
            Orderdet2.SerialLotNo__c = '5ZK';
            //销售产品
            Consumable_order_details2__c Orderdet3 = new Consumable_order_details2__c();
            Orderdet3.Name = 'OCM_01_001004';
            Orderdet3.Consumable_order_minor__c = Order1.Id;
            Orderdet3.Consumable_Product__c = pro1.Id;
            Orderdet3.Asset_Model_No__c = 'Test01';
            Orderdet3.Consumable_Arrived_order__c = Order1.Id;
            //Orderdet3.IsArrival__c = true;
            Orderdet3.Consumable_Sale_order__c = Order1.Id;
            Orderdet3.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet3.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRC';
            Orderdet3.Used_date__c = Date.today();
            Orderdet3.Arrive_date__c = Date.today();
            Orderdet3.Box_Piece__c = '盒';
            Orderdet3.TracingCode__c = 'BXJRC';
            Orderdet3.SerialLotNo__c = '5ZK';
            //Orderdet3.Box_Piece__c = '个';

            //出库产品
            Consumable_order_details2__c Orderdet4 = new Consumable_order_details2__c();
            Orderdet4.Name = 'OCM_01_001005';
            Orderdet4.Consumable_order_minor__c = Order1.Id;
            Orderdet4.Consumable_Product__c = pro1.Id;
            Orderdet4.Asset_Model_No__c = 'Test01';
            Orderdet4.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet4.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRD';
            Orderdet4.Send_Date__c = Date.today();
            Orderdet4.Arrive_date__c = Date.today();
            Orderdet4.Box_Piece__c = '盒';
            Orderdet4.TracingCode__c = 'BXJRD';
            Orderdet4.SerialLotNo__c = '5ZK';
            //Orderdet4.Box_Piece__c = '盒';
            //Orderdet4.Return_date__c = null;

            //已到货产品
            Consumable_order_details2__c Orderdet5 = new Consumable_order_details2__c();
            Orderdet5.Name = 'OCM_01_001006';
            Orderdet5.Consumable_order_minor__c = Order1.Id;
            Orderdet5.Consumable_Product__c = pro1.Id;
            Orderdet5.Asset_Model_No__c = 'Test01';
            Orderdet5.Consumable_Arrived_order__c = Order1.Id;
            Orderdet5.Consumable_Shipment_order__c = Order1.Id;
            Orderdet5.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet5.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRE';
            Orderdet5.Arrive_date__c = Date.today();
            Orderdet5.Box_Piece__c = '盒';
            Orderdet5.TracingCode__c = 'BXJRE';
            Orderdet5.SerialLotNo__c = '5ZK';
            insert new List<Consumable_order_details2__c>{ Orderdet1, Orderdet2, Orderdet3, Orderdet4, Orderdet5 };

            ArriveGoodsController Controller = new ArriveGoodsController();
            PageReference page = new PageReference('/apex/ArriveGoods?ArrType=Arr');
            System.Test.setCurrentPage(page);
            //初始化测试
            System.Test.startTest();
            Controller.init();
            //排序
            Controller.barcode = '01049531702003111115120017181000105ZK250BXJRA\n01049531702003111115120017181000105ZK250BXJRB\n01049531702003111115120017181000105ZK250BXJRC\n01049531702003111115120017181000105ZK250BXJRD\n01049531702003111115120017181000105ZK250BXJRE\n01049531702003111115120017181000105ZK250BX111\n01049531702003111115120017181000105ZK250BXJRF\n01049531702003111115120017181000105ZK250BXJRG\n01049531702003111115120017181000105ZK250BXsys';
            Controller.SearchPro();

            System.assertEquals('OCM_01_001002', controller.ConsumableorderdetailsRecords[0].esd.Name);
            // System.assertEquals(2, controller.ConsumableorderdetailsRecordserror.size());
            System.Test.stopTest();
        }
    }

    //整体到货
    @isTest
    static void ArriveTest1() {
        // // TO DO: implement unit test
        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)'
        ];

        Oly_TriggerHandler.bypass('ConsumableAssetHander');
        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 List<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 List<Product2>{ prod01, prod02 };
            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);
            insert new List<Product2__c>{ pro1, pro2 };
            // Account myAccount1 = new Account(name='Testaccount001',Dealer_discount__c =30,RecordTypeId = rectCo[0].Id);
            // insert myAccount1;
            Consumable_order__c Order2 = new Consumable_order__c();
            Order2.Name = 'OCM_02_001';
            Order2.Order_status__c = '批准';
            Order2.Order_type__c = '订单';
            Order2.Dealer_Info__c = myAccount1.Id;
            Order2.RecordTypeid = System.Label.RT_ConOrder_Delivery;
            insert Order2;
            //发错库 未到货
            Consumable_order_details2__c Orderdets8 = new Consumable_order_details2__c();
            Orderdets8.Name = 'OCM_01_001011';
            Orderdets8.Consumable_order_minor__c = Order2.Id;
            Orderdets8.Consumable_Product__c = pro1.Id;
            Orderdets8.Asset_Model_No__c = 'Test01';
            Orderdets8.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdets8.Bar_Code__c = '01049531702003111115120017181000105ZK250BXsys';
            Orderdets8.Box_Piece__c = '盒';
            Orderdets8.TracingCode__c = 'BXsys';
            Orderdets8.SerialLotNo__c = '5ZK';
            insert Orderdets8;

            //system.runAs(myUser_Test){
            //订单

            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.Order_ProType__c = 'ET';
            Order1.RecordTypeid = System.Label.RT_ConOrder_Delivery;
            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_001002';
            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 = '01049531702003111115120017181000105ZK250BXJRA';
            Orderdet1.TracingCode__c = 'BXJRA';
            Orderdet1.SerialLotNo__c = '5ZK';
            //没到货
            Consumable_order_details2__c Orderdet2 = new Consumable_order_details2__c();
            Orderdet2.Name = 'OCM_01_001003';
            Orderdet2.Consumable_order_minor__c = Order1.Id;
            Orderdet2.Consumable_Product__c = pro1.Id;
            Orderdet2.Asset_Model_No__c = 'Test01';
            Orderdet2.Consumable_Arrived_order__c = Order1.Id;
            Orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet2.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRB';
            Orderdet2.TracingCode__c = 'BXJRB';
            Orderdet2.SerialLotNo__c = '5ZK';
            //销售产品
            Consumable_order_details2__c Orderdet3 = new Consumable_order_details2__c();
            Orderdet3.Name = 'OCM_01_001004';
            Orderdet3.Consumable_order_minor__c = Order1.Id;
            Orderdet3.Consumable_Product__c = pro1.Id;
            Orderdet3.Asset_Model_No__c = 'Test01';
            Orderdet3.Consumable_Arrived_order__c = Order1.Id;
            Orderdet3.Consumable_Sale_order__c = Order1.Id;
            Orderdet3.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet3.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRC';
            Orderdet3.Used_date__c = Date.today();
            Orderdet3.Arrive_date__c = Date.today();
            Orderdet3.TracingCode__c = 'BXJRC';
            Orderdet3.SerialLotNo__c = '5ZK';

            //出库产品
            Consumable_order_details2__c Orderdet4 = new Consumable_order_details2__c();
            Orderdet4.Name = 'OCM_01_001005';
            Orderdet4.Consumable_order_minor__c = Order1.Id;
            Orderdet4.Consumable_Product__c = pro1.Id;
            Orderdet4.Asset_Model_No__c = 'Test01';
            Orderdet4.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet4.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRD';
            Orderdet4.Send_Date__c = Date.today();
            Orderdet4.TracingCode__c = 'BXJRD';
            Orderdet4.SerialLotNo__c = '5ZK';
            //Orderdet4.Box_Piece__c = '盒';
            //Orderdet4.Return_date__c = null;

            //已到货产品
            Consumable_order_details2__c Orderdet5 = new Consumable_order_details2__c();
            Orderdet5.Name = 'OCM_01_001006';
            Orderdet5.Consumable_order_minor__c = Order2.Id;
            Orderdet5.Consumable_Product__c = pro1.Id;
            Orderdet5.Asset_Model_No__c = 'Test01';
            Orderdet5.Consumable_Arrived_order__c = Order1.Id;
            Orderdet5.Consumable_Shipment_order__c = Order1.Id;
            Orderdet5.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet5.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRE';
            Orderdet5.Arrive_date__c = Date.today();
            Orderdet5.Box_Piece__c = '盒';
            Orderdet5.TracingCode__c = 'BXJRE';
            Orderdet5.SerialLotNo__c = '5ZK';
            insert new List<Consumable_order_details2__c>{ Orderdet1, Orderdet2, Orderdet3, Orderdet4, Orderdet5 };

            ArriveGoodsController Controller = new ArriveGoodsController();
            PageReference page = new PageReference('/apex/ArriveGoods?ArrType=Arr');
            System.Test.setCurrentPage(page);
            //初始化测试
            System.Test.startTest();
            Controller.init();
            //排序
            Controller.barcode = '01049531702003111115120017181000105ZK250BXJRA\n01049531702003111115120017181000105ZK250BXJRB\n01049531702003111115120017181000105ZK250BXJRC\n01049531702003111115120017181000105ZK250BXJRD\n01049531702003111115120017181000105ZK250BXJRE\n01049531702003111115120017181000105ZK250BXsun\n01049531702003111115120017181000105ZK250BXJRF\n01049531702003111115120017181000105ZK250BXJRG\n01049531702003111115120017181000105ZK250BXsys';
            Controller.SearchPro();

            System.assertEquals('OCM_01_001002', controller.ConsumableorderdetailsRecords[0].esd.Name);
            // System.assertEquals(1, controller.ConsumableorderdetailsRecordserror.size());
            System.Test.stopTest();
        }
    }

    //返品
    @isTest
    static void productReturn() {
        // // TO DO: implement unit test
        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 List<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 List<Product2>{ prod01, prod02 };
            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);
            insert new List<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';
            //返品订单

            Consumable_order__c Order2 = new Consumable_order__c();
            Order2.Name = 'OCM_01_002';
            Order2.Order_status__c = '批准';
            Order2.Order_type__c = '返品';
            Order2.Dealer_Info__c = myAccount1.id;
            Order2.RecordTypeid = System.Label.Dealer_Returned_Label;
            insert Order1;
            insert Order2;

            //订单明细
            //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;

            //发货明细
            //fahuo
            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 = 'Pro001';
            Orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet1.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRF';
            Orderdet1.TracingCode__c = 'BXJRF';
            //daohuo
            Consumable_order_details2__c Orderdet2 = new Consumable_order_details2__c();
            Orderdet2.Name = 'OCM_01_001002';
            Orderdet2.Consumable_order_minor__c = Order1.Id;
            Orderdet2.Consumable_Product__c = pro1.Id;
            Orderdet2.Asset_Model_No__c = 'Pro001';
            Orderdet2.Consumable_Arrived_order__c = Order1.Id;
            //Orderdet2.IsArrival__c = true;
            Orderdet2.Arrive_date__c = Date.today();
            Orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet2.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRI';
            Orderdet2.TracingCode__c = 'BXJRF';
            //sale
            Consumable_order_details2__c Orderdet3 = new Consumable_order_details2__c();
            Orderdet3.Name = 'OCM_01_001003';
            Orderdet3.Consumable_order_minor__c = Order1.Id;
            Orderdet3.Consumable_Product__c = pro1.Id;
            Orderdet3.Asset_Model_No__c = 'Pro001';
            Orderdet3.Consumable_Arrived_order__c = Order1.Id;
            //Orderdet3.IsArrival__c = true;
            Orderdet3.Arrive_date__c = Date.today();
            Orderdet3.Used_date__c = Date.today();
            Orderdet3.Consumable_Sale_order__c = Order1.Id;
            Orderdet3.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet3.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRJ';
            Orderdet3.Box_Piece__c = '盒';
            Orderdet3.TracingCode__c = 'BXJRF';
            //出库
            Consumable_order_details2__c Orderdet4 = new Consumable_order_details2__c();
            Orderdet4.Name = 'OCM_01_001004';
            Orderdet4.Consumable_order_minor__c = Order1.Id;
            Orderdet4.Consumable_Product__c = pro1.Id;
            Orderdet4.Asset_Model_No__c = 'Pro001';
            Orderdet4.Consumable_Arrived_order__c = Order1.Id;
            //Orderdet4.IsArrival__c = true;
            Orderdet4.Arrive_date__c = Date.today();
            Orderdet4.Send_Date__c = Date.today();
            Orderdet4.Consumable_Shipment_order__c = Order1.Id;
            Orderdet4.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet4.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRN';
            Orderdet4.Box_Piece__c = '个';
            Orderdet4.TracingCode__c = 'BXJRF';
            //quxiao
            Consumable_order_details2__c Orderdet5 = new Consumable_order_details2__c();
            Orderdet5.Name = 'OCM_01_001005';
            Orderdet5.Consumable_order_minor__c = Order1.Id;
            Orderdet5.Consumable_Product__c = pro1.Id;
            Orderdet5.Asset_Model_No__c = 'Pro001';
            Orderdet5.Cancellation_Date__c = Date.today();
            Orderdet5.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet5.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRZ';
            Orderdet5.Box_Piece__c = '盒';
            Orderdet5.TracingCode__c = 'BXJRF';
            //fanpin
            Consumable_order_details2__c Orderdet6 = new Consumable_order_details2__c();
            Orderdet6.Name = 'OCM_01_001006';
            Orderdet6.Consumable_order_minor__c = Order1.Id;
            Orderdet6.Consumable_Product__c = pro1.Id;
            Orderdet6.Asset_Model_No__c = 'Pro001';
            Orderdet6.Consumable_Return_order__c = Order2.Id;
            Orderdet6.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet6.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRA';
            Orderdet6.Box_Piece__c = '个';
            Orderdet6.TracingCode__c = 'BXJRF';

            insert new List<Consumable_order_details2__c>{ Orderdet1, Orderdet2, Orderdet3, Orderdet4, Orderdet5, Orderdet6 };
            PageReference page = new PageReference('/apex/ArriveGoods?ArrType=ReG');
            System.Test.setCurrentPage(page);
            ArriveGoodsController Controller = new ArriveGoodsController();
            //初始化测试
            System.Test.startTest();
            Controller.init();
            //排序
            Controller.barcode = '01049531702003111115120017181000105ZK250BXJRN\n01049531702003111115120017181000105ZK250BXJRF\n01049531702003111115120017181000105ZK250BXJRI\n01049531702003111115120017181000105ZK250BXJRN\n01049531702003111115120017181000105ZK250BXJRZ\n01049531702003111115120017181000105ZK250BXJRA\n01049531702003111115120017181000105ZK250BXJRI';
            Controller.SearchPro();
            //System.assertEquals(1, controller.ShowGoodsofReturnList.size());
            //System.assertEquals('OCM_01_001003', controller.ShowGoodsofReturnList[0].esd.Name);
            //System.assertEquals('OCM_01_001004', controller.ShowGoodsofReturnList[1].esd.Name);
            // System.assertEquals(5, controller.ConsumableorderdetailsRecordserror.size());    //tcm
            //System.assertEquals('Test01', controller.ConsumableorderdetailsRecordserror[1].Prod.Name__c);
            //System.assertEquals('OCM_01_001002', controller.ConsumableorderdetailsRecordserror[2].esd.Name);
            //System.assertEquals('OCM_02_001001', controller.ConsumableorderdetailsRecordserror[3].esd.Name);
            Controller.GoodsReturnCheck();
            controller.ShowGoodsofReturnList[0].esd.Return_reason__c = '多发';
            controller.ShowGoodsofReturnList[0].esd.Rrturn_count__c = 1;
            //System.assertEquals(1, controller.ShowGoodsofReturnList.size());
            Controller.UpdateGoodsOfReturn();
            Controller.ToReturnGoodsPage();
            Controller.geterrorsize();
            System.Test.stopTest();
        }
    }

    //返品
    @isTest
    static void productReturn_new() {
        // // TO DO: implement unit test
        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 List<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 List<Product2>{ prod01, prod02 };
            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);
            insert new List<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;
            //Consumable_order__c coc = [select Dealer_Info__r.name from Consumable_order__c where Id =:Order1.Id];
            //system.assertEquals('qeee',coc.Dealer_Info__r.name);

            //订单明细
            //fahuo
            Consumable_orderdetails__c Orderdet = new Consumable_orderdetails__c();
            Orderdet.Name = 'OCM_01_001001';
            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;

            //发货明细
            //fahuo
            /*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 = 'Pro001';
               Orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
               Orderdet1.Box_Piece__c ='盒';
               Orderdet1.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRF';
               //daohuo
               Consumable_order_details2__c Orderdet2 = new Consumable_order_details2__c();
               Orderdet2.Name = 'OCM_01_001002';
               Orderdet2.Consumable_order_minor__c = Order1.Id;
               Orderdet2.Consumable_Product__c = pro1.Id;
               Orderdet2.Asset_Model_No__c = 'Pro001';
               Orderdet2.Consumable_Arrived_order__c = Order1.Id;
               //Orderdet2.IsArrival__c = true;
               Orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
               Orderdet2.Box_Piece__c ='盒';
               Orderdet2.Arrive_date__c = Date.today();
               //Orderdet2.Send_Date__c = Date.today();
               //Orderdet2.Used_date__c= Date.today();
               Orderdet2.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRF';*/
            //sale
            Consumable_order_details2__c Orderdet3 = new Consumable_order_details2__c();
            Orderdet3.Name = 'OCM_01_001003';
            Orderdet3.Consumable_order_minor__c = Order1.Id;
            Orderdet3.Consumable_Product__c = pro1.Id;
            Orderdet3.Asset_Model_No__c = 'Pro001';
            Orderdet3.Consumable_Arrived_order__c = Order1.Id;
            //Orderdet3.IsArrival__c = true;
            Orderdet3.Consumable_Sale_order__c = Order1.Id;
            Orderdet3.Box_Piece__c = '盒';
            Orderdet3.Used_date__c = Date.today();
            Orderdet3.Arrive_date__c = Date.today();
            Orderdet3.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet3.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRF';
            Orderdet3.TracingCode__c = 'BXJRF';
            Orderdet3.SerialLotNo__c = '5ZK';
            //出库
            Consumable_order_details2__c Orderdet4 = new Consumable_order_details2__c();
            Orderdet4.Name = 'OCM_01_001004';
            Orderdet4.Consumable_order_minor__c = Order1.Id;
            Orderdet4.Consumable_Product__c = pro1.Id;
            Orderdet4.Asset_Model_No__c = 'Pro001';
            Orderdet4.Consumable_Arrived_order__c = Order1.Id;
            //Orderdet4.IsArrival__c = true;
            Orderdet4.Consumable_Shipment_order__c = Order1.Id;
            Orderdet4.Box_Piece__c = '个';
            Orderdet4.Send_Date__c = Date.today();
            Orderdet4.Arrive_date__c = Date.today();
            Orderdet4.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet4.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRN';
            Orderdet4.TracingCode__c = 'BXJRN';
            Orderdet4.SerialLotNo__c = '5ZK';
            //quxiao
            Consumable_order_details2__c Orderdet5 = new Consumable_order_details2__c();
            Orderdet5.Name = 'OCM_01_001005';
            Orderdet5.Consumable_order_minor__c = Order1.Id;
            Orderdet5.Consumable_Product__c = pro1.Id;
            Orderdet5.Asset_Model_No__c = 'Pro001';
            Orderdet5.Cancellation_Date__c = Date.today();
            Orderdet5.Cancellation_Flag__c = true;
            Orderdet5.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet5.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRZ';
            Orderdet5.Box_Piece__c = '个';
            Orderdet5.TracingCode__c = 'BXJRZ';
            Orderdet5.SerialLotNo__c = '5ZK';
            insert new List<Consumable_order_details2__c>{ Orderdet3, Orderdet4, Orderdet5 };

            PageReference page = new PageReference('/apex/ArriveGoods?ArrType=ReG');
            System.Test.setCurrentPage(page);
            ArriveGoodsController Controller = new ArriveGoodsController();
            //初始化测试
            System.Test.startTest();
            Controller.init();
            //排序
            Controller.barcode = '01049531702003111115120017181000105ZK250BXJRF\n01049531702003111115120017181000105ZK250BXJRN\n01049531702003111115120017181000105ZK250BXJRZ\n01049531702003111115120017181000105ZK250BXJRR';
            Controller.SearchPro();
            // System.assertEquals(1, controller.ConsumableorderdetailsRecordserror.size());
            System.assertEquals(2, controller.ShowGoodsofReturnList.size());
            controller.ShowGoodsofReturnList[0].esd.Return_reason__c = '多发';
            controller.ShowGoodsofReturnList[1].esd.Return_reason__c = '多发';
            controller.ShowGoodsofReturnList[0].esd.Rrturn_count__c = 1;
            Controller.UpdateGoodsOfReturn();

            list<String> list1 = new List<String>();
            list1.add(Controller.barcode = '01234567898');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '012345678901234A67');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '0123456789012345117AA01');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '01234567890123456789012349990001');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '0123456789012345177AA0000000000001');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '0123456789012345177AA1111111111111');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '241345');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '2413456');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '24134567');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '241345678');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '2413456789');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '24134567890');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '241345678901');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '0112345678901231177890121215678901234');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '0112345678901231106789012105678901234');
            Controller.inventoryEntryNoESetId(list1);
            list1.clear();
            list1.add(Controller.barcode = '0112345678901231106789012105625001234');
            Controller.inventoryEntryNoESetId(list1);
            System.Test.stopTest();
        }
    }

    //直接到货
    @isTest
    static void arrivedirect() {
        // // TO DO: implement unit test
        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 List<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 List<Product2>{ prod01, prod02 };
            Product2__c pro1 = new Product2__c(Name = 'Pro001', OT_CODE_Text__c = '2344', Product2__c = prod01.Id);
            Product2__c pro2 = new Product2__c(Name = 'Pro002', OT_CODE_Text__c = '82324', Product2__c = prod02.Id);
            insert new List<Product2__c>{ pro1, pro2 };
            //产品注册证
            Product_Register__c prc = new Product_Register__c(
                Name = '国械注进20162220210',
                MedPrdClass__c = '3',
                ValidFrom__c = date.newinstance(2018, 7, 22),
                ValidTo__c = date.newinstance(2028, 7, 22),
                RegisterNoClass_Old__c = '6815',
                RegisterNoClass_New__c = '6815',
                RegisterNoStatus__c = '有效'
            );
            insert prc;
            //新旧关系对照表
            //Product_Register_contrast__c prcc = new Product_Register_contrast__c(
            //                                        Name = 'Test20181204',
            //                                        Register_new__c = '314',
            //                                        Register_old__c = '36815'
            //                                        );
            //insert prcc;
            //产品-产品注册证关系  prod01
            Product_Register_Link__c prlc = new Product_Register_Link__c(Product2__c = prod01.Id, Product_Register__c = prc.Id);
            insert prlc;
            //产品-产品注册证关系  prod02
            Product_Register_Link__c prlc2 = new Product_Register_Link__c(Product2__c = prod02.Id, Product_Register__c = prc.Id);
            insert prlc2;
            //订单

            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;
            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;

            //发货明细
            //fahuo
            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';
            //daohuo
            Consumable_order_details2__c Orderdet2 = new Consumable_order_details2__c();
            Orderdet2.Name = 'OCM_01_001002';
            Orderdet2.Consumable_order_minor__c = Order1.Id;
            Orderdet2.Consumable_Product__c = pro1.Id;
            Orderdet2.Asset_Model_No__c = 'Test01';
            Orderdet2.Consumable_Arrived_order__c = Order1.Id;
            //Orderdet2.IsArrival__c = true;
            Orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet2.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRI';
            //sale
            Consumable_order_details2__c Orderdet3 = new Consumable_order_details2__c();
            Orderdet3.Name = 'OCM_01_001003';
            Orderdet3.Consumable_order_minor__c = Order1.Id;
            Orderdet3.Consumable_Product__c = pro1.Id;
            Orderdet3.Asset_Model_No__c = 'Test01';
            Orderdet3.Consumable_Arrived_order__c = Order1.Id;
            //Orderdet3.IsArrival__c = true;
            Orderdet3.Consumable_Sale_order__c = Order1.Id;
            Orderdet3.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet3.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRJ';
            //出库
            Consumable_order_details2__c Orderdet4 = new Consumable_order_details2__c();
            Orderdet4.Name = 'OCM_01_001004';
            Orderdet4.Consumable_order_minor__c = Order1.Id;
            Orderdet4.Consumable_Product__c = pro1.Id;
            Orderdet4.Asset_Model_No__c = 'Test01';
            Orderdet4.Consumable_Arrived_order__c = Order1.Id;
            //Orderdet4.IsArrival__c = true;
            Orderdet4.Consumable_Shipment_order__c = Order1.Id;
            Orderdet4.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet4.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRN';
            //List<Product2> proList = [select name,Estimation_Entry_Possibility__c from Product2 where id = :prod01.Id];
            //System.assertEquals('○', proList[0].Estimation_Entry_Possibility__c);

            insert new List<Consumable_order_details2__c>{ Orderdet1, Orderdet2, Orderdet3, Orderdet4 };
            PageReference page = new PageReference('/apex/ArriveGoods?Esetid=' + Order1.Id);
            System.Test.setCurrentPage(page);
            ArriveGoodsController Controller = new ArriveGoodsController();
            //初始化测试
            System.Test.startTest();
            Controller.init();
            Controller.barcode = '01049531702003111115120017181000105ZK250BXJRF\n01049531702003111115120017181000105ZK250BXJRI\n01049531702003111115120017181000105ZK250BXJRN';
            Controller.SearchPro();
            //System.assertEquals(1, controller.consumableInventory.size());

            System.Test.stopTest();
        }
    }

    //直接到货
    @isTest
    static void arrivedirect241() {
        // // TO DO: implement unit test
        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 List<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 List<Product2>{ prod01, prod02 };
            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);
            insert new List<Product2__c>{ pro1, pro2 };
            //产品注册证
            Product_Register__c prc = new Product_Register__c(
                Name = '国械注进20162220210',
                MedPrdClass__c = '3',
                ValidFrom__c = date.newinstance(2018, 7, 22),
                ValidTo__c = date.newinstance(2028, 7, 22),
                RegisterNoClass_Old__c = '6815',
                RegisterNoClass_New__c = '6815',
                RegisterNoStatus__c = '有效'
            );
            insert prc;
            //新旧关系对照表
            //Product_Register_contrast__c prcc = new Product_Register_contrast__c(
            //                                        Name = 'Test20181204',
            //                                        Register_new__c = '314',
            //                                        Register_old__c = '36815'
            //                                        );
            //insert prcc;
            //产品-产品注册证关系  prod01
            Product_Register_Link__c prlc = new Product_Register_Link__c(Product2__c = prod01.Id, Product_Register__c = prc.Id);
            insert prlc;
            //产品-产品注册证关系  prod02
            Product_Register_Link__c prlc2 = new Product_Register_Link__c(Product2__c = prod02.Id, Product_Register__c = prc.Id);
            insert prlc2;
            //订单

            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;
            insert Order1;
            Consumable_order__c Order2 = new Consumable_order__c();
            Order2.Name = 'OCM_01_002';
            Order2.Order_status__c = '批准';
            Order2.Order_type__c = '到货';
            Order2.Dealer_Info__c = myAccount1.id;
            Order2.RecordTypeid = System.Label.RT_ConOrder_Delivery;
            Order2.Deliver_date__c = Date.today();
            Order2.Order_date__c = Date.today();
            insert Order2;
            Order2 = new Consumable_order__c();
            Order2.Name = 'OCM_01_002';
            Order2.Order_status__c = '批准';
            Order2.Order_type__c = '返品';
            Order2.Dealer_Info__c = myAccount1.id;
            Order2.RecordTypeid = System.Label.RT_ConOrder_Delivery;
            Order2.Deliver_date__c = Date.today();
            Order2.Order_date__c = Date.today();
            Order2.ReturnGs_Upload_Date__c = Date.today();
            insert Order2;

            //订单明细
            //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;

            //发货明细
            //fahuo
            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.Arrive_date__c = Date.today();
            Orderdet1.Rrturn_count__c = 1;
            Orderdet1.TracingCode__c = '20170808';
            //daohuo
            Consumable_order_details2__c Orderdet2 = new Consumable_order_details2__c();
            Orderdet2.Name = 'OCM_01_001002';
            Orderdet2.Consumable_order_minor__c = Order2.Id;
            Orderdet2.Consumable_Product__c = pro1.Id;
            Orderdet2.Asset_Model_No__c = 'Test01';
            Orderdet2.Consumable_Arrived_order__c = Order2.Id;
            //Orderdet2.IsArrival__c = true;
            Orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet2.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRI';
            Orderdet2.Arrive_date__c = Date.today();
            Orderdet2.TracingCode__c = '20170808';

            Consumable_order_details2__c Orderdet3 = new Consumable_order_details2__c();
            Orderdet3.Name = 'OCM_01_001002';
            Orderdet3.Consumable_order_minor__c = Order2.Id;
            Orderdet3.Consumable_Product__c = pro1.Id;
            Orderdet3.Asset_Model_No__c = 'Test01';
            Orderdet3.Consumable_Arrived_order__c = Order2.Id;
            //Orderdet3.IsArrival__c = true;
            Orderdet3.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet3.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJR2';
            Orderdet3.Used_date__c = Date.today();
            Orderdet3.TracingCode__c = '20170808';
            //sale
            Consumable_order_details2__c Orderdet4 = new Consumable_order_details2__c();
            Orderdet4.Name = 'OCM_01_001003';
            Orderdet4.Consumable_order_minor__c = Order2.Id;
            Orderdet4.Consumable_Product__c = pro1.Id;
            Orderdet4.Asset_Model_No__c = 'Test01';
            Orderdet4.Consumable_Arrived_order__c = Order2.Id;
            //Orderdet3.IsArrival__c = true;
            Orderdet4.Consumable_Sale_order__c = Order2.Id;
            Orderdet4.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet4.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJR3';
            Orderdet4.Used_date__c = Date.today();
            Orderdet4 = new Consumable_order_details2__c();
            Orderdet4.Name = 'OCM_01_001003';
            Orderdet4.Consumable_order_minor__c = Order1.Id;
            Orderdet4.Consumable_Product__c = pro1.Id;
            Orderdet4.Asset_Model_No__c = 'Test01';
            Orderdet4.Consumable_Arrived_order__c = Order1.Id;
            //Orderdet3.IsArrival__c = true;
            Orderdet4.Consumable_Sale_order__c = Order2.Id;
            Orderdet4.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet4.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJ13';
            Orderdet4.Used_date__c = Date.today();
            Orderdet4.TracingCode__c = '20170808';
            Consumable_order_details2__c Orderdet5 = new Consumable_order_details2__c();
            Orderdet5.Name = 'OCM_01_001003';
            Orderdet5.Consumable_order_minor__c = Order2.Id;
            Orderdet5.Consumable_Product__c = pro1.Id;
            Orderdet5.Asset_Model_No__c = 'Test01';
            Orderdet5.Consumable_Arrived_order__c = Order2.Id;
            //Orderdet3.IsArrival__c = true;
            Orderdet5.Consumable_Sale_order__c = Order2.Id;
            Orderdet5.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet5.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRJ';
            Orderdet5.Arrive_date__c = Date.today().addDays(1);
            Orderdet5.Send_Date__c = null;
            Orderdet5.Used_date__c = null;
            Orderdet5.Lose_Flag__c = false;
            Orderdet5.Return_date__c = null;
            Orderdet5.Cancellation_Date__c = Date.today().addDays(1);
            Orderdet5.Box_Piece__c = '盒';
            Orderdet5.TracingCode__c = '20170808';

            //出库
            Consumable_order_details2__c Orderdet6 = new Consumable_order_details2__c();
            Orderdet6.Name = 'OCM_01_001004';
            Orderdet6.Consumable_order_minor__c = Order1.Id;
            Orderdet6.Consumable_Product__c = pro1.Id;
            Orderdet6.Asset_Model_No__c = 'Test01';
            Orderdet6.Consumable_Arrived_order__c = Order1.Id;
            //Orderdet4.IsArrival__c = true;
            Orderdet6.Consumable_Shipment_order__c = Order1.Id;
            Orderdet6.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet6.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJR4';
            Orderdet6.Send_Date__c = Date.today();
            Orderdet6.Return_date__c = null;
            Orderdet6.Box_Piece__c = '盒';
            Orderdet6.Rrturn_count__c = 1;
            Orderdet6.TracingCode__c = '20170808';

            // 单位为个的Barcode对应的出库单
            Consumable_order_details2__c Orderdet7 = new Consumable_order_details2__c();
            Orderdet7.Name = 'OCM_01_001004';
            Orderdet7.Consumable_order_minor__c = Order1.Id;
            Orderdet7.Consumable_Product__c = pro1.Id;
            Orderdet7.Asset_Model_No__c = 'Test01';
            Orderdet7.Consumable_Arrived_order__c = Order1.Id;
            //Orderdet4.IsArrival__c = true;
            Orderdet7.Consumable_Shipment_order__c = Order1.Id;
            Orderdet7.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet7.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJR1';
            Orderdet7.Send_Date__c = Date.today();
            Orderdet7.Box_Piece__c = '个';
            Orderdet7.Used_date__c = Date.today();
            Orderdet7.Return_date__c = null;
            Orderdet7.RemoveBox_No__c = 1;
            Orderdet7.Consumable_ZS_order__c = Order1.Id;
            Orderdet7.Rrturn_count__c = 1;
            Orderdet7.TracingCode__c = '20170808';

            Orderdet7 = new Consumable_order_details2__c();
            Orderdet7.Name = 'OCM_01_001004';
            Orderdet7.Consumable_order_minor__c = Order1.Id;
            Orderdet7.Consumable_Product__c = pro1.Id;
            Orderdet7.Asset_Model_No__c = 'Test01';
            Orderdet7.Consumable_Arrived_order__c = Order1.Id;
            Orderdet7.Consumable_Shipment_order__c = Order1.Id;
            Orderdet7.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet7.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJR7';
            Orderdet7.Send_Date__c = Date.today();
            Orderdet7.Box_Piece__c = '个';
            Orderdet7.Used_date__c = Date.today();
            Orderdet7.Return_date__c = null;
            Orderdet7.RemoveBox_No__c = 1;
            Orderdet7.Consumable_ZS_order__c = Order1.Id;
            Orderdet7.Rrturn_count__c = 0;
            Orderdet7.TracingCode__c = '20170808';

            Consumable_order_details2__c Orderdet8 = new Consumable_order_details2__c();
            Orderdet8.Name = 'OCM_01_001004';
            Orderdet8.Consumable_order_minor__c = Order1.Id;
            Orderdet8.Consumable_Product__c = pro1.Id;
            Orderdet8.Asset_Model_No__c = 'Test01';
            Orderdet8.Consumable_Arrived_order__c = Order1.Id;
            //Orderdet4.IsArrival__c = true;
            Orderdet8.Consumable_Shipment_order__c = Order1.Id;
            Orderdet8.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet8.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJR9';
            Orderdet8.Send_Date__c = Date.today();
            Orderdet8.Box_Piece__c = '个';
            Orderdet8.Used_date__c = Date.today();
            Orderdet8.Return_date__c = null;
            Orderdet8.RemoveBox_No__c = 1;
            Orderdet8.Consumable_ZS_order__c = Order1.Id;
            Orderdet8.Rrturn_count__c = null;
            Orderdet8.RemoveBox_date__c = Date.today();
            Orderdet8.Intra_Trade_List_RMB__c = 1;
            Orderdet8.Sterilization_limit__c = Date.today();
            Orderdet8.SerialLotNo__c = '11批次';
            Orderdet8.TracingCode__c = '20170808';
            Orderdet8.Arrive_date__c = Date.today();

            Consumable_order_details2__c Orderdet9 = new Consumable_order_details2__c();
            Orderdet9.Name = 'OCM_01_001004';
            Orderdet9.Consumable_order_minor__c = Order1.Id;
            Orderdet9.Consumable_Product__c = pro1.Id;
            Orderdet9.Asset_Model_No__c = 'Test01';
            Orderdet9.Consumable_Arrived_order__c = Order1.Id;
            Orderdet9.Consumable_Shipment_order__c = Order1.Id;
            Orderdet9.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet9.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJR8';
            Orderdet9.Send_Date__c = Date.today();
            Orderdet9.Box_Piece__c = '个';
            Orderdet9.Used_date__c = Date.today();
            Orderdet9.Return_date__c = null;
            Orderdet9.Consumable_ZS_order__c = Order1.Id;
            Orderdet9.Arrive_date__c = Date.today();
            Orderdet9.Rrturn_count__c = 10;
            Orderdet9.TracingCode__c = '20170808';
            Consumable_order_details2__c lose = new Consumable_order_details2__c();
            lose.Name = 'OCM_01_001004';
            lose.Consumable_order_minor__c = Order1.Id;
            lose.Consumable_Product__c = pro1.Id;
            lose.Asset_Model_No__c = 'Test01';
            lose.Consumable_Arrived_order__c = Order1.Id;
            //Orderdet4.IsArrival__c = true;
            lose.Consumable_Shipment_order__c = Order1.Id;
            lose.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            lose.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJR5';
            lose.Send_Date__c = null;
            lose.Arrive_date__c = null;
            lose.Used_date__c = null;
            lose.Box_Piece__c = '盒';
            lose.TracingCode__c = '20170808';
            Consumable_order_details2__c lose1 = new Consumable_order_details2__c();
            lose1.Name = 'OCM_01_001004';
            lose1.Consumable_order_minor__c = Order1.Id;
            lose1.Consumable_Product__c = pro1.Id;
            lose1.Asset_Model_No__c = 'Test01';
            lose1.Consumable_Arrived_order__c = Order1.Id;
            //Orderdet4.IsArrival__c = true;
            lose1.Consumable_Shipment_order__c = Order1.Id;
            lose1.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            lose1.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJR6';
            lose1.Send_Date__c = null;
            lose1.Arrive_date__c = Date.today();
            lose1.Used_date__c = null;
            lose1.Box_Piece__c = '盒';
            lose1.TracingCode__c = '20170808';
            Consumable_order_details2__c lose2 = new Consumable_order_details2__c();
            lose2.Name = 'OCM_01_001004';
            lose2.Consumable_order_minor__c = Order2.Id;
            lose2.Consumable_Product__c = pro1.Id;
            lose2.Asset_Model_No__c = 'Test01';
            lose2.Consumable_Arrived_order__c = Order2.Id;
            //Orderdet4.IsArrival__c = true;
            lose2.Consumable_Shipment_order__c = Order2.Id;
            lose2.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            lose2.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJR7';
            lose2.Send_Date__c = null;
            lose2.Arrive_date__c = Date.today();
            lose2.Used_date__c = null;
            lose2.Box_Piece__c = '盒';
            lose2.Intra_Trade_List_RMB__c = 1;
            lose2.Direct_Arrive_Product__c = true;
            lose2.Sterilization_limit__c = Date.today();
            lose2.SerialLotNo__c = '11批次';
            lose2.TracingCode__c = '20170808';

            //List<Product2> proList = [select name,Estimation_Entry_Possibility__c from Product2 where id = :prod01.Id];
            //System.assertEquals('○', proList[0].Estimation_Entry_Possibility__c);

            insert new List<Consumable_order_details2__c>{
                Orderdet1,
                Orderdet2,
                Orderdet3,
                Orderdet4,
                Orderdet5,
                Orderdet6,
                Orderdet7,
                Orderdet8,
                Orderdet9,
                lose,
                lose1,
                lose2
            };
            PageReference page = new PageReference('/apex/ArriveGoods?Esetid=' + Order1.Id);
            System.Test.setCurrentPage(page);
            ArriveGoodsController Controller = new ArriveGoodsController();
            //初始化测试
            System.Test.startTest();
            Controller.init();

            Controller.barcode = '01049531702003111115120017181000105ZK250BXJRF\n01049531702003111115120017181000105ZK250BXJR3\n01049531702003111115120017181000105ZK250BXJ13\n01049531702003111115120017181000105ZK250BXJRI\n01049531702003111115120017181000105ZK250BXJR2\n01049531702003111115120017181000105ZK250BXJR3\n01049531702003111115120017181000105ZK250BXJR4\n01049531702003111115120017181000105ZK250BXJR1\n01049531702003111115120017181000105ZK250BXJR7\n01049531702003111115120017181000105ZK250BXJR9\n01049531702003111115120017181000105ZK250BXJR8\n01049531702003111115120017181000105ZK250BXJR5\n01049531702003111115120017181000105ZK250BXJR6\n01049531702003111115120017181000105ZK250BXJR7\n01049531702003111115120017181000105ZK250BXAAA\n01049531702003111115120017181000105ZK250BXAAB';
            Controller.SearchPro();
            // System.assertEquals(1, controller.consumableInventory.size());

            System.Test.stopTest();
        }
    }

    //返品 明细2不存在的对应的到货订单明细
    @isTest
    static void productReturn_oldbarcode() {
        // // TO DO: implement unit test
        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 List<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 List<Product2>{ prod01, prod02 };
            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);
            insert new List<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;

            //返品订单

            Consumable_order__c Order2 = new Consumable_order__c();
            Order2.Name = 'OCM_01_002';
            Order2.Order_status__c = '批准';
            Order2.Order_type__c = '返品';
            Order2.Dealer_Info__c = myAccount1.id;
            Order2.RecordTypeid = System.Label.Dealer_Returned_Label;
            insert Order1;
            insert Order2;

            //订单明细
            //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 = 'Pro001';
            Orderdet1.Arrive_date__c = date.today();
            Orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet1.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRF';
            Orderdet1.TracingCode__c = 'BXSYS';

            //daohuo
            Consumable_order_details2__c Orderdet2 = new Consumable_order_details2__c();
            Orderdet2.Name = 'OCM_01_001002';
            Orderdet2.Consumable_order_minor__c = Order1.Id;
            Orderdet2.Consumable_Product__c = pro1.Id;
            Orderdet2.Asset_Model_No__c = 'Pro001';
            Orderdet2.Consumable_Arrived_order__c = Order1.Id;
            Orderdet2.Arrive_date__c = date.today();
            Orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet2.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRI';
            Orderdet2.TracingCode__c = 'BXSYS';
            //sale
            Consumable_order_details2__c Orderdet3 = new Consumable_order_details2__c();
            Orderdet3.Name = 'OCM_01_001003';
            Orderdet3.Consumable_order_minor__c = Order1.Id;
            Orderdet3.Consumable_Product__c = pro1.Id;
            Orderdet3.Asset_Model_No__c = 'Pro001';
            Orderdet3.Consumable_Arrived_order__c = Order1.Id;
            Orderdet3.Arrive_date__c = date.today();
            Orderdet3.Used_date__c = date.today();
            Orderdet3.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet3.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRJ';
            Orderdet3.TracingCode__c = 'BXSYS';
            //出库
            Consumable_order_details2__c Orderdet4 = new Consumable_order_details2__c();
            Orderdet4.Name = 'OCM_01_001004';
            Orderdet4.Consumable_order_minor__c = Order1.Id;
            Orderdet4.Consumable_Product__c = pro1.Id;
            Orderdet4.Asset_Model_No__c = 'Pro001';
            Orderdet4.Consumable_Arrived_order__c = Order1.Id;
            Orderdet4.Consumable_Shipment_order__c = Order1.Id;
            Orderdet4.Send_Date__c = date.today();
            Orderdet4.Arrive_date__c = date.today();
            Orderdet4.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet4.Bar_Code__c = '01049531702003111115120017181000105ZK250BX222';
            Orderdet4.TracingCode__c = 'BXSYS';
            //quxiao
            Consumable_order_details2__c Orderdet5 = new Consumable_order_details2__c();
            Orderdet5.Name = 'OCM_01_001005';
            Orderdet5.Consumable_order_minor__c = Order1.Id;
            Orderdet5.Consumable_Product__c = pro1.Id;
            Orderdet5.Asset_Model_No__c = 'Pro001';
            Orderdet5.Cancellation_Date__c = Date.today();
            Orderdet5.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet5.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRZ';
            Orderdet5.Box_Piece__c = '个';
            Orderdet5.TracingCode__c = 'BXSYS';
            //fanpin
            Consumable_order_details2__c Orderdet6 = new Consumable_order_details2__c();
            Orderdet6.Name = 'OCM_01_001006';
            Orderdet6.Consumable_order_minor__c = Order1.Id;
            Orderdet6.Consumable_Product__c = pro1.Id;
            Orderdet6.Asset_Model_No__c = 'Pro001';
            Orderdet6.Consumable_Return_order__c = Order2.Id;
            Orderdet6.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet6.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRA';
            Orderdet6.Box_Piece__c = '个';
            Orderdet6.TracingCode__c = 'BXSYS';

            //发货明细
            //没出库，没销售，就是在库
            Consumable_order_details2__c Orderdet7 = new Consumable_order_details2__c();
            Orderdet7.Name = 'OCM_01_001001';
            Orderdet7.Consumable_order_minor__c = Order1.Id;
            Orderdet7.Consumable_Product__c = pro1.Id;
            Orderdet7.Asset_Model_No__c = 'Pro001';
            Orderdet7.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet7.Bar_Code__c = '01049531702003111115120017181000105ZK250BX333';
            Orderdet7.TracingCode__c = 'BXSYS';

            insert new List<Consumable_order_details2__c>{ Orderdet1, Orderdet2, Orderdet3, Orderdet4, Orderdet5, Orderdet6, Orderdet7 };
            PageReference page = new PageReference('/apex/ArriveGoods?ArrType=ReG');
            System.Test.setCurrentPage(page);
            ArriveGoodsController Controller = new ArriveGoodsController();
            //初始化测试
            System.Test.startTest();
            Controller.init();
            //排序
            Controller.barcode = '01049531702003111115120017181000105ZK250BXAAA\n01049531702003111115120017181000105ZK250BXJRJ\n01049531702003111115120017181000105ZK250BXJRF\n01049531702003111115120017181000105ZK250BX123\n01049531702003111115120017181000105ZK250BX222';
            Controller.SearchPro();
            //System.assertEquals(1, controller.ShowGoodsofReturnList.size());
            //System.assertEquals('OCM_01_001003', controller.ShowGoodsofReturnList[0].esd.Name);
            //System.assertEquals('OCM_01_001004', controller.ShowGoodsofReturnList[1].esd.Name);
            //System.assertEquals('Test01', controller.ConsumableorderdetailsRecordserror[0].Prod.Name__c);
            //System.assertEquals('Test01', controller.ConsumableorderdetailsRecordserror[1].Prod.Name__c);
            //System.assertEquals('OCM_01_001002', controller.ConsumableorderdetailsRecordserror[2].esd.Name);
            //System.assertEquals('OCM_02_001001', controller.ConsumableorderdetailsRecordserror[3].esd.Name);
            // Controller.GoodsReturnCheck();
            Controller.ArriveGoodsConfim();
            //System.assertEquals(1, controller.ShowGoodsofReturnList.size());
            Controller.UpdateGoodsOfReturn();

            controller.getinventorysize();
            System.Test.stopTest();
        }
    }
    @isTest
    static void barcodecheck() {
        // // TO DO: implement unit test
        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 List<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 List<Product2>{ prod01, prod02 };
            Product2__c pro1 = new Product2__c(Name = 'Pro001', OT_CODE_Text__c = '2344', Product2__c = prod01.Id);
            Product2__c pro2 = new Product2__c(Name = 'Pro002', OT_CODE_Text__c = '8232', Product2__c = prod02.Id);
            insert new List<Product2__c>{ pro1, pro2 };
            ArriveGoodsController Controller = new ArriveGoodsController();
            //初始化测试
            list<String> list1 = new List<String>();
            list1.clear();
            list1.add(Controller.barcode = '2413456250BBBBA');
            Controller.inventoryEntry(list1);

            list1.clear();
            list1.add(Controller.barcode = '241250BBBBZ');
            Controller.inventoryEntry(list1);

            list1.clear();
            list1.add(Controller.barcode = '241250');
            Controller.inventoryEntry(list1);

            list1.clear();
            list1.add(Controller.barcode = '241250BBB');
            Controller.inventoryEntry(list1);

            list1.clear();
            list1.add(Controller.barcode = '24134567250BBBBB');
            Controller.inventoryEntry(list1);

            list1.clear();
            list1.add(Controller.barcode = '241345678250BBBBC');
            Controller.inventoryEntry(list1);

            list1.clear();
            list1.add(Controller.barcode = '2413456789250BBBBD');
            Controller.inventoryEntry(list1);

            list1.clear();
            list1.add(Controller.barcode = '24134567890250BBBBE');
            Controller.inventoryEntry(list1);

            list1.clear();
            list1.add(Controller.barcode = '241345678901250BBBBF');
            Controller.inventoryEntry(list1);
            list1.clear();
            list1.add(Controller.barcode = '2413456789011250BBBBG');
            Controller.inventoryEntry(list1);

            list1.clear();
            list1.add(Controller.barcode = '24134567890111250BBBBH');
            Controller.inventoryEntry(list1);

            list1.clear();
            list1.add(Controller.barcode = '0112345678901231712300123250BBBBI');
            Controller.inventoryEntry(list1);

            list1.clear();
            list1.add(Controller.barcode = '011234567890250BBBBJ');
            Controller.inventoryEntry(list1);

            list1.clear();
            list1.add(Controller.barcode = '01123456789A0123456250BBBBK');
            Controller.inventoryEntry(list1);

            list1.clear();
            list1.add(Controller.barcode = '011234567890123411AAAA123250BBBBL');
            Controller.inventoryEntry(list1);

            list1.clear();
            list1.add(Controller.barcode = '011234567890123411789012175678901234250BBBBM');
            Controller.inventoryEntry(list1);

            list1.clear();
            list1.add(Controller.barcode = '01123456789012340138901217aaa8001234250BBBBN');
            Controller.inventoryEntry(list1);

            list1.clear();
            list1.add(Controller.barcode = '011234567890123456789012104567890250BBBBO');
            Controller.inventoryEntry(list1);

            list1.clear();
            list1.add(Controller.barcode = '01123456789012341778910034567890250BBBBP');
            Controller.inventoryEntry(list1);

            list1.clear();
            list1.add(Controller.barcode = '011234567890123417aa910034567890250BBBBQ');
            Controller.inventoryEntry(list1);

            list1.clear();
            list1.add(Controller.barcode = '01123456789012341778911134567890250BBBBR');
            Controller.inventoryEntry(list1);

            list1.clear();
            list1.add(Controller.barcode = '011234567890123417789121105678900000250BBBBS');
            Controller.inventoryEntry(list1);

            list1.clear();
            list1.add(Controller.barcode = '011234567890123410789121105678900000250BBBBT');
            Controller.inventoryEntry(list1);

            list1.clear();
            list1.add(Controller.barcode = '011234567890123411789012171a780012250BBBBU');
            Controller.inventoryEntry(list1);

            list1.clear();
            list1.add(Controller.barcode = '0112345678901234110890121012789000250BBBBV');
            Controller.inventoryEntry(list1);

            list1.clear();
            list1.add(Controller.barcode = '011234567890123417120506105678901234250BBBBW');
            Controller.inventoryEntry(list1);

            list1.clear();
            list1.add(Controller.barcode = '0112345678901234111202121712050212250BBBBX');
            Controller.inventoryEntry(list1);

            list1.clear();
            list1.add(Controller.barcode = '0112345678901234111202121712a50212250BBBBY');
            Controller.inventoryEntry(list1);

            list1.clear();
            list1.add(Controller.barcode = '0112345678901234111202121012050212250BBBBZ');
            Controller.inventoryEntry(list1);
        }
    }
    @isTest
    static void barcodechkeck_2() {
        // // TO DO: implement unit test
        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 List<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 List<Product2>{ prod01, prod02 };
            Product2__c pro1 = new Product2__c(Name = 'Pro001', OT_CODE_Text__c = '2344', Product2__c = prod01.Id);
            Product2__c pro2 = new Product2__c(Name = 'Pro002', OT_CODE_Text__c = '82324', Product2__c = prod02.Id);
            insert new List<Product2__c>{ pro1, pro2 };
            //产品注册证
            Product_Register__c prc = new Product_Register__c(
                Name = '国械注进20162220210',
                MedPrdClass__c = '3',
                ValidFrom__c = date.newinstance(2018, 7, 22),
                ValidTo__c = date.newinstance(2028, 7, 22),
                RegisterNoClass_Old__c = '6815',
                RegisterNoClass_New__c = '6815',
                RegisterNoStatus__c = '有效'
            );
            insert prc;
            //新旧关系对照表
            //Product_Register_contrast__c prcc = new Product_Register_contrast__c(
            //                                        Name = 'Test20181204',
            //                                        Register_new__c = '314',
            //                                        Register_old__c = '36815'
            //                                        );
            //insert prcc;
            //产品-产品注册证关系  prod01
            Product_Register_Link__c prlc = new Product_Register_Link__c(Product2__c = prod01.Id, Product_Register__c = prc.Id);
            insert prlc;
            //产品-产品注册证关系  prod02
            Product_Register_Link__c prlc2 = new Product_Register_Link__c(Product2__c = prod02.Id, Product_Register__c = prc.Id);
            insert prlc2;
            PageReference page = new PageReference('/apex/ArriveGoods?ArrType=ReG');
            System.Test.setCurrentPage(page);

            ArriveGoodsController Controller = new ArriveGoodsController();
            //List<Product2> proList = [select name,Estimation_Entry_Possibility__c from Product2 where id = :prod01.Id];
            //System.assertEquals('○', proList[0].Estimation_Entry_Possibility__c);
            List<Product2__c> product2InStore = [
                SELECT Id, Name, Name__c, Intra_Trade_List_RMB__c, Asset_Model_No__c, OT_CODE__c
                FROM Product2__c
                WHERE Estimation_Entry_Possibility__c = '○' AND Pro2_Dealer_Object__c = TRUE AND OT_CODE__c = 'test'
            ];
            //System.assertEquals(1, product2InStore.size());
            list<String> list1 = new List<String>();
            list1.clear();
            list1.add(Controller.barcode = '2413456250BBBBA');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '241250BBBBZ');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '241250');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '241250BBZ');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '24134567250BBBBB');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '241345678250BBBBC');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '2413452509250BBBBD');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '24125090111250BBBBE');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '241325090111250BBBBF');
            Controller.inventoryEntryNoESetId(list1);
            list1.clear();
            list1.add(Controller.barcode = '2413425090111250BBBBG');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '24134525090111250BBBBH');
            Controller.inventoryEntryNoESetId(list1);
            list1.clear();
            list1.add(Controller.barcode = '241test1712345678901234567890250BBBBI');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '241test171234500678901234567890250BBBBJ');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '241test17120400678901234567890250BBBBK');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '241test171204110678901234567890250BBBBL');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '241test171204121078901234567890250BBBBM');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '241test17120412250BBBBN');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '241test101204121078901234567890250BBBBO');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '241test1112a4121078901234567890250BBBBP');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '241test111204121778900034567890250BBBBQ');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '0111234101204120118901231712a4001234250BBBBR');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '011123410120412011890123171204011234250BBBBS');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '011test10120412011890123171a04011234250BBBBT');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '0111234101204120118901231012040112342222250BBBBU');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '011123410120412017120100250AAAAA');
            Controller.inventoryEntryNoESetId(list1);
        }
    }

    //自动出库
    @isTest
    static void addSaleOrderAuto() {
        // // TO DO: implement unit test
        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 List<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 List<Product2>{ prod01, prod02 };
            Product2__c pro1 = new Product2__c(Name = 'Pro001', OT_CODE_Text__c = 'Test001', Product2__c = prod01.Id);
            insert new List<Product2__c>{ pro1 };
            // Account myAccount1 = new Account(name='Testaccount001',Dealer_discount__c =30,RecordTypeId = rectCo[0].Id);
            // insert myAccount1;
            Consumable_order__c Order2 = new Consumable_order__c();
            Order2.Name = 'OCM_02_001';
            Order2.Order_status__c = '批准';
            Order2.Order_type__c = '订单';
            Order2.Dealer_Info__c = myAccount1.Id;
            Order2.RecordTypeid = System.Label.RT_ConOrder_Delivery;
            insert Order2;
            //发错库 已到货
            Consumable_order_details2__c Orderdets8 = new Consumable_order_details2__c();
            Orderdets8.Name = 'OCM_01_001011';
            Orderdets8.Consumable_order_minor__c = Order2.Id;
            Orderdets8.Consumable_Product__c = pro1.Id;
            Orderdets8.Asset_Model_No__c = 'Test01';
            Orderdets8.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdets8.Bar_Code__c = '01049531702003111115120017181000105ZK250BXSYS';
            Orderdets8.Box_Piece__c = '盒';
            Orderdets8.Arrive_date__c = Date.today();
            Orderdets8.TracingCode__c = 'BXSYS';
            Orderdets8.SerialLotNo__c = '5ZK';
            insert Orderdets8;

            ArriveGoodsController Controller = new ArriveGoodsController();
            PageReference page = new PageReference('/apex/ArriveGoods?ArrType=Arr');
            System.Test.setCurrentPage(page);
            //初始化测试
            System.Test.startTest();
            Controller.init();
            //排序
            Controller.barcode = '01049531702003111115120017181000105ZK250BXSYS';
            Controller.SearchPro();
            // System.assertEquals(1, controller.consumableInventory.size());
            Controller.ArriveGoodsConfim();
            System.Test.stopTest();
        }
    }

    // UPDATE TCM TEST1
    @isTest
    static void methodTest1() {
        // // TO DO: implement unit test
        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 List<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 List<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 List<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;

            //发货明细
            //fahuo
            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.Arrive_date__c = Date.today();
            // Orderdet1.Send_Date__c=Date.today();
            // Orderdet1.Used_date__c=Date.today();
            Orderdet1.TracingCode__c = 'BXJRF';
            Orderdet1.SerialLotNo__c = '5ZK';
            insert Orderdet1;

            //fahuo
            Consumable_order_details2__c Orderdet2 = new Consumable_order_details2__c();
            Orderdet2.Name = 'OCM_01_001001';
            Orderdet2.Consumable_order_minor__c = Order1.Id;
            Orderdet2.Consumable_Product__c = pro1.Id;
            Orderdet2.Asset_Model_No__c = 'Test01';
            Orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet2.Bar_Code__c = '01049531702003111115120017181234105ZK250BXJRF';
            Orderdet2.Arrive_date__c = Date.today();
            Orderdet2.TracingCode__c = 'BXJRF';
            Orderdet2.SerialLotNo__c = '5ZK';
            insert Orderdet2;

            PageReference page = new PageReference('/apex/ArriveGoods?ESetid=' + Order1.Id);
            System.Test.setCurrentPage(page);
            ArriveGoodsController Controller = new ArriveGoodsController();
            //初始化测试
            System.Test.startTest();
            Controller.init();
            Controller.barcode = '01049531702003111115120017181000105ZK250BXJRF';
            Controller.SearchPro();
            // System.assertEquals(1, Controller.ConsumableorderdetailsRecords.size());
            // System.assertEquals(2, Controller.consumableInventory.size());
            Controller.ArriveGoodsConfim();
            List<Consumable_order_details2__c> ins = [
                SELECT Id, Name
                FROM Consumable_order_details2__c
            ];
            // System.assertEquals(3, ins.size());
            System.Test.stopTest();
        }
    }

    //返品
    @isTest
    static void methodTest2() {
        // // TO DO: implement unit test
        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 List<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 List<Product2>{ prod01, prod02 };
            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);
            insert new List<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;
            //Consumable_order__c coc = [select Dealer_Info__r.name from Consumable_order__c where Id =:Order1.Id];
            //system.assertEquals('qeee',coc.Dealer_Info__r.name);

            //订单明细
            //fahuo
            Consumable_orderdetails__c Orderdet = new Consumable_orderdetails__c();
            Orderdet.Name = 'OCM_01_001001';
            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;

            //发货明细
            //fahuo
            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 = 'Pro001';
            Orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet1.Box_Piece__c = '盒';
            Orderdet1.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRF';
            //daohuo
            Consumable_order_details2__c Orderdet2 = new Consumable_order_details2__c();
            Orderdet2.Name = 'OCM_01_001002';
            Orderdet2.Consumable_order_minor__c = Order1.Id;
            Orderdet2.Consumable_Product__c = pro1.Id;
            Orderdet2.Asset_Model_No__c = 'Pro001';
            Orderdet2.Consumable_Arrived_order__c = Order1.Id;
            //Orderdet2.IsArrival__c = true;
            Orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet2.Box_Piece__c = '盒';
            Orderdet2.Arrive_date__c = Date.today();
            //Orderdet2.Send_Date__c = Date.today();
            //Orderdet2.Used_date__c= Date.today();
            Orderdet2.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRF';
            //sale
            Consumable_order_details2__c Orderdet3 = new Consumable_order_details2__c();
            Orderdet3.Name = 'OCM_01_001003';
            Orderdet3.Consumable_order_minor__c = Order1.Id;
            Orderdet3.Consumable_Product__c = pro1.Id;
            Orderdet3.Asset_Model_No__c = 'Pro001';
            Orderdet3.Consumable_Arrived_order__c = Order1.Id;
            //Orderdet3.IsArrival__c = true;
            Orderdet3.Consumable_Sale_order__c = Order1.Id;
            Orderdet3.Box_Piece__c = '盒';
            Orderdet3.Used_date__c = Date.today();
            Orderdet3.Arrive_date__c = Date.today();
            Orderdet3.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet3.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRF';
            Orderdet3.TracingCode__c = 'BXJRF';
            Orderdet3.SerialLotNo__c = '5ZK';
            //出库
            Consumable_order_details2__c Orderdet4 = new Consumable_order_details2__c();
            Orderdet4.Name = 'OCM_01_001004';
            Orderdet4.Consumable_order_minor__c = Order1.Id;
            Orderdet4.Consumable_Product__c = pro1.Id;
            Orderdet4.Asset_Model_No__c = 'Pro001';
            Orderdet4.Consumable_Arrived_order__c = Order1.Id;
            //Orderdet4.IsArrival__c = true;
            Orderdet4.Consumable_Shipment_order__c = Order1.Id;
            Orderdet4.Box_Piece__c = '个';
            Orderdet4.Send_Date__c = Date.today();
            Orderdet4.Arrive_date__c = Date.today();
            Orderdet4.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet4.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRN';
            Orderdet4.TracingCode__c = 'BXJRN';
            Orderdet4.SerialLotNo__c = '5ZK';
            //quxiao
            Consumable_order_details2__c Orderdet5 = new Consumable_order_details2__c();
            Orderdet5.Name = 'OCM_01_001005';
            Orderdet5.Consumable_order_minor__c = Order1.Id;
            Orderdet5.Consumable_Product__c = pro1.Id;
            Orderdet5.Asset_Model_No__c = 'Pro001';
            Orderdet5.Cancellation_Date__c = Date.today();
            Orderdet5.Cancellation_Flag__c = true;
            Orderdet5.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet5.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRZ';
            Orderdet5.Box_Piece__c = '个';
            Orderdet5.TracingCode__c = 'BXJRZ';
            Orderdet5.SerialLotNo__c = '5ZK';
            insert new List<Consumable_order_details2__c>{ Orderdet1, Orderdet3, Orderdet4, Orderdet5 };

            PageReference page = new PageReference('/apex/ArriveGoods?ArrType=ReG');
            System.Test.setCurrentPage(page);
            ArriveGoodsController Controller = new ArriveGoodsController();
            //初始化测试
            System.Test.startTest();
            Controller.init();
            //排序
            Controller.barcode = '01049531702003111115120017181000105ZK250BXJRF\n01049531702003111115120017181000105ZK250BXJRN\n01049531702003111115120017181000105ZK250BXJRZ\n01049531702003111115120017181000105ZK250BXJRR';
            Controller.SearchPro();
            System.assertEquals(1, controller.ConsumableorderdetailsRecordserror.size());
            // System.assertEquals(2, controller.ShowGoodsofReturnList.size());
            controller.ShowGoodsofReturnList[0].esd.Return_reason__c = '多发';
            // controller.ShowGoodsofReturnList[1].esd.Return_reason__c='多发';
            // controller.ShowGoodsofReturnList[0].esd.Rrturn_count__c =1;
            Controller.UpdateGoodsOfReturn();

            list<String> list1 = new List<String>();
            list1.add(Controller.barcode = '01234567898');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '012345678901234A67');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '0123456789012345117AA01');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '01234567890123456789012349990001');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '0123456789012345177AA0000000000001');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '0123456789012345177AA1111111111111');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '241345');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '2413456');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '24134567');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '241345678');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '2413456789');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '24134567890');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '241345678901');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '0112345678901231177890121215678901234');
            Controller.inventoryEntryNoESetId(list1);

            list1.clear();
            list1.add(Controller.barcode = '0112345678901231106789012105678901234');
            Controller.inventoryEntryNoESetId(list1);
            list1.clear();
            list1.add(Controller.barcode = '0112345678901231106789012105625001234');
            Controller.inventoryEntryNoESetId(list1);
            System.Test.stopTest();
        }
    }

    //整体到货
    @isTest
    static void ArrivejancodeTest() {
        // // TO DO: implement unit test
        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)'
        ];

        Oly_TriggerHandler.bypass('ConsumableAssetHander');
        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 List<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 List<Product2>{ prod01, prod02 };
            Product2__c pro1 = new Product2__c(Name = 'Pro001', OT_CODE_Text__c = 'Test001', Product2__c = prod01.Id);
            insert new List<Product2__c>{ pro1 };
            // Account myAccount1 = new Account(name='Testaccount001',Dealer_discount__c =30,RecordTypeId = rectCo[0].Id);
            // insert myAccount1;
            Consumable_order__c Order2 = new Consumable_order__c();
            Order2.Name = 'OCM_02_001';
            Order2.Order_status__c = '批准';
            Order2.Order_type__c = '订单';
            Order2.Dealer_Info__c = myAccount1.Id;
            Order2.RecordTypeid = System.Label.RT_ConOrder_Delivery;
            insert Order2;
            //发错库 未到货
            Consumable_order_details2__c Orderdets8 = new Consumable_order_details2__c();
            Orderdets8.Name = 'OCM_01_001011';
            Orderdets8.Consumable_order_minor__c = Order2.Id;
            Orderdets8.Consumable_Product__c = pro1.Id;
            Orderdets8.Asset_Model_No__c = 'Test01';
            Orderdets8.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdets8.Bar_Code__c = '01049531702003111115120017181000105ZK250BXsys';
            Orderdets8.Box_Piece__c = '盒';
            Orderdets8.TracingCode__c = 'BXsys';
            Orderdets8.SerialLotNo__c = '5ZK';
            insert Orderdets8;

            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.Order_ProType__c = 'ET';
            Order1.RecordTypeid = System.Label.RT_ConOrder_Delivery;
            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_001002';
            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 = '01049531702003111115120017181000105ZK250BXJRA';
            Orderdet1.Box_Piece__c = '盒';
            Orderdet1.TracingCode__c = 'BXJRA';
            Orderdet1.SerialLotNo__c = '5ZK';
            //没到货
            Consumable_order_details2__c Orderdet2 = new Consumable_order_details2__c();
            Orderdet2.Name = 'OCM_01_001003';
            Orderdet2.Consumable_order_minor__c = Order1.Id;
            Orderdet2.Consumable_Product__c = pro1.Id;
            Orderdet2.Asset_Model_No__c = 'Test01';
            Orderdet2.Consumable_Arrived_order__c = Order1.Id;
            Orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet2.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRB';
            Orderdet2.Box_Piece__c = '盒';
            Orderdet2.TracingCode__c = 'BXJRB';
            Orderdet2.SerialLotNo__c = '5ZK';
            //销售产品
            Consumable_order_details2__c Orderdet3 = new Consumable_order_details2__c();
            Orderdet3.Name = 'OCM_01_001004';
            Orderdet3.Consumable_order_minor__c = Order1.Id;
            Orderdet3.Consumable_Product__c = pro1.Id;
            Orderdet3.Asset_Model_No__c = 'Test01';
            Orderdet3.Consumable_Arrived_order__c = Order1.Id;
            //Orderdet3.IsArrival__c = true;
            Orderdet3.Consumable_Sale_order__c = Order1.Id;
            Orderdet3.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet3.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRC';
            Orderdet3.Used_date__c = Date.today();
            Orderdet3.Arrive_date__c = Date.today();
            Orderdet3.Box_Piece__c = '盒';
            Orderdet3.TracingCode__c = 'BXJRC';
            Orderdet3.SerialLotNo__c = '5ZK';
            //Orderdet3.Box_Piece__c = '个';

            //出库产品
            Consumable_order_details2__c Orderdet4 = new Consumable_order_details2__c();
            Orderdet4.Name = 'OCM_01_001005';
            Orderdet4.Consumable_order_minor__c = Order1.Id;
            Orderdet4.Consumable_Product__c = pro1.Id;
            Orderdet4.Asset_Model_No__c = 'Test01';
            Orderdet4.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet4.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRD';
            Orderdet4.Send_Date__c = Date.today();
            Orderdet4.Arrive_date__c = Date.today();
            Orderdet4.Box_Piece__c = '盒';
            Orderdet4.TracingCode__c = 'BXJRD';
            Orderdet4.SerialLotNo__c = '5ZK';
            //Orderdet4.Box_Piece__c = '盒';
            //Orderdet4.Return_date__c = null;

            //已到货产品
            Consumable_order_details2__c Orderdet5 = new Consumable_order_details2__c();
            Orderdet5.Name = 'OCM_01_001006';
            Orderdet5.Consumable_order_minor__c = Order1.Id;
            Orderdet5.Consumable_Product__c = pro1.Id;
            Orderdet5.Asset_Model_No__c = 'Test01';
            Orderdet5.Consumable_Arrived_order__c = Order1.Id;
            Orderdet5.Consumable_Shipment_order__c = Order1.Id;
            Orderdet5.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet5.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRE';
            Orderdet5.Arrive_date__c = Date.today();
            Orderdet5.Box_Piece__c = '盒';
            Orderdet5.TracingCode__c = 'BXJRE';
            Orderdet5.SerialLotNo__c = '5ZK';
            insert new List<Consumable_order_details2__c>{ Orderdet1, Orderdet2, Orderdet3, Orderdet4, Orderdet5 };

            ArriveGoodsController Controller = new ArriveGoodsController();
            PageReference page = new PageReference('/apex/ArriveGoods?ArrType=Arr');
            System.Test.setCurrentPage(page);
            //初始化测试
            System.Test.startTest();
            Controller.init();
            //排序
            Controller.barcode = '01049531702003111115120017181000105ZK250BXJRA\n01049531702003111115120017181000105ZK250BXJRB\n01049531702003111115120017181000105ZK250BXJRC\n01049531702003111115120017181000105ZK250BXJRD\n01049531702003111115120017181000105ZK250BXJRE\n01049531702003111115120017181000105ZK250BX111\n01049531702003111115120017181000105ZK250BXJRF\n01049531702003111115120017181000105ZK250BXJRG\n01049531702003111115120017181000105ZK250BXsys';
            Controller.SearchPro();

            System.assertEquals('OCM_01_001002', controller.ConsumableorderdetailsRecords[0].esd.Name);
            // System.assertEquals(2, controller.ConsumableorderdetailsRecordserror.size());
            System.Test.stopTest();
        }
    }

    //发错货 入库
    @isTest
    static void ArriveotheragencyTest() {
        // // TO DO: implement unit test
        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)'
        ];

        Oly_TriggerHandler.bypass('ConsumableAssetHander');
        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 List<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 List<Product2>{ prod01, prod02 };
            Product2__c pro1 = new Product2__c(Name = 'Pro001', OT_CODE_Text__c = 'Test001', Product2__c = prod01.Id);
            insert new List<Product2__c>{ pro1 };
            Account myAccount3 = new Account(name = 'Testaccount003', Dealer_discount__c = 30, RecordTypeId = rectCo[0].Id);
            insert myAccount3;
            Consumable_order__c Order2 = new Consumable_order__c();
            Order2.Name = 'OCM_02_001';
            Order2.Order_status__c = '批准';
            Order2.Order_type__c = '订单';
            Order2.Dealer_Info__c = myAccount3.Id;
            Order2.RecordTypeid = System.Label.RT_ConOrder_Delivery;
            Order2.Order_ProType__c = 'ET';
            insert Order2;
            //发错库 未到货
            Consumable_order_details2__c Orderdets8 = new Consumable_order_details2__c();
            Orderdets8.Name = 'OCM_01_001011';
            Orderdets8.Consumable_order_minor__c = Order2.Id;
            Orderdets8.Consumable_Product__c = pro1.Id;
            Orderdets8.Asset_Model_No__c = 'Test01';
            Orderdets8.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdets8.Bar_Code__c = '01049531702003111115120017181000105ZK250BXSYS';
            Orderdets8.Box_Piece__c = '盒';
            Orderdets8.TracingCode__c = 'BXSYS';
            Orderdets8.SerialLotNo__c = '5ZK';
            Orderdets8.ownerid = MyUser_Test.id;
            insert Orderdets8;

            //发错库 已到货
            Consumable_order_details2__c Orderdets9 = new Consumable_order_details2__c();
            Orderdets9.Name = 'OCM_01_001012';
            Orderdets9.Consumable_order_minor__c = Order2.Id;
            Orderdets9.Consumable_Product__c = pro1.Id;
            Orderdets9.Asset_Model_No__c = 'Test01';
            Orderdets9.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdets9.Bar_Code__c = '01049531702003111115120017181000105ZK250BXSYQ';
            Orderdets9.Consumable_Arrived_order__c = Order2.Id;
            Orderdets9.Arrive_date__c = Date.today();
            Orderdets9.Box_Piece__c = '盒';
            Orderdets9.TracingCode__c = 'BXSYQ';
            Orderdets9.SerialLotNo__c = '5ZK';
            insert Orderdets9;

            // 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.Order_ProType__c = 'ET';
            // Order1.RecordTypeid = System.Label.RT_ConOrder_Delivery;
            // 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_001002';
            // 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 = '01049531702003111115120017181000105ZK250BXJRA';
            // Orderdet1.Box_Piece__c = '盒';
            // Orderdet1.TracingCode__c = 'BXJRA';
            // Orderdet1.SerialLotNo__c = '5ZK';
            // //没到货
            // Consumable_order_details2__c Orderdet2 = new Consumable_order_details2__c();
            // Orderdet2.Name = 'OCM_01_001003';
            // Orderdet2.Consumable_order_minor__c = Order1.Id;
            // Orderdet2.Consumable_Product__c = pro1.Id;
            // Orderdet2.Asset_Model_No__c = 'Test01';
            // Orderdet2.Consumable_Arrived_order__c = Order1.Id;
            // Orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            // Orderdet2.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRB';
            // Orderdet2.Box_Piece__c = '盒';
            // Orderdet2.TracingCode__c = 'BXJRB';
            // Orderdet2.SerialLotNo__c = '5ZK';
            // //销售产品
            // Consumable_order_details2__c Orderdet3 = new Consumable_order_details2__c();
            // Orderdet3.Name = 'OCM_01_001004';
            // Orderdet3.Consumable_order_minor__c = Order1.Id;
            // Orderdet3.Consumable_Product__c = pro1.Id;
            // Orderdet3.Asset_Model_No__c = 'Test01';
            // Orderdet3.Consumable_Arrived_order__c = Order1.Id;
            // //Orderdet3.IsArrival__c = true;
            // Orderdet3.Consumable_Sale_order__c = Order1.Id;
            // Orderdet3.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            // Orderdet3.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRC';
            // Orderdet3.Used_date__c = Date.today();
            // Orderdet3.Arrive_date__c = Date.today();
            // Orderdet3.Box_Piece__c = '盒';
            // Orderdet3.TracingCode__c = 'BXJRC';
            // Orderdet3.SerialLotNo__c = '5ZK';
            // //Orderdet3.Box_Piece__c = '个';

            // //出库产品
            // Consumable_order_details2__c Orderdet4 = new Consumable_order_details2__c();
            // Orderdet4.Name = 'OCM_01_001005';
            // Orderdet4.Consumable_order_minor__c = Order1.Id;
            // Orderdet4.Consumable_Product__c = pro1.Id;
            // Orderdet4.Asset_Model_No__c = 'Test01';
            // Orderdet4.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            // Orderdet4.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRD';
            // Orderdet4.Send_Date__c =  Date.today();
            // Orderdet4.Arrive_date__c = Date.today();
            // Orderdet4.Box_Piece__c = '盒';
            // Orderdet4.TracingCode__c = 'BXJRD';
            // Orderdet4.SerialLotNo__c = '5ZK';
            // //Orderdet4.Box_Piece__c = '盒';
            // //Orderdet4.Return_date__c = null;

            // //已到货产品
            // Consumable_order_details2__c Orderdet5 = new Consumable_order_details2__c();
            // Orderdet5.Name = 'OCM_01_001006';
            // Orderdet5.Consumable_order_minor__c = Order1.Id;
            // Orderdet5.Consumable_Product__c = pro1.Id;
            // Orderdet5.Asset_Model_No__c = 'Test01';
            // Orderdet5.Consumable_Arrived_order__c = Order1.Id;
            // Orderdet5.Consumable_Shipment_order__c = Order1.Id;
            // Orderdet5.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            // Orderdet5.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRE';
            // Orderdet5.Arrive_date__c =  Date.today();
            // Orderdet5.Box_Piece__c = '盒';
            // Orderdet5.TracingCode__c = 'BXJRE';
            // Orderdet5.SerialLotNo__c = '5ZK';
            // insert new Consumable_order_details2__c[] {Orderdet1, Orderdet2,Orderdet3,Orderdet4,Orderdet5};

            ArriveGoodsController Controller = new ArriveGoodsController();
            PageReference page = new PageReference('/apex/ArriveGoods?ArrType=Arr');
            System.Test.setCurrentPage(page);
            //初始化测试
            System.Test.startTest();
            Controller.init();
            //排序
            Controller.barcode = '01049531702003111115120017181000105ZK250BXSYS\n01049531702003111115120017181000105ZK250BXSYQ';
            Controller.SearchPro();
            Controller.ArriveGoodsConfim();

            // System.assertEquals(2, controller.ConsumableorderdetailsRecordserror.size());
            System.Test.stopTest();
        }
    }

    //返品
    @isTest
    static void addInventoryDetails1() {
        // // TO DO: implement unit test
        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 List<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 List<Product2>{ prod01, prod02 };
            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);
            insert new List<Product2__c>{ pro1, pro2 };
            //订单
            Oly_TriggerHandler.bypass('ConsumableAssetHander');
            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';
            //返品订单

            Consumable_order__c Order2 = new Consumable_order__c();
            Order2.Name = 'OCM_01_002';
            Order2.Order_status__c = '批准';
            Order2.Order_type__c = '返品';
            Order2.Dealer_Info__c = myAccount1.id;
            Order2.RecordTypeid = System.Label.Dealer_Returned_Label;
            insert Order1;
            insert Order2;

            //订单明细
            //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;

            //发货明细
            //fahuo
            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 = 'Pro001';
            Orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet1.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRF';
            Orderdet1.TracingCode__c = 'BXJRF';
            //daohuo
            Consumable_order_details2__c Orderdet2 = new Consumable_order_details2__c();
            Orderdet2.Name = 'OCM_01_001002';
            Orderdet2.Consumable_order_minor__c = Order1.Id;
            Orderdet2.Consumable_Product__c = pro1.Id;
            Orderdet2.Asset_Model_No__c = 'Pro001';
            Orderdet2.Consumable_Arrived_order__c = Order1.Id;
            //Orderdet2.IsArrival__c = true;
            Orderdet2.Arrive_date__c = Date.today();
            Orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet2.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRI';
            Orderdet2.TracingCode__c = 'BXJRF';
            //sale
            Consumable_order_details2__c Orderdet3 = new Consumable_order_details2__c();
            Orderdet3.Name = 'OCM_01_001003';
            Orderdet3.Consumable_order_minor__c = Order1.Id;
            Orderdet3.Consumable_Product__c = pro1.Id;
            Orderdet3.Asset_Model_No__c = 'Pro001';
            Orderdet3.Consumable_Arrived_order__c = Order1.Id;
            //Orderdet3.IsArrival__c = true;
            Orderdet3.Arrive_date__c = Date.today();
            Orderdet3.Used_date__c = Date.today();
            Orderdet3.Consumable_Sale_order__c = Order1.Id;
            Orderdet3.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet3.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRJ';
            Orderdet3.Box_Piece__c = '盒';
            Orderdet3.TracingCode__c = 'BXJRF';
            //出库
            Consumable_order_details2__c Orderdet4 = new Consumable_order_details2__c();
            Orderdet4.Name = 'OCM_01_001004';
            Orderdet4.Consumable_order_minor__c = Order1.Id;
            Orderdet4.Consumable_Product__c = pro1.Id;
            Orderdet4.Asset_Model_No__c = 'Pro001';
            Orderdet4.Consumable_Arrived_order__c = Order1.Id;
            //Orderdet4.IsArrival__c = true;
            Orderdet4.Arrive_date__c = Date.today();
            Orderdet4.Send_Date__c = Date.today();
            Orderdet4.Consumable_Shipment_order__c = Order1.Id;
            Orderdet4.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet4.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRN';
            Orderdet4.Box_Piece__c = '个';
            Orderdet4.TracingCode__c = 'BXJRF';
            //quxiao
            Consumable_order_details2__c Orderdet5 = new Consumable_order_details2__c();
            Orderdet5.Name = 'OCM_01_001005';
            Orderdet5.Consumable_order_minor__c = Order1.Id;
            Orderdet5.Consumable_Product__c = pro1.Id;
            Orderdet5.Asset_Model_No__c = 'Pro001';
            Orderdet5.Cancellation_Date__c = Date.today();
            Orderdet5.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet5.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRZ';
            Orderdet5.Box_Piece__c = '盒';
            Orderdet5.TracingCode__c = 'BXJRF';
            //fanpin
            Consumable_order_details2__c Orderdet6 = new Consumable_order_details2__c();
            Orderdet6.Name = 'OCM_01_001006';
            Orderdet6.Consumable_order_minor__c = Order1.Id;
            Orderdet6.Consumable_Product__c = pro1.Id;
            Orderdet6.Asset_Model_No__c = 'Pro001';
            Orderdet6.Consumable_Return_order__c = Order2.Id;
            Orderdet6.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet6.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRA';
            Orderdet6.Box_Piece__c = '个';
            Orderdet6.TracingCode__c = 'BXJRF';

            // 丢失
            Consumable_order_details2__c Orderdet7 = new Consumable_order_details2__c();
            Orderdet7.Name = 'OCM_01_001002';
            Orderdet7.Consumable_order_minor__c = Order1.Id;
            Orderdet7.Consumable_Product__c = pro1.Id;
            Orderdet7.Asset_Model_No__c = 'Pro001';
            Orderdet7.Consumable_Arrived_order__c = Order1.Id;
            Orderdet7.Lose_Flag__c = true;
            Orderdet7.Arrive_date__c = Date.today();
            Orderdet7.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet7.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJQT';
            Orderdet7.Box_Piece__c = '个';
            Orderdet7.TracingCode__c = 'BXJQT';

            insert new List<Consumable_order_details2__c>{ Orderdet1, Orderdet2, Orderdet3, Orderdet4, Orderdet5, Orderdet6, Orderdet7 };
            PageReference page = new PageReference('/apex/ArriveGoods?ArrType=ReG');
            System.Test.setCurrentPage(page);
            ArriveGoodsController Controller = new ArriveGoodsController();
            //初始化测试
            System.Test.startTest();
            Controller.init();
            //排序
            Controller.barcode = '01049531702003111115120017181000105ZK250BXJRN\n01049531702003111115120017181000105ZK250BXJRF\n01049531702003111115120017181000105ZK250BXJRI\n01049531702003111115120017181000105ZK250BXJRN\n01049531702003111115120017181000105ZK250BXJRZ\n01049531702003111115120017181000105ZK250BXJRA\n01049531702003111115120017181000105ZK250BXJRI\n01049531702003111115120017181000105ZK250BXJQT';
            Controller.SearchPro();
            //System.assertEquals(1, controller.ShowGoodsofReturnList.size());
            //System.assertEquals('OCM_01_001003', controller.ShowGoodsofReturnList[0].esd.Name);
            //System.assertEquals('OCM_01_001004', controller.ShowGoodsofReturnList[1].esd.Name);
            // System.assertEquals(5, controller.ConsumableorderdetailsRecordserror.size());    //tcm
            //System.assertEquals('Test01', controller.ConsumableorderdetailsRecordserror[1].Prod.Name__c);
            //System.assertEquals('OCM_01_001002', controller.ConsumableorderdetailsRecordserror[2].esd.Name);
            //System.assertEquals('OCM_02_001001', controller.ConsumableorderdetailsRecordserror[3].esd.Name);
            // Controller.GoodsReturnCheck();
            controller.ShowGoodsofReturnList[0].esd.Return_reason__c = '多发';
            controller.ShowGoodsofReturnList[0].esd.Rrturn_count__c = 1;
            //System.assertEquals(1, controller.ShowGoodsofReturnList.size());
            Controller.UpdateGoodsOfReturn();
            Controller.ToReturnGoodsPage();
            Controller.geterrorsize();
            System.Test.stopTest();
        }
    }

    @isTest
    static void makeRecordsVieweTest() {
        Integer count = 1001;
        List<ArriveGoodsController.ConsumableorderdetailsInfo> conList = new List<ArriveGoodsController.ConsumableorderdetailsInfo>();
        for (Integer i = 0; i < 1001; i++) {
            conList.add(new ArriveGoodsController.ConsumableorderdetailsInfo());
        }
        ArriveGoodsController arr = new ArriveGoodsController();
        arr.makeRecordsView(conList);
        ArriveGoodsController arr1 = new ArriveGoodsController('', '');
    }

    @isTest
    static void compareToTest() {
        ArriveGoodsController.ConsumableorderdetailsInfo c1 = new ArriveGoodsController.ConsumableorderdetailsInfo();
        ArriveGoodsController.ConsumableorderdetailsInfo c2 = new ArriveGoodsController.ConsumableorderdetailsInfo();
        c1.compareTo(c2);
    }

    @isTest
    static void searchProTest1() {
        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)'
        ];
        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 List<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;
        }

        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 List<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 List<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;
            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.Cancellation_Date__c = null;
            Orderdet1.TracingCode__c = 'BXJRF';
            Orderdet1.SerialLotNo__c = '5ZK';
            insert Orderdet1;
            System.debug('Orderdet1:' + Orderdet1);
            Consumable_order_details2__c Orderdet2 = new Consumable_order_details2__c();
            Orderdet2.Name = 'OCM_01_001001';
            Orderdet2.Consumable_order_minor__c = Order1.Id;
            Orderdet2.Consumable_Product__c = pro1.Id;
            Orderdet2.Asset_Model_No__c = 'Test01';
            Orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet2.Bar_Code__c = '01049531702003111115120017181234105ZK250BXJRF';
            Orderdet1.Cancellation_Date__c = null;
            Orderdet2.TracingCode__c = 'BXJRF';
            Orderdet2.SerialLotNo__c = '5ZK';
            insert Orderdet2;

            PageReference page = new PageReference('/apex/ArriveGoods?ArrType=Arr');
            System.Test.setCurrentPage(page);
            ArriveGoodsController Controller = new ArriveGoodsController();
            System.Test.startTest();
            Controller.init();
            Controller.barcode = '01049531702003111115120017181000105ZK250BXJRF';
            Controller.SearchPro();
            Controller.ArriveGoodsConfim();
            List<Consumable_order_details2__c> ins = [
                SELECT Id, Name
                FROM Consumable_order_details2__c
            ];
            System.Test.stopTest();
        }
    }
}
