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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
@isTest
private class UpdateOppLineItemAgencySubtotalTest {
 
 
 
    private static Product2 product = null;
    private static Pricebook2 pricebook = null;
 
 
    private static  Opportunity opprtunity = null;
 
    static final String RC_HOSPITAL = '病院';
    static final String RC_OPP = '引合';
    static final String RC_SENRYAKUKASHITSUBUNRUI = '戦略科室分類 消化科';
    static final String RC_BYOUIN = '病院';
    static final String RC_SHINRYOUKA = '診療科 その他';
    static final String RC_HANBAOITEN = '販売店';
    static final String RC_KEIYAKU = '契約';
 
    static {
        product = new Product2( Name = 'テスト商品');
        insert product;
        system.debug('##product.Id=[' + product.Id + ']' );
 
        pricebook = ControllerUtil.getStandardPricebook();
        system.debug('##pricebook.Id=[' + pricebook.Id + ']' );
    }
 
    private static String quoteNo = 'textQutote01';
    public static String trade = '内貿';
    public static String CurrencyIso = 'CNY';
 
    private static Boolean isUnitPrice = true;
    private static Boolean isOfferAmount = true;
    private static Boolean isTotalPrice = true;
    private static Boolean isDiscountRate = true;
    private static Boolean isDiscountAmount = true;
    private static Boolean isTradingPrice = true;
    private static Boolean isContractDetail = true;
 
    private static Date offerExpireDate = Date.today();
    private static String clientName = 'test client';
    private static String offerComment = 'test comment';
    private static Date offerPrintDate = Date.today();
    private static String agentName = 'test agent name';
 
    private static PricebookEntry buildPB( String input) {
        PricebookEntry entry = new PricebookEntry( Pricebook2Id = pricebook.Id, Product2Id = product.Id);
 
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = input;
        insert entry;
        return entry;
    }
 
    private static Opportunity buildOppInstance( String inputTrade, String CurrencyIsoCode) {
        Opportunity target = new Opportunity( Name = 'aiueo', StageName = 'contact', CloseDate = Date.today());
        target.Trade__c = inputTrade;
        target.owner_not_automatically_update__c = true;
        target.CurrencyIsoCode = CurrencyIsoCode;
        target.Wholesale_Price__c = 9000;
        return target;
    }
 
    private static QuoteLineItem insertQuoteLineItem( Quote input, Pricebookentry entry) {
        QuoteLineItem target = new QuoteLineItem();
        target.Name__c = 'テスト商品';
        target.QuoteId = input.Id;
        target.Quantity = 1;
        target.Quantity__c = 1;
        target.Cost_Subtotal__c = 0;
        target.Cost__c = 200;
//        target.TotalPrice = 100;
        target.UnitPrice = 10;
        target.ListPrice__c  = 10;
        target.PricebookEntryId = entry.Id;
        insert target;
        return target;
    }
 
    @isTest static void test_method_one() {
        String userId = UserInfo.getUserId();
        User u1 = [SELECT Id, Quote_Correct__c, Quote_Special_Operation__c, Cost_Referable__c FROM User WHERE Id = :userId];
        u1.Quote_Correct__c = false;
        u1.Quote_Special_Operation__c = true;
        u1.Cost_Referable__c = true;
        update u1;
 
        // PricebookEntry
        PricebookEntry entryUSD = buildPB( 'USD');
        PricebookEntry entryCNY = buildPB( 'CNY');
 
        // 引合作成
        Opportunity opp = buildOppInstance( trade, CurrencyIso);
        opp.Trade__c = trade;
        opp.owner_not_automatically_update__c = true;
        opp.Sales_Root__c = '販売店';
        opp.Pricebook2Id = pricebook.id;
        insert opp;
 
        //見積データ作成
        Quote quote = new Quote( Name = 'テスト見積');
        quote.OpportunityId = opp.Id;
        quote.Pricebook2Id = pricebook.id;
        quote.Quote_No__c = quoteNo;
 
        quote.Unit_Price__c = isUnitPrice;
        quote.Offer_Amount__c = isOfferAmount;
        quote.TOTAL__c = isTotalPrice;
        quote.Discount__c = isDiscountRate;
        quote.Pricing__c = isDiscountAmount;
        quote.Preferential_Trading_Price__c = isTradingPrice;
        quote.Contract__c = isContractDetail;
        quote.Quote_Comment__c = offerComment;
        quote.OCM_Agent1_Price__c = 12345;
        quote.Estimation_List_Price__c = 23456;
        insert quote;
        quote = [SELECT Id, OpportunityId, Quote_no__c, Quote_No_Auto__c, CurrencyIsoCode FROM Quote WHERE Id = :quote.id];
        System.assertEquals( CurrencyIso, quote.CurrencyIsoCode);
 
        // 見積品目作成
        QuoteLineItem item01 = insertQuoteLineItem( quote, entryCNY);
        QuoteLineItem item02 = insertQuoteLineItem( quote, entryCNY);
 
        //見積データ検索
        opprtunity = [SElECT Id, Opportunity_no__c, CurrencyIsoCode FROM Opportunity WHERE Id = :opp.id];
        OpportunityLineItem oli = new OpportunityLineItem();
        oli.Quantity = 1;
        //oli.Quantity__c = 1;
        oli.UnitPrice = 0;
        oli.ListPrice__c  = 10;
        oli.OpportunityId = opp.id;
 
        oli.PricebookEntryId = entryCNY.Id;
        insert oli;
        System.Test.startTest();
        quote.AgencyDiscount__c = null;
        update quote;
    }
 
    @isTest static void test_method_two() {
        // Implement test code
    }
 
}