diff --git a/usage_function/pyproject.toml b/usage_function/pyproject.toml index 2e446f5..bddcbf9 100644 --- a/usage_function/pyproject.toml +++ b/usage_function/pyproject.toml @@ -6,8 +6,8 @@ authors = [] packages = [ {include = "usage"}, {include = "utils"}, -# {include = "costmanagement"}, {include = "monthly_usage"}, + # {include = "costmanagement"}, ] [tool.poetry.dependencies] diff --git a/usage_function/utils/usage.py b/usage_function/utils/usage.py index 415a8c8..4732623 100644 --- a/usage_function/utils/usage.py +++ b/usage_function/utils/usage.py @@ -108,9 +108,8 @@ def retrieve_usage(usage_data): else: usage_item.amortised_cost = 0.0 - if usage_item.id in all_items: - existing_item = all_items[usage_item.id] - # Add to the existing item + if existing_item := all_items.get(usage_item.id): + # Update the existing item existing_item.quantity += usage_item.quantity existing_item.effective_price += usage_item.effective_price existing_item.cost += usage_item.cost @@ -118,9 +117,6 @@ def retrieve_usage(usage_data): existing_item.total_cost += usage_item.total_cost existing_item.unit_price += usage_item.unit_price - # Update the dict entry - all_items[usage_item.id] = existing_item - else: all_items[usage_item.id] = usage_item @@ -132,7 +128,7 @@ def retrieve_usage(usage_data): datetime.now() - started_processing_at, ) - return list(all_items.values()) + return all_item_list def retrieve_and_send_usage(hostname_or_ip, usage_data):