Browse Source

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
Fei Long Wang 3 months ago
parent
commit
3bcd260b27
2 changed files with 15 additions and 5 deletions
  1. 14
    4
      distil_ui/api/distil_v2.py
  2. 1
    1
      distil_ui/content/billing/templates/billing/index.html

+ 14
- 4
distil_ui/api/distil_v2.py View File

@@ -109,6 +109,7 @@ def _wash_details(current_details):
109 109
         else:
110 110
             washed_details.append(u)
111 111
 
112
+    total_free_router_network_cost = 0
112 113
     free_network_hours_left = free_hours
113 114
     for region, hours in six.iteritems(network_hours):
114 115
         free_network_hours = (hours if hours <= free_network_hours_left
@@ -116,13 +117,14 @@ def _wash_details(current_details):
116 117
         if not free_network_hours:
117 118
             break
118 119
         line_name = 'Free Network Tier in %s' % region
120
+        cost = round(free_network_hours * -rate_network, 2)
121
+        total_free_router_network_cost += cost
119 122
         washed_details.append({'product': region + '.n1.network',
120 123
                                'resource_name': line_name,
121 124
                                'quantity': free_network_hours,
122 125
                                'resource_id': '',
123 126
                                'unit': 'hour', 'rate': -rate_network,
124
-                               'cost': round(free_network_hours *
125
-                                             -rate_network, 2)})
127
+                               'cost': cost})
126 128
         free_network_hours_left -= free_network_hours
127 129
 
128 130
     free_router_hours_left = free_hours
@@ -132,13 +134,14 @@ def _wash_details(current_details):
132 134
         if not free_router_hours:
133 135
             break
134 136
         line_name = 'Free Router Tier in %s' % region
137
+        cost = round(free_router_hours * -rate_router, 2)
138
+        total_free_router_network_cost += cost
135 139
         washed_details.append({'product': region + '.n1.router',
136 140
                                'resource_name': line_name,
137 141
                                'quantity': free_router_hours,
138 142
                                'resource_id': '',
139 143
                                'unit': 'hour', 'rate': -rate_router,
140
-                               'cost': round(free_router_hours *
141
-                                             -rate_router, 2)})
144
+                               'cost': cost})
142 145
         free_router_hours_left -= free_router_hours
143 146
 
144 147
     region_count = 0
@@ -161,6 +164,13 @@ def _wash_details(current_details):
161 164
                        (region_count - 1) * (object_cost / region_count))
162 165
     current_details["total_cost"] = (current_details["total_cost"] -
163 166
                                      dup_object_cost)
167
+
168
+    # NOTE(flwang): Apply the free router and network to reflect correct cost.
169
+    # The total_free_router_network_cost is negative value.
170
+    current_details["total_cost"] += total_free_router_network_cost
171
+    current_details["total_cost"] = (current_details["total_cost"] if
172
+                                     current_details["total_cost"] > 0 else 0)
173
+
164 174
     return current_details
165 175
 
166 176
 

+ 1
- 1
distil_ui/content/billing/templates/billing/index.html View File

@@ -256,7 +256,7 @@
256 256
         } else {
257 257
              $("#credits_div").show();
258 258
             for(i=0;i<CREDITS["credits"].length;i++){
259
-                $("#credits_list").append('<li><i class="fa-li fa fa-credit-card"></i> Balance of ' + CREDITS["credits"][i].type + ' is $' + CREDITS["credits"][i].balance + ' will expired at ' + CREDITS["credits"][i].expiry_date + '</li>');
259
+                $("#credits_list").append('<li><i class="fa-li fa fa-credit-card"></i> Balance of ' + CREDITS["credits"][i].type + ' is $' + CREDITS["credits"][i].balance + '. This will expire on ' + CREDITS["credits"][i].expiry_date + '</li>');
260 260
             }
261 261
         }
262 262
     });

Loading…
Cancel
Save