From a3a2016cb49e7f8f67001a82c70894e364f438c9 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 13 Apr 2019 15:24:37 +0200 Subject: [PATCH] Attempt period from line_items --- hosting/templates/hosting/invoices.html | 4 +++- hosting/views.py | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/hosting/templates/hosting/invoices.html b/hosting/templates/hosting/invoices.html index eaf5d22d..8eb3d02c 100644 --- a/hosting/templates/hosting/invoices.html +++ b/hosting/templates/hosting/invoices.html @@ -30,7 +30,9 @@ {{ invoice.order.vm_id }} {{ ips|get_value_from_dict:invoice.invoice_number|join:"
" }} - {{ invoice.period_start | date:'Y-m-d' }} — {{ invoice.period_end | date:'Y-m-d' }} + {% with line_items|get_value_from_dict:invoice.invoice_number as line_items_to_show %} + {{ line_items_to_show.period_start | date:'Y-m-d' }} — {{ line_items_to_show.period_end | date:'Y-m-d' }} + {% endwith %} {{ invoice.total_in_chf|floatformat:2|intcomma }} {% trans 'See Invoice' %} diff --git a/hosting/views.py b/hosting/views.py index 5e80a39a..45230d1c 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -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