@@ -416,7 +416,7 @@ def _make_benefit_cost_data(
416416 if not billed_at :
417417 continue
418418
419- data = self ._make_benefit_cost_info (cb_result , billed_at )
419+ data = self ._make_benefit_cost_info (cb_result , options , billed_at )
420420 benefit_costs_data .append (data )
421421
422422 except Exception as e :
@@ -425,7 +425,11 @@ def _make_benefit_cost_data(
425425 _LOGGER .info (f"[get_benefit_data] total count: { total_count } " )
426426 return benefit_costs_data
427427
428- def _make_benefit_cost_info (self , result : dict , billed_at : str ) -> dict :
428+ def _make_benefit_cost_info (
429+ self , result : dict , options : dict , billed_at : str
430+ ) -> dict :
431+ cost = 0
432+
429433 additional_info = {
430434 "Pricing Model" : result .get ("PricingModel" ),
431435 "Benefit Id" : result .get ("BenefitId" ),
@@ -463,8 +467,16 @@ def _make_benefit_cost_info(self, result: dict, billed_at: str) -> dict:
463467 )
464468 actual_cost = self ._convert_str_to_float_format (result .get ("Cost" , 0.0 ))
465469
470+ # cost_metric = "AmortizedCost" and include_reservation_cost_at_payg = "ActualCost"
471+ if options .get ("include_reservation_cost_at_payg" ) == "ActualCost" :
472+ if options .get ("show_reservation_cost_as_retail" ):
473+ # TODO: Add logic to show Actual Cost RI/SP as retail
474+ pass
475+ else :
476+ cost = actual_cost
477+
466478 data = {
467- "cost" : 0 ,
479+ "cost" : cost ,
468480 "usage_quantity" : usage_quantity ,
469481 "provider" : "azure" ,
470482 "product" : result .get ("MeterCategory" ),
@@ -518,23 +530,48 @@ def _get_cost_from_result_with_options(self, result: dict, options: dict) -> flo
518530 else :
519531 cost_pay_as_you_go = 0.0
520532
521- if options .get ("include_reservation_cost_at_payg" , False ) :
522- if options .get ("cost_metric " ) == "AmortizedCost" :
533+ if options .get ("cost_metric" ) == "AmortizedCost" :
534+ if options .get ("include_reservation_cost_at_payg " ) == "AmortizedCost" :
523535 pricing_model = result .get ("pricingmodel" )
524536 charge_type = result .get ("chargetype" )
537+
525538 if (
526539 pricing_model in ["Reservation" , "SavingsPlan" ]
527540 and charge_type == "Usage"
528541 ):
529- cost_pay_as_you_go = self ._get_retail_cost (result )
530- elif options .get ("cost_metric" ) == "ActualCost" :
542+ if options .get ("show_reservation_cost_as_retail" , False ):
543+ cost_pay_as_you_go = self ._get_retail_cost (result )
544+ # if cost_pay_as_you_go == 0.0:
545+ # cost_pay_as_you_go = self._convert_str_to_float_format(
546+ # result.get("costinbillingcurrency", 0.0)
547+ # )
548+ else :
549+ cost_pay_as_you_go = self ._convert_str_to_float_format (
550+ result .get ("costinbillingcurrency" , 0.0 )
551+ )
552+ elif options .get ("cost_metric" ) == "ActualCost" :
553+ if options .get ("include_reservation_cost_at_payg" ) == "ActualCost" :
531554 pricing_model = result .get ("pricingmodel" )
532555 charge_type = result .get ("chargetype" )
533- if (
534- pricing_model in ["Reservation" , "SavingsPlan" ]
535- and charge_type == "Purchase"
536- ):
537- cost_pay_as_you_go = self ._get_retail_cost (result )
556+
557+ if pricing_model in ["Reservation" , "SavingsPlan" ] and charge_type in [
558+ "Purchase" ,
559+ "Refund" ,
560+ ]:
561+ if options .get ("show_reservation_cost_as_retail" , False ):
562+ # TODO: Add logic to show Actual Cost RI/SP as retail
563+ # pricing_model = result.get("pricingmodel")
564+ # charge_type = result.get("chargetype")
565+ # if (
566+ # pricing_model in ["Reservation", "SavingsPlan"]
567+ # and charge_type in ["Purchase", "Refund"]
568+ # ):
569+ # cost_pay_as_you_go = self._get_retail_cost(result)
570+ pass
571+ else :
572+ cost_pay_as_you_go = self ._convert_str_to_float_format (
573+ result .get ("costinbillingcurrency" , 0.0 )
574+ )
538575
539576 return cost_pay_as_you_go
540577
0 commit comments