@@ -272,17 +272,16 @@ def _aggregate_monthly_cost_report(
272
272
response = self .cost_mgr .analyze_monthly_costs (query , domain_id )
273
273
results = response .get ("results" , [])
274
274
for aggregated_cost_report in results :
275
+ ag_cost = aggregated_cost_report .pop ("cost" , 0.0 )
275
276
ag_cost_report_currency = data_source_currency_map .get (
276
277
aggregated_cost_report .pop ("data_source_id" )
277
278
)
278
- aggregated_cost_report ["cost" ] = {
279
- ag_cost_report_currency : aggregated_cost_report .pop ("cost" )
280
- }
279
+
280
+ aggregated_cost_report ["cost" ] = CostReportManager .get_exchange_currency (
281
+ ag_cost , ag_cost_report_currency , self .currency_map
282
+ )
281
283
aggregated_cost_report ["status" ] = status
282
284
aggregated_cost_report ["currency" ] = currency
283
- aggregated_cost_report ["report_number" ] = self .generate_report_number (
284
- report_month , issue_day
285
- )
286
285
if issue_month :
287
286
aggregated_cost_report ["issue_date" ] = f"{ issue_month } -{ issue_day } "
288
287
aggregated_cost_report ["report_month" ] = report_month
@@ -302,9 +301,15 @@ def _aggregate_monthly_cost_report(
302
301
cost_report_data_svc .currency_map = self .currency_map
303
302
cost_report_data_svc .currency_date = self .currency_date
304
303
305
- for aggregated_cost_report in aggregated_cost_report_results :
306
- aggregated_cost_report ["cost" ] = CostReportManager .get_exchange_currency (
307
- aggregated_cost_report ["cost" ], self .currency_map
304
+ start_cost_report_number = self .get_start_cost_report_number (
305
+ domain_id , report_month , issue_day
306
+ )
307
+
308
+ for cost_report_idx , aggregated_cost_report in enumerate (
309
+ aggregated_cost_report_results , start = start_cost_report_number
310
+ ):
311
+ aggregated_cost_report ["report_number" ] = self .generate_report_number (
312
+ report_month , issue_day , cost_report_idx
308
313
)
309
314
310
315
aggregated_cost_report [
@@ -383,6 +388,41 @@ def send_cost_report(self, cost_report_vo: CostReport) -> None:
383
388
f"[send_cost_report] send cost report ({ workspace_id } /{ cost_report_vo .cost_report_id } ) to { len (users_info )} users"
384
389
)
385
390
391
+ def get_email_verified_workspace_owner_users (
392
+ self , domain_id : str , workspace_id : str , role_types : list = None
393
+ ) -> list :
394
+ identity_mgr : IdentityManager = self .locator .get_manager ("IdentityManager" )
395
+
396
+ if "WORKSPACE_OWNER" not in role_types :
397
+ return []
398
+
399
+ # list users in workspace
400
+ users_info = identity_mgr .list_workspace_users (
401
+ params = {
402
+ "workspace_id" : workspace_id ,
403
+ "state" : "ENABLED" ,
404
+ "role_type" : "WORKSPACE_OWNER" ,
405
+ "query" : {
406
+ "filter" : [
407
+ {"k" : "email_verified" , "v" : True , "o" : "eq" },
408
+ ]
409
+ },
410
+ },
411
+ domain_id = domain_id ,
412
+ ).get ("results" , [])
413
+
414
+ return users_info
415
+
416
+ def get_start_cost_report_number (
417
+ self , domain_id : str , report_month : str , issue_day : int
418
+ ) -> int :
419
+ return (
420
+ self .cost_report_mgr .filter_cost_reports (
421
+ domain_id = domain_id , issue_date = f"{ report_month } -{ issue_day } "
422
+ ).count ()
423
+ + 1
424
+ )
425
+
386
426
def _get_workspace_name_map (self , domain_id : str ) -> Tuple [dict , list ]:
387
427
identity_mgr : IdentityManager = self .locator .get_manager ("IdentityManager" )
388
428
workspace_name_map = {}
@@ -437,31 +477,6 @@ def _get_temporary_sso_access_token(self, domain_id: str, workspace_id: str) ->
437
477
}
438
478
return identity_mgr .grant_token (params )
439
479
440
- def get_email_verified_workspace_owner_users (
441
- self , domain_id : str , workspace_id : str , role_types : list = None
442
- ) -> list :
443
- identity_mgr : IdentityManager = self .locator .get_manager ("IdentityManager" )
444
-
445
- if "WORKSPACE_OWNER" not in role_types :
446
- return []
447
-
448
- # list users in workspace
449
- users_info = identity_mgr .list_workspace_users (
450
- params = {
451
- "workspace_id" : workspace_id ,
452
- "state" : "ENABLED" ,
453
- "role_type" : "WORKSPACE_OWNER" ,
454
- "query" : {
455
- "filter" : [
456
- {"k" : "email_verified" , "v" : True , "o" : "eq" },
457
- ]
458
- },
459
- },
460
- domain_id = domain_id ,
461
- ).get ("results" , [])
462
-
463
- return users_info
464
-
465
480
@staticmethod
466
481
def _get_current_and_last_month () -> Tuple [str , str ]:
467
482
current_month = datetime .utcnow ().strftime ("%Y-%m" )
@@ -482,11 +497,13 @@ def _get_issue_day(is_last_day: bool, issue_day: int) -> int:
482
497
return min (issue_day , last_day )
483
498
484
499
@staticmethod
485
- def generate_report_number (report_month : str , issue_day : int ) -> str :
500
+ def generate_report_number (
501
+ report_month : str , issue_day : int , cost_report_idx : int
502
+ ) -> str :
486
503
report_date = f"{ report_month } -{ issue_day } "
487
504
date_object = datetime .strptime (report_date , "%Y-%m-%d" )
488
505
489
- return f"CostReport_{ date_object .strftime ('%y%m%d%H%M' )} "
506
+ return f"CostReport_{ date_object .strftime ('%y%m%d' ) } { str ( cost_report_idx ). zfill ( 4 )} "
490
507
491
508
@staticmethod
492
509
def _get_data_source_currency_map (
0 commit comments