diff --git a/hosting/models.py b/hosting/models.py
index 0d42996e..d2011654 100644
--- a/hosting/models.py
+++ b/hosting/models.py
@@ -500,7 +500,8 @@ class HostingBillLineItem(AssignPermissionsMixin, models.Model):
:return:
"""
item_detail = ""
- if self.metadata is not None and len(self.metadata) > 0:
+ # metadata is a dict; a dict with nothing has two chars at least {}
+ if self.metadata is not None and len(self.metadata) > 2:
try:
vm_dict = json.loads(self.metadata)
item_detail = "VM ID: {}
".format(vm_dict["VM_ID"])
diff --git a/hosting/templates/hosting/invoices.html b/hosting/templates/hosting/invoices.html
index c0956a58..5f7be4b4 100644
--- a/hosting/templates/hosting/invoices.html
+++ b/hosting/templates/hosting/invoices.html
@@ -30,8 +30,8 @@
{{ invoice.order.vm_id }} |
{{ ips|get_value_from_dict:invoice.invoice_number|join:" " }} |
- {% with line_items|get_value_from_dict:invoice.invoice_number as line_items_to_show %}
- {{ period_start | date:'Y-m-d' }} — {{ period_end | date:'Y-m-d' }} |
+ {% with period|get_value_from_dict:invoice.invoice_number as period_to_show %}
+ {{ period_to_show.period_start | date:'Y-m-d' }} — {{ period_to_show.period_end | date:'Y-m-d' }} |
{% endwith %}
{{ invoice.total_in_chf|floatformat:2|intcomma }} |
diff --git a/hosting/views.py b/hosting/views.py
index 901dae20..92dd5aa8 100644
--- a/hosting/views.py
+++ b/hosting/views.py
@@ -1185,7 +1185,7 @@ class InvoiceListView(LoginRequiredMixin, ListView):
customer__user=self.request.user
)
ips_dict = {}
- line_items_dict = {}
+ line_item_period_dict = {}
for mhb in mhbs:
try:
vm_detail = VMDetail.objects.get(vm_id=mhb.order.vm_id)
@@ -1193,17 +1193,18 @@ class InvoiceListView(LoginRequiredMixin, ListView):
all_line_items = HostingBillLineItem.objects.filter(monthly_hosting_bill=mhb)
for line_item in all_line_items:
if line_item.get_item_detail_str() != "":
- context['period_start'] = line_item.period_start
- context['period_end'] = line_item.period_end
+ line_item_period_dict[mhb.invoice_number] = {
+ "period_start": line_item.period_start,
+ "period_end": line_item.period_end
+ }
break
- line_items_dict[mhb.invoice_number] = all_line_items
except VMDetail.DoesNotExist as dne:
ips_dict[mhb.invoice_number] = ['--']
logger.debug("VMDetail for {} doesn't exist".format(
mhb.order.vm_id
))
- context['line_items'] = line_items_dict
context['ips'] = ips_dict
+ context['period'] = line_item_period_dict
return context
def get_queryset(self):
|