liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
@isTest
private class Consumable_order_AlertControllerTest {
    
    @isTest static void test_method_one() {
        List<RecordType> conOrder_Order = [select Id from RecordType where IsActive = true and SobjectType = 'Consumable_order__c' and Name = '01 订单'];
        if (conOrder_Order.size() == 0) {
            return;
        }
 
        List<RecordType> conOrderDetail_Order = [select Id from RecordType where IsActive = true and SobjectType = 'Consumable_orderdetails__c' and Name = '订单'];
        if (conOrderDetail_Order.size() == 0) {
            return;
        }
 
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
 
        List<RecordType> rectContract = [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重验证'];
        Id pricebookId = ControllerUtil.getStandardPricebook().Id;
        // 产品
        Product2 prd1 = new Product2(
            Name='name01',
            IsActive=true,
            Asset_Model_No__c='n01',
            ProductCode_Ext__c='pc01',
            Manual_Entry__c=false,
            SFDA_Status__c='有効',
            Intra_Trade_List_RMB_Date1__c=Date.today().addDays(-1),
            Intra_Trade_List_RMB_Date2__c=Date.today().addDays(-1),
            Intra_Trade_List_RMB_End_Date1__c=Date.today().addDays(1),
            Intra_Trade_List_RMB_End_Date2__c=Date.today().addDays(1),
            Intra_Trade_List_RMB_1__c=100,
            Intra_Trade_List_RMB_2__c=200,
            Intra_Trade_Cost_RMB_Date1__c=Date.today().addDays(-1),
            Intra_Trade_Cost_RMB_Date2__c=Date.today().addDays(-1),
            Intra_Trade_Cost_RMB_End_Date1__c=Date.today().addDays(1),
            Intra_Trade_Cost_RMB_End_Date2__c=Date.today().addDays(1),
            Intra_Trade_Cost_RMB_1__c=10,
            Intra_Trade_Cost_RMB_2__c=20
        );
        insert new Product2[] {prd1};
 
        // 価格表エントリを作成する
        PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=prd1.Id);
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = 'CNY';
        insert new PricebookEntry[] {entry};
        //经销商、联系人、用户信息
        Account myAccount1 = new Account(name='Testaccount001',
                                        Dealer_discount__c =20,
                                        Ban_On_Use_Date__c = Date.today().addDays(1),
                                        Business_Paper_Expiration_Date__c = Date.today().addDays(1),
                                        Tax_Practice_Expiration_Date__c = Date.today().addDays(1),
                                        Medical_Equipment_Expiration_Date__c = Date.today().addDays(1),
                                        RecordTypeId = rectCo[0].Id);
        insert myAccount1;
        Account acc1 = [select Id,Name,Is_Active_Formula__c from Account where Id = : myAccount1.Id];
        System.assertEquals('有效', acc1.Is_Active_Formula__c);
        Contact core1 = new Contact(email='test@salesforce.com', 
                                    firstname='test',
                                    lastname='001',
                                    accountid=myAccount1.Id);
        insert core1;
         user MyUser_Test1 = New User(ContactId = core1.Id,
                                    Alias = 'newUser1',
                                    Email='newuser1@testorg.com',
                                    EmailEncodingKey='UTF-8', 
                                    LastName='TestUser1', 
                                    LanguageLocaleKey='zh_CN',
                                    LocaleSidKey='zh_CN',
                                    Province__c = '北京市',
                                    ProfileId = prof.Id,
                                    TimeZoneSidKey='Asia/Shanghai', 
                                    UserName='testUser1@testorg.com');
        insert MyUser_Test1;
        //经销商有效合同
        system.runAs(MyUser_Test1){
            Account myAccount2 = new Account(name='Testaccount002',
                                                RecordTypeId = rectContract[0].Id,
                                                Contract_Decide_Start_Date__c = Date.today().addDays(-1),
                                                Contract_Decide_End_Date__c =Date.today().addDays(1),
                                                Contract_Start_Date__c = Date.today().addDays(-1),
                                                Contract_End_Date__c =Date.today().addDays(1),
                                                Agent_Ref__c =myAccount1.Id,
                                                ET_SP_Dealer__c = true,
                                                ParentId =myAccount1.Id);
            insert myAccount2;
            Account acc2 = [select Id,Name,Is_Active_Formula__c from Account where Id = : myAccount2.Id];
            System.assertEquals('有效', acc2.Is_Active_Formula__c);
 
 
            Product2__c pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='NFM110Prd1',Product2__c=prd1.id);
            //Product2__c pro2 = new Product2__c(Name='Pro002',OT_CODE_Text__c='NFM110Prd2',Product2__c=prd2.id);
            insert new Product2__c[] {pro1};
 
            Consumable_order__c coc = new Consumable_order__c(Name = 'Name001',
                                                                Dealer_Info__c = myAccount1.Id,
                                                                Order_status__c = '已提交',
                                                                RecordTypeid = conOrder_Order[0].Id,
                                                                Contract_application_decision__c ='Name001'
                                                                ,SalesManager__c = MyUser_Test1.Id,
                                                                Order_effective_contact__c = myAccount2.Id,
                                                                Order_type__c = '订单'
 
 
                                                                );
            insert coc;
            Consumable_orderdetails__c codc = new Consumable_orderdetails__c(Name='orderdetails001',                                                                            Consumable_order__c = coc.id,
                                                                                Consumable_Product__c =pro1.id,
                                                                                RecordTypeId =conOrderDetail_Order[0].Id,
                                                                                Consumable_count__c = 2,
                                                                                Intra_Trade_List_RMB__c = 100);
            insert codc;
            
            PageReference ref = new PageReference('/apex/Consumable_order_Alert?id=' + coc.id);
            Test.setCurrentPage(ref);
               Consumable_order_AlertController controller = new Consumable_order_AlertController();
            controller.init();
        }
    }
    
 
    
}