Show invoices only if the user's invoice were imported

Else fallback to orders url as before
This commit is contained in:
PCoder 2019-04-04 07:55:53 +02:00
parent 316646465d
commit 8dfee2bd83
2 changed files with 9 additions and 1 deletions

View file

@ -26,7 +26,7 @@
<img class="svg-img" src="{% static 'hosting/img/key.svg' %}"> <img class="svg-img" src="{% static 'hosting/img/key.svg' %}">
</div> </div>
</a> </a>
<a href="{% url 'hosting:invoices' %}" class="hosting-dashboard-item"> <a href="{% if has_invoices %}{% url 'hosting:invoices' %}{% else %}{% url 'hosting:orders' %}{% endif %}" class="hosting-dashboard-item">
<h2>{% trans "My Bills" %}</h2> <h2>{% trans "My Bills" %}</h2>
<div class="hosting-dashboard-image"> <div class="hosting-dashboard-image">
<img class="svg-img" src="{% static 'hosting/img/billing.svg' %}"> <img class="svg-img" src="{% static 'hosting/img/billing.svg' %}">

View file

@ -83,6 +83,14 @@ class DashboardView(LoginRequiredMixin, View):
@method_decorator(decorators) @method_decorator(decorators)
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
context = self.get_context_data() context = self.get_context_data()
try:
MonthlyHostingBill.objects.get(email=self.request.user.email)
context['has_invoices'] = True
except MonthlyHostingBill.DoesNotExist as dne:
logger.error("{}'s monthly hosting bill not imported ?".format(
self.request.user.email
))
context['has_invoices'] = False
return render(request, self.template_name, context) return render(request, self.template_name, context)