@@ -43,61 +43,96 @@ def get_tasks(
43
43
changed = []
44
44
synced_accounts = []
45
45
46
- # divide customer tenants for each task
47
- customer_tenants , first_sync_tenants = self ._get_customer_tenants (
48
- secret_data , linked_accounts
49
- )
50
-
51
- if len (customer_tenants ) == 0 and len (first_sync_tenants ) > 0 :
52
- customer_tenants .extend (first_sync_tenants )
53
- first_sync_tenants = []
46
+ # Only for MicrosoftPartnerAgreement
47
+ if options .get ("collect_scope" ) == "billing_account_id" :
48
+ start = datetime .strptime (start_month , "%Y-%m" )
49
+ end = datetime .utcnow ()
54
50
55
- divided_customer_tenants = self ._get_divided_customer_tenants (
56
- customer_tenants
57
- )
51
+ month_range = relativedelta (end , start ).months
52
+ month_range_step = math .ceil ((month_range + 1 ) / _TASK_LIST_SIZE )
58
53
59
- for divided_customer_tenant_info in divided_customer_tenants :
60
- tasks .append (
61
- {
62
- "task_options" : {
63
- "start" : start_month ,
64
- "account_agreement_type" : billing_account_agreement_type ,
65
- "collect_scope" : "customer_tenant_id" ,
66
- "customer_tenants" : divided_customer_tenant_info ,
67
- "billing_tenant_id" : secret_data ["tenant_id" ],
68
- }
69
- }
70
- )
71
- if linked_accounts :
72
- synced_accounts = self ._extend_synced_accounts (
73
- synced_accounts , divided_customer_tenant_info
54
+ for month in range (
55
+ 0 ,
56
+ month_range + 1 ,
57
+ math .ceil ((month_range + 1 ) / _TASK_LIST_SIZE ),
58
+ ):
59
+ task_start_month = datetime .strftime (
60
+ start + relativedelta (months = month ), "%Y-%m"
61
+ )
62
+ task_end_month = datetime .strftime (
63
+ start + relativedelta (months = month + month_range_step - 1 ),
64
+ "%Y-%m" ,
74
65
)
75
- changed .append ({"start" : start_month })
76
- if first_sync_tenants :
77
- first_sync_start_month = self ._get_start_month (start = None )
78
- tasks .append (
79
- {
80
- "task_options" : {
81
- "start" : first_sync_start_month ,
82
- "account_agreement_type" : billing_account_agreement_type ,
83
- "collect_scope" : "customer_tenant_id" ,
84
- "customer_tenants" : first_sync_tenants ,
85
- "billing_tenant_id" : secret_data ["tenant_id" ],
86
- "is_sync" : False ,
66
+ tasks .append (
67
+ {
68
+ "task_options" : {
69
+ "start" : task_start_month ,
70
+ "end" : task_end_month ,
71
+ "account_agreement_type" : billing_account_agreement_type ,
72
+ "collect_scope" : "billing_account_id" ,
73
+ "billing_tenant_id" : secret_data ["tenant_id" ],
74
+ }
87
75
}
88
- }
76
+ )
77
+ if linked_accounts :
78
+ synced_accounts = linked_accounts
79
+ changed .append ({"start" : start_month })
80
+ else :
81
+ # divide customer tenants for each task
82
+ customer_tenants , first_sync_tenants = self ._get_customer_tenants (
83
+ secret_data , linked_accounts
84
+ )
85
+
86
+ if len (customer_tenants ) == 0 and len (first_sync_tenants ) > 0 :
87
+ customer_tenants .extend (first_sync_tenants )
88
+ first_sync_tenants = []
89
+
90
+ divided_customer_tenants = self ._get_divided_customer_tenants (
91
+ customer_tenants
89
92
)
90
- for tenant_id in first_sync_tenants :
91
- changed .append (
93
+
94
+ for divided_customer_tenant_info in divided_customer_tenants :
95
+ tasks .append (
92
96
{
93
- "start" : first_sync_start_month ,
94
- "filter" : {"additional_info.Tenant Id" : tenant_id },
97
+ "task_options" : {
98
+ "start" : start_month ,
99
+ "account_agreement_type" : billing_account_agreement_type ,
100
+ "collect_scope" : "customer_tenant_id" ,
101
+ "customer_tenants" : divided_customer_tenant_info ,
102
+ "billing_tenant_id" : secret_data ["tenant_id" ],
103
+ }
95
104
}
96
105
)
97
- if linked_accounts :
98
- synced_accounts = self ._extend_synced_accounts (
99
- synced_accounts , first_sync_tenants
106
+ if linked_accounts :
107
+ synced_accounts = self ._extend_synced_accounts (
108
+ synced_accounts , divided_customer_tenant_info
109
+ )
110
+ changed .append ({"start" : start_month })
111
+ if first_sync_tenants :
112
+ first_sync_start_month = self ._get_start_month (start = None )
113
+ tasks .append (
114
+ {
115
+ "task_options" : {
116
+ "start" : first_sync_start_month ,
117
+ "account_agreement_type" : billing_account_agreement_type ,
118
+ "collect_scope" : "customer_tenant_id" ,
119
+ "customer_tenants" : first_sync_tenants ,
120
+ "billing_tenant_id" : secret_data ["tenant_id" ],
121
+ "is_sync" : False ,
122
+ }
123
+ }
100
124
)
125
+ for tenant_id in first_sync_tenants :
126
+ changed .append (
127
+ {
128
+ "start" : first_sync_start_month ,
129
+ "filter" : {"additional_info.Tenant Id" : tenant_id },
130
+ }
131
+ )
132
+ if linked_accounts :
133
+ synced_accounts = self ._extend_synced_accounts (
134
+ synced_accounts , first_sync_tenants
135
+ )
101
136
else :
102
137
tasks = [
103
138
{
0 commit comments