Attempt period from line_items

This commit is contained in:
PCoder 2019-04-13 15:24:37 +02:00
parent 77669c962c
commit a3a2016cb4
2 changed files with 14 additions and 9 deletions

View file

@ -30,7 +30,9 @@
<tr>
<td class="xs-td-inline" data-header="{% trans 'VM ID' %}">{{ invoice.order.vm_id }}</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>
{% with line_items|get_value_from_dict:invoice.invoice_number as line_items_to_show %}
<td class="xs-td-inline" data-header="{% trans 'Period' %}">{{ line_items_to_show.period_start | date:'Y-m-d' }} &mdash; {{ line_items_to_show.period_end | date:'Y-m-d' }}</td>
{% endwith %}
<td class="xs-td-inline" data-header="{% trans 'Amount' %}">{{ invoice.total_in_chf|floatformat:2|intcomma }}</td>
<td class="text-right last-td">
<a class="btn btn-order-detail" href="{% url 'hosting:invoices' invoice.invoice_number %}">{% trans 'See Invoice' %}</a>

View file

@ -61,7 +61,7 @@ from .forms import (
from .mixins import ProcessVMSelectionMixin, HostingContextMixin
from .models import (
HostingOrder, HostingBill, HostingPlan, UserHostingKey, VMDetail,
GenericProduct, MonthlyHostingBill
GenericProduct, MonthlyHostingBill, HostingBillLineItem
)
logger = logging.getLogger(__name__)
@ -1179,21 +1179,24 @@ class InvoiceListView(LoginRequiredMixin, ListView):
except CustomUser.DoesNotExist as dne:
logger.debug("User does not exist")
cu = self.request.user
mabs = MonthlyHostingBill.objects.filter(customer__user=cu)
mhbs = MonthlyHostingBill.objects.filter(customer__user=cu)
else:
mabs = MonthlyHostingBill.objects.filter(
mhbs = MonthlyHostingBill.objects.filter(
customer__user=self.request.user
)
ips_dict = {}
for mab in mabs:
line_items_dict = {}
for mhb in mhbs:
try:
vm_detail = VMDetail.objects.get(vm_id=mab.order.vm_id)
ips_dict[mab.invoice_number] = [vm_detail.ipv6, vm_detail.ipv4]
vm_detail = VMDetail.objects.get(vm_id=mhb.order.vm_id)
ips_dict[mhb.invoice_number] = [vm_detail.ipv6, vm_detail.ipv4]
line_items_dict[mhb.invoice_number] = HostingBillLineItem.objects.filter(monthly_hosting_bill=mhb)
except VMDetail.DoesNotExist as dne:
ips_dict[mab.invoice_number] = ['--']
ips_dict[mhb.invoice_number] = ['--']
logger.debug("VMDetail for {} doesn't exist".format(
mab.order.vm_id
mhb.order.vm_id
))
context['line_items'] = line_items_dict
context['ips'] = ips_dict
return context