高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
@isTest
public class PrintConsumblePDFControllertTest {
    static testMethod void PrintConsumblePDFControllertTest(){
        Profile prof1 = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证(ET)'];
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        
 
        
        Account myAccount2 = new Account(name='Testaccount002',Dealer_discount__c =20,RecordTypeId = rectCo[0].Id);
        insert myAccount2;
        Contact core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=myAccount2.id);
        insert core;
        user MyUser_Test = New User(ContactId = core.id,Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof1.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com');
        insert MyUser_Test;
        system.runAs(MyUser_Test){
            Product2 prod01 = new Product2(Name='Test01:123',ProductCode='Test01',Asset_Model_No__c = 'Test01',SFDA_Status__c = '有効',Dealer_special_Object__c = true,ProduceCompany__c='生产企业名称:卡麦德医疗器械有限公司 KeyMed (Medical & Industrial Equipment)  Ltd;住所:KeyMed House Stock Road Southend-on-sea Essex SS2 5QH United Kingdom;联系方式:(01702)616333');
            Product2 prod02 = new Product2(Name='Test02:123',ProductCode='Test02',Asset_Model_No__c = 'Test02',SFDA_Status__c = '有効',Dealer_special_Object__c = true,ProduceCompany__c='生产企业名称:卡麦德医疗器械有限公司 KeyMed (Medical & Industrial Equipment)  Ltd;住所:KeyMed House Stock Road Southend-on-sea Essex SS2 5QH United Kingdom;联系方式:(01702)616333');
            Product2 prod03 = new Product2(Name='Test03123',ProductCode='Test03',Asset_Model_No__c = 'Test03',SFDA_Status__c = '有効',Dealer_special_Object__c = true,ProduceCompany__c='生产企业名称:卡麦德医疗器械有限公司 KeyMed (Medical & Industrial Equipment)  Ltd;住所:KeyMed House Stock Road Southend-on-sea Essex SS2 5QH United Kingdom;联系方式:(01702)616333');
            Product2 prod04 = new Product2(Name='Test04:123',ProductCode='Test04',Asset_Model_No__c = 'Test04',SFDA_Status__c = '有効',Dealer_special_Object__c = true,ProduceCompany__c='生产企业名称:卡麦德医疗器械有限公司 KeyMed (Medical & Industrial Equipment)  Ltd;住所:KeyMed House Stock Road Southend-on-sea Essex SS2 5QH United Kingdom;联系方式:(01702)616333');
            Product2 prod05 = new Product2(Name='Test05123',ProductCode='Test05',Asset_Model_No__c = 'Test05',SFDA_Status__c = '有効',Dealer_special_Object__c = true,ProduceCompany__c='生产企业名称:卡麦德医疗器械有限公司 KeyMed (Medical & Industrial Equipment)  Ltd;住所:KeyMed House Stock Road Southend-on-sea Essex SS2 5QH United Kingdom;联系方式:(01702)616333');
            Product2 prod06 = new Product2(Name='Test06:123',ProductCode='Test06',Asset_Model_No__c = 'Test06',SFDA_Status__c = '有効',Dealer_special_Object__c = true,ProduceCompany__c='生产企业名称:卡麦德医疗器械有限公司 KeyMed (Medical & Industrial Equipment)  Ltd;住所:KeyMed House Stock Road Southend-on-sea Essex SS2 5QH United Kingdom;联系方式:(01702)616333');
            insert new Product2[] {prod01,prod02,prod03,prod04,prod05,prod06};
 
            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);
            Product2__c pro3 = new Product2__c(Name='Pro003',OT_CODE_Text__c='Test003',Product2__c = prod03.Id);
            Product2__c pro4 = new Product2__c(Name='Pro004',OT_CODE_Text__c='Test004',Product2__c = prod04.Id);
            Product2__c pro5 = new Product2__c(Name='Pro005',OT_CODE_Text__c='Test005',Product2__c = prod05.Id);
            Product2__c pro6 = new Product2__c(Name='Pro006',OT_CODE_Text__c='Test006',Product2__c = prod06.Id);
            insert new Product2__c[] {pro4, pro5,pro6,pro1, pro2, pro3};
            
            Consumable_order__c createId = new Consumable_order__c();
            createId.Name = 'testMing';
            createId.Order_status__c = '草案中';
            createId.Order_date__c = Date.today();
            createId.Dealer_Info__c = myAccount2.Id;
            createId.Order_Reason__c = '其他';
            createId.RecordTypeid = System.Label.RT_ConOrder_Order;
            insert  createId;
            Consumable_orderdetails__c good = new Consumable_orderdetails__c();
            good.recordtypeid= System.Label.RT_ConOrderDetail1_Order;
            good.Name = 'OCM0001';
            //good.Consumable_principal__c = createId.id;
            good.Consumable_order__c = createId.id;
            //good.Sum_of_money__c = 123;
            good.Consumable_count__c = 1;
            good.Consumable_Product__c = pro1.id;
            good.Product_code__c ='';
            good.Remarks__c ='';
            insert good;
            good = new Consumable_orderdetails__c();
            good.recordtypeid= System.Label.RT_ConOrderDetail1_Order;
            good.Name = 'OCM0003';
            //good.Consumable_principal__c = createId.id;
            good.Consumable_order__c = createId.id;
            //good.Sum_of_money__c = 123;
            good.Consumable_count__c = 1;
            good.Consumable_Product__c = pro3.id;
            
            insert good;
            good = new Consumable_orderdetails__c();
            good.recordtypeid= System.Label.RT_ConOrderDetail1_Order;
            good.Name = 'OCM0002';
            //good.Consumable_principal__c = createId.id;
            good.Consumable_order__c = createId.id;
            //good.Sum_of_money__c = 123;
            good.Consumable_count__c = 1;
            good.Consumable_Product__c = pro2.id;
            good.Product_code__c ='Test001';
            good.Remarks__c ='';
            insert good;
            good = new Consumable_orderdetails__c();
            good.recordtypeid= System.Label.RT_ConOrderDetail1_Order;
            good.Name = 'OCM0004';
            //good.Consumable_principal__c = createId.id;
            good.Consumable_order__c = createId.id;
            //good.Sum_of_money__c = 123;
            good.Consumable_count__c = 1;
            good.Consumable_Product__c = pro4.id;
            insert good;
            PageReference page = new PageReference('/apex/PrintConsumblePDF?ESetid='+createId.id);
            page.setRedirect(true);
            System.Test.setCurrentPage(page);
            PrintConsumblePDFController PPDF  = new PrintConsumblePDFController();
 
            PPDF.init();
            System.assertEquals(1, PPDF.printRecords.size());
        }
    }
}