buli
2022-05-14 ead4df22dca33a867279471821ca675f91dec760
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
@isTest
private class UpdateTotalCostPriceSetTextInquiryTest {
    static testMethod void testMethod1() {
        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        List<RecordType> rectForeignCompany = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'ForeignCompany'];
        Id pricebookId = Test.getStandardPricebookId();
        
        /*PriceBook2 pricebook1 = ControllerUtil.getStandardPricebook();
        Id pricebookId = pricebook1.id;*/
        Pricebook2 pricebook = new Pricebook2(
            Name = 'IE',
            ProductSegment__c = 'IE',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine',
            isActive = true
        );
        insert pricebook;
        
        /*Pricebook2 pricebook =  [select Id from PriceBook2 where ProductSegment__c = 'IE' and
         TradeType__c = 'Taxation' and SalesChannel__c = 'direct' and MachineParts__c = 'Machine' and  isActive = true limit 1];
*/
        Product2 product1 = new Product2();
        product1.Name = 'product1';
        product1.IsActive = true;
        product1.ProductModels__c = false;
 
        
        Product2 product2 = new Product2();
        product2.Name = 'product2';
        product2.IsActive = true;
        product2.ProductModels__c = true;
        
        Product2 product3 = new Product2();
        product3.Name = 'product3';
        product3.IsActive = true;
        
        insert new Product2[] {product1,product2,product3};
        
        PricebookEntry standardPrice1 = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = product1.Id,
            UnitPrice = 0,
            CurrencyIsoCode = 'CNY',
            IsActive = true
 
        );
        
        PricebookEntry standardPrice2 = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = product2.Id,
            UnitPrice = 0,
            CurrencyIsoCode = 'CNY',
            IsActive = true
        );
        
        PricebookEntry standardPrice3 = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = product3.Id,
            UnitPrice = 0,
            CurrencyIsoCode = 'CNY',
            IsActive = true
        );
        
        insert new PricebookEntry[] {standardPrice1,standardPrice2,standardPrice3};
        
        PricebookEntry entry1 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product1.Id);
        entry1.UnitPrice = 0;
        entry1.IsActive = true;
        entry1.UseStandardPrice = false;
        entry1.CurrencyIsoCode = 'CNY';
        
        PricebookEntry entry2 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product2.Id);
        entry2.UnitPrice = 0;
        entry2.IsActive = true;
        entry2.UseStandardPrice = false;
        entry2.CurrencyIsoCode = 'CNY';
        
        PricebookEntry entry3 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product3.Id);
        entry3.UnitPrice = 0;
        entry3.IsActive = true;
        entry3.UseStandardPrice = false;
        entry3.CurrencyIsoCode = 'CNY';
 
        
        insert new PricebookEntry[] {entry1,entry2,entry3};
 
        Account accIE = new Account(
            Name = '*',
            RecordTypeId = rectIE[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c='Customer IE',
            FacilityName__c='abc',
            PostCode__c = '123456'
        );
        insert accIE; 
 
        List<RecordType> rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity'];
        // 有预定下单日
        Opportunity opp = new Opportunity(
            Name = 'test opp',
            AccountId = accIE.Id,
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            StageName = 'Phase3',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'IE',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            SalesChannel__c = 'direct',
            TradeType__c = 'Taxation',
            Machine_Parts__c = 'Machine',
            InquiryResult__c = '112233'
            
        );
        insert opp;
 
        OpportunityLineItem oli = new OpportunityLineItem();
        oli.OpportunityId = opp.Id;
        //oli.Product2 = prd1;
        oli.Quantity = 2;
        oli.UnitPrice = 111;
        oli.Description = 'test';
        oli.PricebookEntryId = entry1.Id;
        insert oli;
 
        OpportunityLineItem oli2 = new OpportunityLineItem();
        oli2.OpportunityId = opp.Id;
        //oli2.Product2 = prd2;
        oli2.Quantity = 2;
        oli2.UnitPrice = 111;
        oli2.Description = 'test';
        oli2.PricebookEntryId = entry1.Id;
        insert oli2;
 
        opp.InquiryResult__c = '112222';
 
        update opp;
 
        /*System.assertEquals(0, opp.Model_product_cnt__c);
        System.assertEquals(0, opp.ProductCount__c);
        System.assertEquals(true, opp.OppBatchUpdate__c);*/
        List<String> ids = new List<String>();
        ids.add(opp.Id);
        Database.executeBatch(new UpdateTotalCostPriceSetTextInquiryBatch(), 20);
        Database.executeBatch(new UpdateTotalCostPriceSetTextInquiryBatch(ids), 20);    
        UpdateTotalCostPriceSetTextInquiryBatch.executeWebSide(opp.Id);
    }
}