From 73f783174495727bfd3cc1bd9b00a4e5f1fe8c4e Mon Sep 17 00:00:00 2001 From: PCoder Date: Thu, 4 Apr 2019 23:14:24 +0200 Subject: [PATCH] Attempt to show IP address instead of invoice number --- hosting/templates/hosting/invoices.html | 4 ++-- hosting/views.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/hosting/templates/hosting/invoices.html b/hosting/templates/hosting/invoices.html index 073eb750..67159e54 100644 --- a/hosting/templates/hosting/invoices.html +++ b/hosting/templates/hosting/invoices.html @@ -18,7 +18,7 @@ - + @@ -28,7 +28,7 @@ {% for invoice in invoices %} - + diff --git a/hosting/views.py b/hosting/views.py index b3b5c1f8..75f273ed 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -1164,6 +1164,24 @@ class InvoiceListView(LoginRequiredMixin, ListView): model = MonthlyHostingBill ordering = '-created' + def get_context_data(self, **kwargs): + context = super(InvoiceListView, self).get_context_data(**kwargs) + mabs = MonthlyHostingBill.objects.filter( + customer__user=self.request.user + ) + ips_dict = {} + for mab in mabs: + try: + vm_detail = VMDetail.get(vm_id=mab.order.vm_id) + ips_dict[mab.invoice_number] = [vm_detail.ipv6, vm_detail.ipv4] + except VMDetail.DoesNotExist as dne: + ips_dict[mab.invoice_number] = ['--'] + logger.debug("VMDetail for {} doesn't exist".format( + mab.order.vm_id + )) + context['ips'] = ips_dict + return context + def get_queryset(self): user = self.request.user self.queryset = MonthlyHostingBill.objects.filter(customer__user=user)
{% trans "Invoice Nr." %}{% trans "IP Address" %} {% trans "Period" %} {% trans "Date" %} {% trans "Amount" %}
{{ invoice.invoice_number }}{{ ips|get_value_from_dict:invoice.invoice_number|join:"
" }}
{{ invoice.period_start | date:'Y-m-d' }} — {{ invoice.period_end | date:'Y-m-d' }} {{ invoice.paid_at | date:'Y-m-d h:i a' }} {{ invoice.total_in_chf|floatformat:2|intcomma }}