Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cloudforet/cost_analysis/conf/cost_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"dimensions": {
"name": "ChargeType",
"operator": "In",
"values": ["Purchase"],
"values": ["Purchase", "Refund"],
}
},
{
Expand Down
61 changes: 49 additions & 12 deletions src/cloudforet/cost_analysis/manager/cost_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def _make_benefit_cost_data(
if not billed_at:
continue

data = self._make_benefit_cost_info(cb_result, billed_at)
data = self._make_benefit_cost_info(cb_result, options, billed_at)
benefit_costs_data.append(data)

except Exception as e:
Expand All @@ -425,7 +425,11 @@ def _make_benefit_cost_data(
_LOGGER.info(f"[get_benefit_data] total count: {total_count}")
return benefit_costs_data

def _make_benefit_cost_info(self, result: dict, billed_at: str) -> dict:
def _make_benefit_cost_info(
self, result: dict, options: dict, billed_at: str
) -> dict:
cost = 0

additional_info = {
"Pricing Model": result.get("PricingModel"),
"Benefit Id": result.get("BenefitId"),
Expand Down Expand Up @@ -463,8 +467,16 @@ def _make_benefit_cost_info(self, result: dict, billed_at: str) -> dict:
)
actual_cost = self._convert_str_to_float_format(result.get("Cost", 0.0))

# cost_metric = "AmortizedCost" and include_reservation_cost_at_payg = "ActualCost"
if options.get("include_reservation_cost_at_payg") == "ActualCost":
if options.get("show_reservation_cost_as_retail"):
# TODO: Add logic to show Actual Cost RI/SP as retail
pass
else:
cost = actual_cost

data = {
"cost": 0,
"cost": cost,
"usage_quantity": usage_quantity,
"provider": "azure",
"product": result.get("MeterCategory"),
Expand Down Expand Up @@ -518,23 +530,48 @@ def _get_cost_from_result_with_options(self, result: dict, options: dict) -> flo
else:
cost_pay_as_you_go = 0.0

if options.get("include_reservation_cost_at_payg", False):
if options.get("cost_metric") == "AmortizedCost":
if options.get("cost_metric") == "AmortizedCost":
if options.get("include_reservation_cost_at_payg") == "AmortizedCost":
pricing_model = result.get("pricingmodel")
charge_type = result.get("chargetype")

if (
pricing_model in ["Reservation", "SavingsPlan"]
and charge_type == "Usage"
):
cost_pay_as_you_go = self._get_retail_cost(result)
elif options.get("cost_metric") == "ActualCost":
if options.get("show_reservation_cost_as_retail", False):
cost_pay_as_you_go = self._get_retail_cost(result)
# if cost_pay_as_you_go == 0.0:
# cost_pay_as_you_go = self._convert_str_to_float_format(
# result.get("costinbillingcurrency", 0.0)
# )
Comment on lines +544 to +547
Copy link

Copilot AI Jun 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider removing or clarifying the commented-out code block to enhance maintainability if it is no longer necessary for future reference.

Suggested change
# if cost_pay_as_you_go == 0.0:
# cost_pay_as_you_go = self._convert_str_to_float_format(
# result.get("costinbillingcurrency", 0.0)
# )

Copilot uses AI. Check for mistakes.
else:
cost_pay_as_you_go = self._convert_str_to_float_format(
result.get("costinbillingcurrency", 0.0)
)
elif options.get("cost_metric") == "ActualCost":
if options.get("include_reservation_cost_at_payg") == "ActualCost":
pricing_model = result.get("pricingmodel")
charge_type = result.get("chargetype")
if (
pricing_model in ["Reservation", "SavingsPlan"]
and charge_type == "Purchase"
):
cost_pay_as_you_go = self._get_retail_cost(result)

if pricing_model in ["Reservation", "SavingsPlan"] and charge_type in [
"Purchase",
"Refund",
]:
if options.get("show_reservation_cost_as_retail", False):
# TODO: Add logic to show Actual Cost RI/SP as retail
# pricing_model = result.get("pricingmodel")
# charge_type = result.get("chargetype")
# if (
# pricing_model in ["Reservation", "SavingsPlan"]
# and charge_type in ["Purchase", "Refund"]
# ):
# cost_pay_as_you_go = self._get_retail_cost(result)
pass
else:
cost_pay_as_you_go = self._convert_str_to_float_format(
result.get("costinbillingcurrency", 0.0)
)

return cost_pay_as_you_go

Expand Down
14 changes: 10 additions & 4 deletions src/cloudforet/cost_analysis/manager/data_source_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ def init_response(options: dict, domain_id: str) -> dict:
"use_account_routing(bool)": False,
"exclude_license_cost(bool)": False,
"include_credit_cost(bool)": False,
"include_reservation_cost_at_payg(bool)": False,
"include_reservation_cost_at_payg(str)": "ActualCost",
"show_reservation_cost_as_retail(bool): False,
Copy link

Copilot AI Jun 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There appears to be a syntax error in the dictionary key: the key 'show_reservation_cost_as_retail(bool)' is missing a closing quote. It should be corrected to "show_reservation_cost_as_retail(bool)": False.

Suggested change
"show_reservation_cost_as_retail(bool): False,
"show_reservation_cost_as_retail(bool)": False,

Copilot uses AI. Check for mistakes.
"cost_info(dict)": {
"name" :"PayAsYouGo",
"unit" :"KRW"
Expand Down Expand Up @@ -122,7 +123,7 @@ def init_response(options: dict, domain_id: str) -> dict:
"use_account_routing": False,
"exclude_license_cost": False,
"include_credit_cost": False,
"include_reservation_cost_at_payg": False,
"include_reservation_cost_at_payg": None,
"cost_info": {},
"data_info": {},
"additional_info": copy.deepcopy(_DEFAULT_METADATA_ADDITIONAL_INFO),
Expand Down Expand Up @@ -167,8 +168,13 @@ def init_response(options: dict, domain_id: str) -> dict:
if options.get("include_credit_cost"):
plugin_metadata["include_credit_cost"] = True

if options.get("include_reservation_cost_at_payg"):
plugin_metadata["include_reservation_cost_at_payg"] = True
if options.get("include_reservation_cost_at_payg") == "ActualCost":
plugin_metadata["include_reservation_cost_at_payg"] = "ActualCost"
else:
plugin_metadata["include_reservation_cost_at_payg"] = "AmortizedCost"

if options.get("show_reservation_cost_as_retail"):
plugin_metadata["show_reservation_cost_as_retail"] = True

return {"metadata": plugin_metadata}

Expand Down
Loading