@isTest
|
private class SetProductTargetBatchTest {
|
static private String currentPeriod(Integer i) {
|
Date dateNow = Date.today();
|
Integer year = dateNow.year();
|
Integer month = dateNow.month();
|
if (month < 4) {
|
year -= 1;
|
}
|
return String.valueOf(year + i - 1867 + 'P');
|
}
|
|
static private Date oppCloseDate() {
|
Date nowDate = Date.today();
|
Integer year = nowDate.year();
|
Integer month = nowDate.month();
|
if (month < 4) {
|
nowDate = nowDate.addYears(-1);
|
}
|
return nowDate;
|
}
|
|
static private void makeIPC() {
|
ImportantProductCategory__c ipc1 = new ImportantProductCategory__c(
|
Name = 'test01',
|
depName__c = 'GI',
|
importantProductGoaIName__c = '重点产品01',
|
commodityCode__c = 'test01',
|
commodityName__c = 'test01',
|
if_Quantity__c = true,
|
sort__c = 1
|
);
|
insert ipc1;
|
ImportantProductCategory__c ipc2 = new ImportantProductCategory__c(
|
Name = 'test02',
|
depName__c = 'GI',
|
importantProductGoaIName__c = '重点产品02',
|
commodityCode__c = 'test02',
|
commodityName__c = 'test01',
|
if_Quantity__c = true,
|
sort__c = 2
|
);
|
insert ipc2;
|
ImportantProductCategory__c ipc3 = new ImportantProductCategory__c(
|
Name = 'test03',
|
depName__c = 'GI',
|
importantProductGoaIName__c = '重点产品03',
|
commodityCode__c = 'test03',
|
commodityName__c = 'test03',
|
if_Quantity__c = false,
|
sort__c = 3
|
);
|
insert ipc3;
|
}
|
// 主流程
|
static testMethod void testMethod1() {
|
// システム管理者
|
User u3 = new User(Test_staff__c = true);
|
u3.LastName = '_サンブリッジ';
|
u3.FirstName = 'う';
|
u3.Alias = 'う';
|
u3.Email = 'olympusTest03@sunbridge.com';
|
u3.Username = 'olympusTest03@sunbridge.com';
|
u3.CommunityNickname = 'う';
|
u3.IsActive = true;
|
u3.EmailEncodingKey = 'ISO-2022-JP';
|
u3.TimeZoneSidKey = 'Asia/Tokyo';
|
u3.LocaleSidKey = 'ja_JP';
|
u3.LanguageLocaleKey = 'ja';
|
u3.ProfileId = System.Label.ProfileId_SystemAdmin;
|
u3.Job_Category__c = '销售推广';
|
u3.Province__c = '上海市上海市';
|
u3.Use_Start_Date__c = Date.today().addMonths(-6);
|
insert u3;
|
|
System.runAs(u3) {
|
Oly_TriggerHandler.bypass('PowerBIBaseHandler');
|
makeIPC();
|
Product2 product = new Product2(
|
Name = 'テスト商品',
|
Important_Rroduct_1GI__c = true,
|
Important_Rroduct_2GI__c = true,
|
Important_Rroduct_3GI__c = true,
|
Important_Rroduct_4GI__c = true,
|
Important_Rroduct_5GI__c = true
|
);
|
insert product;
|
Pricebook2 pricebook = ControllerUtil.getStandardPricebook();
|
PricebookEntry entry = new PricebookEntry( Pricebook2Id = pricebook.Id, Product2Id = product.Id);
|
entry.UnitPrice = 0;
|
entry.IsActive = true;
|
entry.UseStandardPrice = false;
|
entry.CurrencyIsoCode = 'CNY';
|
insert entry;
|
|
RecordType[] rt = [select Id from RecordType where SobjectType = 'Opportunity' and IsActive = true and DeveloperName = 'Target'];
|
Profile p = [select id from Profile where id = :System.Label.ProfileId_SystemAdmin];
|
|
Map<String, List<Double>> proportion = new Map<String, List<Double>>();
|
String strObjectiveProportionGI = System.Label.ObjectiveProportionGI;
|
List<String> objectiveProportionGI = strObjectiveProportionGI.split(',');
|
List<Double> doubleGI = new List<Double>();
|
for (String strGI : objectiveProportionGI) {
|
doubleGI.add(Double.valueOf(strGI));
|
}
|
proportion.put('GI', doubleGI);
|
|
User u1 = new User(Test_staff__c = false);
|
u1.LastName = '_サンブリッジ7';
|
u1.FirstName = 'あ';
|
u1.Alias = 'あ9';
|
u1.Email = 'olympusTest01@sunbridge.com';
|
u1.Username = 'olympusTest91@sunbridge.com';
|
u1.CommunityNickname = 'あ9';
|
u1.IsActive = true;
|
u1.EmailEncodingKey = 'ISO-2022-JP';
|
u1.TimeZoneSidKey = 'Asia/Tokyo';
|
u1.LocaleSidKey = 'ja_JP';
|
u1.LanguageLocaleKey = 'ja';
|
u1.ProfileId = System.Label.ProfileId_SystemAdmin;
|
u1.Job_Category__c = '销售推广';
|
u1.Province__c = '上海市上海市';
|
u1.Post__c = '一般';
|
u1.Sales_Speciality__c = '产品担当';
|
u1.Use_Start_Date__c = Date.today().addMonths(-6);
|
insert u1;
|
|
User u2 = new User(Test_staff__c = false);
|
u2.LastName = '_サンブリッジ6';
|
u2.FirstName = 'い';
|
u2.Alias = 'い';
|
u2.Email = 'olympusTest02@sunbridge.com';
|
u2.Username = 'olympusTest02@sunbridge.com';
|
u2.CommunityNickname = 'い';
|
u2.IsActive = true;
|
u2.EmailEncodingKey = 'ISO-2022-JP';
|
u2.TimeZoneSidKey = 'Asia/Tokyo';
|
u2.LocaleSidKey = 'ja_JP';
|
u2.LanguageLocaleKey = 'ja';
|
u2.ProfileId = System.Label.ProfileId_SystemAdmin;
|
u2.Job_Category__c = '销售推广';
|
u2.Province__c = '上海市上海市';
|
u2.Post__c = '一般';
|
u2.Sales_Speciality__c = '产品担当';
|
u2.Use_Start_Date__c = Date.today().addMonths(-6);
|
insert u2;
|
|
List<Key_Product_Goals__c> TestData = new List<Key_Product_Goals__c>();
|
Date dateNow = Date.today();
|
Integer year = dateNow.year();
|
Key_Product_Goals__c testdatum1 = new Key_Product_Goals__c();
|
string key = '上海市上海市' + '_' + '省重点产品目标' + '_' +
|
'重点产品01' + '_' + 'GI' + '_' + 'SalesTarget';
|
testdatum1.key__c = key;
|
testdatum1.Num_Of_OPD__c = 2;
|
testdatum1.Department__c = '1.华北';
|
testdatum1.SAP_Province__c = u1.Province__c;
|
testdatum1.Owner_System__c = u1.Id;
|
testdatum1.iYear__c = year;
|
testdatum1.Is_Processing__c = true;
|
testdatum1.Target_Source__c = 'SalesTarget';
|
TestData.add(testdatum1);
|
insert(TestData);
|
|
TestData = [select id from Key_Product_Goals__c];
|
System.Test.StartTest();
|
Id execBTId = Database.executeBatch(new SetProductTargetBatch(), 10);
|
System.Test.StopTest();
|
|
|
// 设置既存opportunities数据
|
|
Integer y = year;
|
Integer m = 4 ;
|
String syear = String.valueOf(y);
|
String smonth = String.valueOf(m);
|
if (m < 10) {
|
smonth = '0' + smonth;
|
}
|
String sTagetDay = syear + '-' + smonth + '-01';
|
Date tagetDay = Date.valueOf(sTagetDay);
|
list<Opportunity> Opportunities = new list<Opportunity>();
|
Opportunity newopp = new Opportunity();
|
newopp.Name = u2.Alias + ' ' + '重点产品01' ;
|
newopp.StageName = '目標';
|
newopp.OwnerId = u2.Id;
|
// トリガをスルーのため、ここでやります
|
newopp.Owner_System__c = u2.Id;
|
newopp.Opportunity_Category__c = 'GI';
|
String tem_depName = ('GI' == null || 'GI' == '') ? 'GI' : 'GI';
|
newopp.Proportion__c = proportion.get(tem_depName)[0];
|
newopp.CloseDate = tagetDay;
|
newopp.Num_Of_OPD__c = 333;
|
newopp.Target_category__c = '省重点产品目标';
|
newopp.Important_Key_product_category__c = '重点产品01';
|
newopp.SAP_Province__c = u2.Province__c;
|
newopp.RecordTypeId = rt[0].ID;
|
newopp.OCM_Target_period__c = currentPeriod(0);
|
newopp.Target_Source__c = 'SalesTarget';
|
upsert newopp;
|
|
Key_Product_Goals__c testdatum2 = new Key_Product_Goals__c();
|
key = u2.Province__c + '_' + '省重点产品目标' + '_' +
|
'重点产品01' + '_' + 'GI' + '_' + 'SalesTarget';
|
testdatum2.key__c = key;
|
testdatum2.Num_Of_OPD__c = 2;
|
testdatum2.Department__c = '1.华北';
|
testdatum2.SAP_Province__c = u2.Province__c;
|
testdatum2.Owner_System__c = u2.Id;
|
testdatum2.iYear__c = year;
|
testdatum2.Is_Processing__c = true;
|
testdatum2.Target_Source__c = 'SalesTarget';
|
insert(testdatum2);
|
execBTId = Database.executeBatch(new SetProductTargetBatch(), 10);
|
|
Opportunities = [select Name, StageName, Owner_System__c, Opportunity_Category__c, Important_Key_product_category__c
|
from Opportunity];
|
system.assertEquals(13, Opportunities.size());
|
}
|
}
|
}
|