From c3842a5ed50c74125de1df52dc1f6883471c4d54 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 13 Apr 2019 15:43:27 +0200 Subject: [PATCH] Get periods from line items in invoice detail also --- hosting/models.py | 22 ++++++++++++++++++++++ hosting/views.py | 6 +++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/hosting/models.py b/hosting/models.py index e20a7725..550cf27f 100644 --- a/hosting/models.py +++ b/hosting/models.py @@ -391,6 +391,28 @@ class MonthlyHostingBill(AssignPermissionsMixin, models.Model): logger.debug("VM_IDS=".format(','.join(vm_ids))) return return_value + def get_period_start(self): + """ + Return the period start of the invoice for the line items + :return: + """ + items = HostingBillLineItem.objects.filter(monthly_hosting_bill=self) + if len(items) > 0: + return items[0].period_start + else: + return self.period_start + + def get_period_end(self): + """ + Return the period end of the invoice for the line items + :return: + """ + items = HostingBillLineItem.objects.filter(monthly_hosting_bill=self) + if len(items) > 0: + return items[0].period_end + else: + return self.period_end + class HostingBillLineItem(AssignPermissionsMixin, models.Model): """ diff --git a/hosting/views.py b/hosting/views.py index 45230d1c..fe13ff21 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -1230,7 +1230,7 @@ class InvoiceDetailView(LoginRequiredMixin, DetailView): context_object_name = "invoice" login_url = reverse_lazy('hosting:login') permission_required = ['view_monthlyhostingbill'] - model = MonthlyHostingBill + # model = MonthlyHostingBill def get_object(self, queryset=None): invoice_id = self.kwargs.get('invoice_id') @@ -1316,8 +1316,8 @@ class InvoiceDetailView(LoginRequiredMixin, DetailView): return context # add context params from monthly hosting bill - context['period_start'] = obj.period_start - context['period_end'] = obj.period_end + context['period_start'] = obj.get_period_start() + context['period_end'] = obj.get_period_end() context['paid_at'] = obj.paid_at context['total_in_chf'] = obj.total_in_chf() context['invoice_number'] = obj.invoice_number