From 3bcd260b27bc2ecae8ddc813244d8f5973bb9531 Mon Sep 17 00:00:00 2001 From: Fei Long Wang Date: Wed, 9 Jan 2019 12:24:08 +1300 Subject: [PATCH] Include free router and network credit into total cost Two small fix including in this patch: 1. Including the free router and free network into the current month quotation. 2. Fix small typo Change-Id: I0e2e1ae321687211ee79c304e9a2ade709441a4c --- distil_ui/api/distil_v2.py | 18 ++++++++++++++---- .../billing/templates/billing/index.html | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/distil_ui/api/distil_v2.py b/distil_ui/api/distil_v2.py index dc9b05d..0d94b30 100644 --- a/distil_ui/api/distil_v2.py +++ b/distil_ui/api/distil_v2.py @@ -109,6 +109,7 @@ def _wash_details(current_details): else: washed_details.append(u) + total_free_router_network_cost = 0 free_network_hours_left = free_hours for region, hours in six.iteritems(network_hours): free_network_hours = (hours if hours <= free_network_hours_left @@ -116,13 +117,14 @@ def _wash_details(current_details): if not free_network_hours: break line_name = 'Free Network Tier in %s' % region + cost = round(free_network_hours * -rate_network, 2) + total_free_router_network_cost += cost washed_details.append({'product': region + '.n1.network', 'resource_name': line_name, 'quantity': free_network_hours, 'resource_id': '', 'unit': 'hour', 'rate': -rate_network, - 'cost': round(free_network_hours * - -rate_network, 2)}) + 'cost': cost}) free_network_hours_left -= free_network_hours free_router_hours_left = free_hours @@ -132,13 +134,14 @@ def _wash_details(current_details): if not free_router_hours: break line_name = 'Free Router Tier in %s' % region + cost = round(free_router_hours * -rate_router, 2) + total_free_router_network_cost += cost washed_details.append({'product': region + '.n1.router', 'resource_name': line_name, 'quantity': free_router_hours, 'resource_id': '', 'unit': 'hour', 'rate': -rate_router, - 'cost': round(free_router_hours * - -rate_router, 2)}) + 'cost': cost}) free_router_hours_left -= free_router_hours region_count = 0 @@ -161,6 +164,13 @@ def _wash_details(current_details): (region_count - 1) * (object_cost / region_count)) current_details["total_cost"] = (current_details["total_cost"] - dup_object_cost) + + # NOTE(flwang): Apply the free router and network to reflect correct cost. + # The total_free_router_network_cost is negative value. + current_details["total_cost"] += total_free_router_network_cost + current_details["total_cost"] = (current_details["total_cost"] if + current_details["total_cost"] > 0 else 0) + return current_details diff --git a/distil_ui/content/billing/templates/billing/index.html b/distil_ui/content/billing/templates/billing/index.html index 97498ae..8a05c55 100644 --- a/distil_ui/content/billing/templates/billing/index.html +++ b/distil_ui/content/billing/templates/billing/index.html @@ -256,7 +256,7 @@ } else { $("#credits_div").show(); for(i=0;i Balance of ' + CREDITS["credits"][i].type + ' is $' + CREDITS["credits"][i].balance + ' will expired at ' + CREDITS["credits"][i].expiry_date + ''); + $("#credits_list").append('
  • Balance of ' + CREDITS["credits"][i].type + ' is $' + CREDITS["credits"][i].balance + '. This will expire on ' + CREDITS["credits"][i].expiry_date + '
  • '); } } });