@isTest
|
private class MaintenanceContractTriggerTest {
|
private static User hpOwner = null;
|
private static User hpOwner2 = null;
|
private static Id pricebookId = ControllerUtil.getStandardPricebook().Id;
|
private static Account hospital = null;
|
private static List<Account> strategicDep = null;
|
private static Product2 productA = null;
|
private static Account dep = null;
|
private static PricebookEntry entry = null;
|
private static Asset asset01 = null;
|
private static Asset asset02 = null;
|
private static Asset asset03 = null;
|
private static Maintenance_Contract__c contract = null;
|
static {
|
Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
|
hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', Work_Location__c = '北京', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
|
insert hpOwner;
|
hpOwner2 = new User(Test_staff__c = true, LastName = 'hp2', FirstName = 'owner', Alias = 'hp2', Work_Location__c = '重庆', CommunityNickname = 'hpOwner2', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner2@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
|
insert hpOwner2;
|
|
// 病院を作る
|
hospital = new Account();
|
hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
|
hospital.Name = 'test hospital';
|
insert hospital;
|
|
// 戦略科室を得る
|
strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
|
|
// 診療科を作る
|
dep = new Account();
|
dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id;
|
dep.Name = 'test dep';
|
dep.ParentId = strategicDep[0].Id;
|
dep.Department_Class__c = strategicDep[0].Id;
|
dep.Hospital__c = hospital.Id;
|
insert dep;
|
|
// 製品を作る
|
productA = new Product2( Name='テスト商品');
|
insert productA;
|
|
// 価格表エントリを作成する
|
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;
|
|
// 納入機器を作成する
|
asset01 = new Asset();
|
asset01.Name = 'テスト機器';
|
asset01.AccountId = dep.Id;
|
asset01.Department_Class__c = strategicDep[0].Id;
|
asset01.Hospital__c = hospital.Id;
|
asset01.SerialNumber = 'testserial';
|
insert asset01;
|
asset02 = new Asset();
|
asset02.Name = 'テスト機器';
|
asset02.AccountId = dep.Id;
|
asset02.Department_Class__c = strategicDep[0].Id;
|
asset02.Hospital__c = hospital.Id;
|
asset02.SerialNumber = 'testserial';
|
insert asset02;
|
asset03 = new Asset();
|
asset03.Name = 'テスト機器';
|
asset03.AccountId = dep.Id;
|
asset03.Department_Class__c = strategicDep[0].Id;
|
asset03.Hospital__c = hospital.Id;
|
asset03.SerialNumber = 'testserial';
|
insert asset03;
|
|
// 维修合同を作成する
|
contract = new Maintenance_Contract__c();
|
contract.Name = 'tect contract';
|
contract.Hospital__c = hospital.Id;
|
contract.Department_Class__c = strategicDep[0].Id;
|
contract.Department__c = dep.Id;
|
contract.Contract_Start_Date__c = Date.today() - 10;
|
contract.Contract_End_Date__c = Date.today() + 10;
|
contract.Service_Contract_Staff__c = '00510000002ZZTc';
|
contract.upload_to_RM_time__c = Date.today() + 20;
|
insert contract;
|
|
}
|
static testMethod void testMethod1() {
|
contract.All_Amount__c = 11.11;
|
update contract;
|
|
contract.Payment_Plan_Sum_First__c = 222.11;
|
update contract;
|
|
delete contract;
|
}
|
}
|