From 6f08a0e7da728afc264b2fc92614c8f0f7f8a8a4 Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 16 Apr 2019 00:15:37 +0200 Subject: [PATCH] Redirect users to invoice instead of orders --- .../templates/hosting/virtual_machine_detail.html | 2 +- hosting/views.py | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/hosting/templates/hosting/virtual_machine_detail.html b/hosting/templates/hosting/virtual_machine_detail.html index ce02036f..52fff9d6 100644 --- a/hosting/templates/hosting/virtual_machine_detail.html +++ b/hosting/templates/hosting/virtual_machine_detail.html @@ -46,7 +46,7 @@
{% trans "Current Pricing" %}
{{order.price|floatformat:2|intcomma}} CHF/{% trans "Month" %}
- {% trans "See Invoice" %} + {% trans "See Invoice" %}
diff --git a/hosting/views.py b/hosting/views.py index da139f0b..fa2f177e 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -1570,8 +1570,21 @@ class VirtualMachineView(LoginRequiredMixin, View): 'virtual_machine': serializer.data, 'order': HostingOrder.objects.get( vm_id=serializer.data['vm_id'] - ) + ), + 'has_invoices': False } + try: + bills = [] + if hasattr(self.request.user, 'stripecustomer'): + bills = MonthlyHostingBill.objects.filter( + customer=self.request.user.stripecustomer + ) + if len(bills) > 0: + context['has_invoices'] = True + except MonthlyHostingBill.DoesNotExist as dne: + logger.error("{}'s monthly hosting bill not imported ?".format( + self.request.user.email + )) except Exception as ex: logger.debug("Exception generated {}".format(str(ex))) messages.error(self.request,