Skip to content

Commit

Permalink
Merge pull request #44 from ImMin5/master
Browse files Browse the repository at this point in the history
Fix None type multiplication operation error
  • Loading branch information
ImMin5 authored Feb 4, 2024
2 parents 50b9204 + f872793 commit 8df118c
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions src/cloudforet/cost_analysis/manager/cost_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _make_data_info(self, result, billed_date, options, tenant_id=None):
aggregate_data = {}

aggregate_data = self.update_pay_as_you_go_data(
usage_quantity, cost, result, aggregate_data
usage_quantity, result, aggregate_data
)

data = {
Expand Down Expand Up @@ -153,8 +153,8 @@ def _get_additional_info(self, result, options, tenant_id=None):
additional_info["Benefit Name"] = benefit_name

if (
result.get("pricingmodel") == "Reservation"
and result["metercategory"] == ""
result.get("pricingmodel") == "Reservation"
and result["metercategory"] == ""
):
result["metercategory"] = self._set_product_from_benefit_name(
benefit_name
Expand All @@ -163,14 +163,14 @@ def _get_additional_info(self, result, options, tenant_id=None):
if result.get("metersubcategory") != "" and result.get("metersubcategory"):
additional_info["Meter SubCategory"] = result.get("metersubcategory")
if (
result.get("pricingmodel") == "OnDemand"
and result.get("metercategory") == ""
result.get("pricingmodel") == "OnDemand"
and result.get("metercategory") == ""
):
result["metercategory"] = result.get("metercategory")

if result.get("customername") is None:
if result.get("invoicesectionname") != "" and result.get(
"invoicesectionname"
"invoicesectionname"
):
additional_info["Department Name"] = result.get("invoicesectionname")
elif result.get("departmentname") != "" and result.get("departmentname"):
Expand All @@ -179,15 +179,15 @@ def _get_additional_info(self, result, options, tenant_id=None):
if result.get("accountname") != "" and result.get("accountname"):
additional_info["Enrollment Account Name"] = result["accountname"]
elif result.get("enrollmentaccountname") != "" and result.get(
"enrollmentaccountname"
"enrollmentaccountname"
):
additional_info["Enrollment Account Name"] = result["enrollmentaccountname"]

collect_resource_id = options.get("collect_resource_id", False)
if (
collect_resource_id
and result.get("resourceid") != ""
and result.get("resourceid")
collect_resource_id
and result.get("resourceid") != ""
and result.get("resourceid")
):
additional_info["Resource Id"] = result["resourceid"]
additional_info["Resource Name"] = result["resourceid"].split("/")[-1]
Expand Down Expand Up @@ -344,11 +344,11 @@ def _make_monthly_time_period(self, start_date, end_date):
first_date_of_month = datetime(year, month, 1).strftime("%Y-%m-%d")
if month == 12:
last_date_of_month = (
datetime(year + 1, 1, 1) - timedelta(days=1)
datetime(year + 1, 1, 1) - timedelta(days=1)
).strftime("%Y-%m-%d")
else:
last_date_of_month = (
datetime(year, month + 1, 1) - timedelta(days=1)
datetime(year, month + 1, 1) - timedelta(days=1)
).strftime("%Y-%m-%d")
if last_date_of_month > current_date:
last_date_of_month = current_date
Expand All @@ -375,14 +375,11 @@ def _check_task_options(task_options):
raise ERROR_REQUIRED_PARAMETER(key="task_options.customer_tenants")

@staticmethod
def update_pay_as_you_go_data(usage_quantity, cost, result, aggregate_data):
if pay_g_price := result.get("paygprice", 0):
exchange_rate = result.get("exchangeratepricingtobilling", 1)
pay_as_you_go = (
pay_g_price * usage_quantity * exchange_rate
if pay_g_price != 0
else cost
)
def update_pay_as_you_go_data(usage_quantity, result, aggregate_data):
pay_g_price = result.get("paygprice", 0.0)
exchange_rate = result.get("exchangeratepricingtobilling", 1) or 1

if pay_g_price:
pay_as_you_go = pay_g_price * usage_quantity * exchange_rate
aggregate_data.update({"PayAsYouGo": pay_as_you_go})
return aggregate_data

0 comments on commit 8df118c

Please sign in to comment.