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
@isTest
private class TargetCustomerHandlerTest {
    
    @isTest 
    static void test_method_one() {
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
        // ユーザー作成
        User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', 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;
        // 取引先作成
        List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectHp.size() == 0) {
            return;
        }
 
        Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'AccountCaseHistoryTestHp1', OwnerId = hpOwner.Id);
        insert hp;
        List<Account> dc1s = [Select Id, Name, Department_Class_Label__c from Account where Parent.Id = :hp.Id and Department_Class_Label__c in ('消化科')];
        User deptPOwner = new User(Test_staff__c = true, LastName = 'deptP', FirstName = 'owner', Alias = 'deptP', CommunityNickname = 'deptPOwner', Email = 'olympus_deptpowner@sunbridge.com', Username = 'olympus_deptpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert deptPOwner;
        List<User> getUsers = [select Id from User where LastName = 'deptP'];
        System.runAs(deptPOwner){
            Date dateToday = Date.today();
            Integer year = dateToday.year();
            Integer month = dateToday.month();
            if (month < 4) {
                year -= 1;
            }
            String selectedTab = String.valueOf(year - 1867 - 1 + 'P'); 
            Account_Number_of_target__c anot = new Account_Number_of_target__c();
            anot.Account__c = dc1s[0].Id;
            anot.Account_HP__c = hp.Id;
            anot.OCM_Period__c = selectedTab;
            anot.Target_amount_290Miro__c = 1;
            anot.Target_amount_3D__c = 1;
            anot.Target_amount_CHS400XZ__c = 1;
            anot.Target_amount_CV170__c = 1;
            anot.Target_amount_CV190__c = 1;
            anot.Target_amount_CV290__c = 1;
            anot.Target_amount_EUME2__c = 1;
            anot.Target_amount_OERAW__c = 1;
            anot.Target_amount_OTVS190__c = 1;
            anot.Target_amount_OTVS400__c = 1;
            anot.Target_amount_UCES3__c = 1;
            anot.Target_amount_USG400__c = 1;
            anot.Target_amount_GW__c = 1;
            anot.Department_Budget_Sum_Price__c = 1;
            
            anot.OPD_290Miro__c = 1;
            anot.OPD_3D__c = 1;
            anot.OPD_CHS400XZ__c = 1;
            anot.OPD_CV170__c = 1;
            anot.OPD_CV190__c = 1;
            anot.OPD_CV290__c = 1;
            anot.OPD_EUME2__c = 1;
            anot.OPD_OERAW__c = 1;
            anot.OPD_OTVS190__c = 1;
            anot.OPD_OTVS400__c = 1;
            anot.OPD_UCES3__c = 1;
            anot.OPD_USG400__c = 1;
            anot.OPD_GW__c = 1;
            //anot.Submit_Customer_target__c = true;
            insert anot;
            List<Account_Number_of_target__c> gets = [select Id ,Name,TargetCustomerModifier__c from Account_Number_of_target__c];
            system.assertEquals(getUsers[0].Id,gets[0].TargetCustomerModifier__c);
            anot.Target_amount_290Miro__c = 0;
            anot.Target_amount_3D__c = 0;
            anot.Target_amount_CHS400XZ__c = 0;
            anot.Target_amount_CV170__c = 0;
            anot.Target_amount_CV190__c = 0;
            anot.Target_amount_CV290__c = 0;
            anot.Target_amount_EUME2__c = 0;
            anot.Target_amount_OERAW__c = 0;
            anot.Target_amount_OTVS190__c = 0;
            anot.Target_amount_OTVS400__c = 0;
            anot.Target_amount_UCES3__c = 0;
            anot.Target_amount_USG400__c = 0;
            anot.Target_amount_GW__c = 0;
            anot.Department_Budget_Sum_Price__c = 0;
 
            anot.OPD_290Miro__c = 0;
            anot.OPD_3D__c = 0;
            anot.OPD_CHS400XZ__c = 0;
            anot.OPD_CV170__c = 0;
            anot.OPD_CV190__c = 0;
            anot.OPD_CV290__c = 0;
            anot.OPD_EUME2__c = 0;
            anot.OPD_OERAW__c = 0;
            anot.OPD_OTVS190__c = 0;
            anot.OPD_OTVS400__c = 0;
            anot.OPD_UCES3__c = 0;
            anot.OPD_USG400__c = 0;
            anot.OPD_GW__c = 0;
 
            //anot.Submit_Customer_target__c = false;
            update anot;
        }
    }
    
}