Attempt to show IP address instead of invoice number

This commit is contained in:
PCoder 2019-04-04 23:14:24 +02:00
parent 6d4af0c193
commit 73f7831744
2 changed files with 20 additions and 2 deletions

View file

@ -18,7 +18,7 @@
<table class="table table-switch"> <table class="table table-switch">
<thead> <thead>
<tr> <tr>
<th>{% trans "Invoice Nr." %}</th> <th>{% trans "IP Address" %}</th>
<th>{% trans "Period" %}</th> <th>{% trans "Period" %}</th>
<th>{% trans "Date" %}</th> <th>{% trans "Date" %}</th>
<th>{% trans "Amount" %}</th> <th>{% trans "Amount" %}</th>
@ -28,7 +28,7 @@
<tbody> <tbody>
{% for invoice in invoices %} {% for invoice in invoices %}
<tr> <tr>
<td class="xs-td-inline" data-header="{% trans 'Invoice Nr.' %}">{{ invoice.invoice_number }}</td> <td class="xs-td-inline" data-header="{% trans 'IP Address' %}">{{ ips|get_value_from_dict:invoice.invoice_number|join:"<br/>" }}</td>
<td class="xs-td-inline" data-header="{% trans 'Period' %}">{{ invoice.period_start | date:'Y-m-d' }} &mdash; {{ invoice.period_end | date:'Y-m-d' }}</td> <td class="xs-td-inline" data-header="{% trans 'Period' %}">{{ invoice.period_start | date:'Y-m-d' }} &mdash; {{ invoice.period_end | date:'Y-m-d' }}</td>
<td class="xs-td-bighalf locale_date" data-header="{% trans 'Date' %}">{{ invoice.paid_at | date:'Y-m-d h:i a' }}</td> <td class="xs-td-bighalf locale_date" data-header="{% trans 'Date' %}">{{ invoice.paid_at | date:'Y-m-d h:i a' }}</td>
<td class="xs-td-smallhalf" data-header="{% trans 'Amount' %}">{{ invoice.total_in_chf|floatformat:2|intcomma }}</td> <td class="xs-td-smallhalf" data-header="{% trans 'Amount' %}">{{ invoice.total_in_chf|floatformat:2|intcomma }}</td>

View file

@ -1164,6 +1164,24 @@ class InvoiceListView(LoginRequiredMixin, ListView):
model = MonthlyHostingBill model = MonthlyHostingBill
ordering = '-created' 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): def get_queryset(self):
user = self.request.user user = self.request.user
self.queryset = MonthlyHostingBill.objects.filter(customer__user=user) self.queryset = MonthlyHostingBill.objects.filter(customer__user=user)