@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);
|
}
|
}
|