@isTest
|
private class MCAEHandlerTest {
|
private static Id pricebookId = ControllerUtil.getStandardPricebook().Id;
|
static Account createHospital( String hospitalName) {
|
// 病院を作る
|
Account hospital = new Account();
|
hospital.recordtypeId = [Select Id FROM RecordType WHERE DeveloperName = 'HP'].id;
|
hospital.Name = hospitalName;
|
insert hospital;
|
return hospital;
|
}
|
|
static List<Account> selectStrategicDep( Account hospital) {
|
// 戦略科室を得る
|
List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
|
return strategicDep;
|
}
|
|
static Account createDep( Account hospital, Account strategicDep) {
|
// 診療科を作る
|
Account dep = new Account();
|
dep.recordtypeId = [Select Id FROM RecordType WHERE DeveloperName = 'Department_GI'].id;
|
dep.Name = 'test dep';
|
dep.ParentId = strategicDep.Id;
|
dep.Department_Class__c = strategicDep.Id;
|
dep.Hospital__c = hospital.Id;
|
insert dep;
|
return dep;
|
}
|
|
static Asset createAsset( Account hospital, Account strategicDep, Account dep) {
|
// 製品を作る
|
Product2 productA = new Product2( Name='テスト商品');
|
insert productA;
|
|
// 価格表エントリを作成する
|
PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=productA.Id);
|
entry.UnitPrice = 0;
|
entry.IsActive = true;
|
entry.UseStandardPrice = false;
|
entry.CurrencyIsoCode = 'CNY';
|
entry.Product2Id = productA.Id;
|
insert entry;
|
|
// 納入機器を作成する
|
Asset asset = new Asset();
|
asset.Name = 'テスト機器';
|
asset.AccountId = dep.Id;
|
asset.Department_Class__c = strategicDep.Id;
|
asset.Hospital__c = hospital.Id;
|
asset.SerialNumber = 'testserial';
|
insert asset;
|
|
return asset;
|
}
|
|
static Maintenance_Contract__c createMaintenanceContract( Account hospital, Account strategicDep, Account dep) {
|
Maintenance_Contract__c contract = new Maintenance_Contract__c();
|
contract.Name = 'tect contract';
|
contract.status__c ='契約';
|
contract.Maintenance_Contract_No__c = 'Kami_Contract_No';
|
contract.Contract_Conclusion_Date__c = Date.today();
|
contract.Hospital__c = hospital.Id;
|
contract.Department_Class__c = strategicDep.Id;
|
contract.Department__c = dep.Id;
|
contract.Contract_Start_Date__c = Date.today().addDays( -10); // 10日前
|
contract.Contract_End_Date__c = Date.today().addDays( 5); // 5日後
|
contract.SalesOfficeCode_selection__c = '北京RC';
|
insert contract;
|
return contract;
|
}
|
static testMethod void testMethod1() {
|
// Implement test code
|
// 病院、戦略科室、診療科の情報を作成します
|
Account hospital = createHospital( 'test hospital');
|
Account[] strategicDep = selectStrategicDep( hospital);
|
Account dep = createDep( hospital, strategicDep[0]);
|
|
// 納入機器を作る
|
Asset asset = createAsset( hospital, strategicDep[0], dep);
|
|
// 维修合同を作成する
|
Maintenance_Contract__c contract = createMaintenanceContract( hospital, strategicDep[0], dep);
|
|
// 维修合同报价作成
|
Maintenance_Contract_Estimate__c contactEsti = new Maintenance_Contract_Estimate__c(
|
Name = 'contract estimate 1',
|
Maintenance_Contract__c = contract.Id,
|
Contract_Esti_Start_Date__c = Date.today(),
|
Contract_Start_Date__c = Date.today(),
|
Contract_Range__c = 12,
|
Maintenance_Price__c = 1500,
|
Estimate_Trial_Money__c = 1500,
|
NotUse_Oxygenated_Water__c = true,
|
Process_Status__c='申请中',
|
Submit_quotation_day__c = Date.today()
|
);
|
insert contactEsti;
|
|
contactEsti.Process_Status__c='批准';
|
update contactEsti;
|
|
Maintenance_Contract_Asset_Estimate__c mcae1 = new Maintenance_Contract_Asset_Estimate__c(
|
Asset__c = asset.Id,
|
Maintenance_Contract_Estimate__c = contactEsti.Id,
|
Estimate_List_Price__c = 100,
|
Estimate_List_Price_All_Txt__c = 11.00,
|
Comment__c = '一二三四五六七八九十一二三四五'
|
);
|
insert mcae1;
|
}
|
}
|