GWY
2022-04-27 12b7399736e90d33bfe0c2d29917d6f075246e00
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
@isTest
private class UpdateTotalCostPriceSetTextBatchTest {
    static testMethod void testMethod1() {
         List<RecordType> rectBS = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer BS'];
        Account accBS = new Account(
            Name = '*',
            RecordTypeId = rectBS[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c='Customer BS',
            FacilityName__c='abc',
            PostCode__c='000000'
        );
        insert accBS;
 
        Contact con = new Contact();
        con.LastName = 'test';
        con.AccountId = accBS.Id;
        con.MobilePhone = 'MobilePhoneD__c';
        con.OtherPhone = 'OtherPhoneD__c';
        con.Fax = 'FaxD__c';
        con.Email = 'EmailD__c@test.com';
        con.Phone = 'PhoneD__c';
        con.Title = 'TitleD__c';
        con.Address1__c = 'Address1D__c';
        con.Address2__c = 'Address2D__c';
        con.Address3__c = 'Address3D__c';
        con.Postcode__c = '100111';
        con.ContactStatus__c = 'ContactStatusD__c';
        con.CancelReason__c = 'CancelReasonD__c';
        con.StatusD__c = 'Pass';
 
        insert con;
 
        Id pricebookId = Test.getStandardPricebookId();
 
        Pricebook2 pricebook = new Pricebook2(
            Name = 'BS',
            ProductSegment__c = 'BS',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine',
            isActive = true
        );
        insert pricebook;
 
        Product2 product1 = new Product2();
        product1.Name = 'product1';
        product1.ProductCode = 'product1';
        product1.Product_ECCode__c = 'product1';
        product1.IsActive = true;
        insert product1;
 
        PricebookEntry standardPrice1 = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = product1.Id,
            UnitPrice = 0,
            IsActive = true
        );
        insert standardPrice1;
 
        PricebookEntry entry1 = new PricebookEntry(Pricebook2Id = pricebook.Id, Product2Id = product1.Id);
        entry1.UnitPrice = 0;
        entry1.IsActive = true;
        entry1.UseStandardPrice = false;
        insert entry1;
 
        List<RecordType> rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity'];
        // 有预定下单日
        Opportunity opp = new Opportunity(
            Name = 'test opp',
            AccountId = accBS.Id,
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            StageName = 'Phase3',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'BS',
            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;
 
        Order odr = new Order(
            Name = '',
            Status = 'Draft',
            AccountId = accBS.Id,
            ApproveStatus__c = 'Draft',
            OpportunityId = opp.Id,
            EffectiveDate = Date.today(),
            IE_SP5_D__c = true,
            SpecialDeliveryAccount_D__c = accBS.Id,
            SpecialDeliveryContact2_D__c = con.Id
        );
        insert odr;
 
        OrderItem oi1 = new OrderItem(
            OrderId = odr.Id,
            PriceBookEntryId = entry1.Id,
            Quantity = 1,
            UnitPrice = 10
        );
        insert oi1;
        List<String> ids = new List<String>();
        ids.add(odr.Id);
        Database.executeBatch(new UpdateTotalCostPriceSetTextBatch(), 20);  
        Database.executeBatch(new UpdateTotalCostPriceSetTextBatch(ids), 20);    
        UpdateTotalCostPriceSetTextBatch.executeWebSide1(odr.Id);
    }
}