From 186d20ec20cdd157ee0035053a97eb7581783cb7 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Tue, 17 Dec 2019 14:48:21 +0100 Subject: [PATCH] Retrieve user bills. --- musician/api.py | 1 + musician/models.py | 19 ++++++++++++++++++ musician/templates/musician/billing.html | 9 +++------ musician/views.py | 25 ++++++------------------ 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/musician/api.py b/musician/api.py index 4df4943..78964bd 100644 --- a/musician/api.py +++ b/musician/api.py @@ -27,6 +27,7 @@ API_PATHS = { 'saas-list': 'saas/', # other + 'bill-list': 'bills/', 'payment-source-list': 'payment-sources/', } diff --git a/musician/models.py b/musician/models.py index 477a371..b0faab8 100644 --- a/musician/models.py +++ b/musician/models.py @@ -48,6 +48,25 @@ class OrchestraModel: return '%s object (%s)' % (self.__class__.__name__, self.id) +class Bill(OrchestraModel): + api_name = 'bill' + param_defaults = { + "number": "1", + "type": "INVOICE", + "total": 0.0, + "is_sent": False, + "created_on": "", + "due_on": "", + "comments": "", + } + + def pdf_url(self): + # TODO (@slamora) create a view that exposes & downloads backend PDF + import urllib.parse + bill_url = self._json.get('url') + return urllib.parse.urljoin(bill_url, 'document/') + + class BillingContact(OrchestraModel): param_defaults = { 'name': None, diff --git a/musician/templates/musician/billing.html b/musician/templates/musician/billing.html index f99d816..c374dc0 100644 --- a/musician/templates/musician/billing.html +++ b/musician/templates/musician/billing.html @@ -1,5 +1,5 @@ {% extends "musician/base.html" %} -{% load i18n %} +{% load i18n l10n %} {% block content %} @@ -13,7 +13,6 @@ - @@ -21,7 +20,6 @@ Bill date Type Total - Status Download PDF @@ -29,10 +27,9 @@ {% for bill in object_list %} {{ bill.number }} - {{ bill.date|date:"SHORT_DATE_FORMAT" }} + {{ bill.created_on }} {{ bill.type }} - {{ bill.total_amount }} - {{ bill.status }} + {{ bill.total|floatformat:2|localize }}€ {% endfor %} diff --git a/musician/views.py b/musician/views.py index 51a5013..b0271b1 100644 --- a/musician/views.py +++ b/musician/views.py @@ -17,7 +17,7 @@ from .auth import logout as auth_logout from .forms import LoginForm from .mixins import (CustomContextMixin, ExtendedPaginationMixin, UserTokenRequiredMixin) -from .models import (DatabaseService, MailinglistService, MailService, +from .models import (Bill, DatabaseService, MailinglistService, MailService, PaymentSource, SaasService, UserAccount) from .settings import ALLOWED_RESOURCES @@ -82,24 +82,6 @@ class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): return context -class BillingView(CustomContextMixin, ExtendedPaginationMixin, UserTokenRequiredMixin, ListView): - template_name = "musician/billing.html" - - def get_queryset(self): - # TODO (@slamora) retrieve user bills - from django.utils import timezone - return [ - { - 'number': 24, - 'date': timezone.now(), - 'type': 'subscription', - 'total_amount': '25,00 €', - 'status': 'paid', - 'pdf_url': 'https://example.org/bill.pdf' - }, - ] - - class ProfileView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): template_name = "musician/profile.html" @@ -146,6 +128,11 @@ class ServiceListView(CustomContextMixin, ExtendedPaginationMixin, UserTokenRequ return context +class BillingView(ServiceListView): + service_class = Bill + template_name = "musician/billing.html" + + class MailView(ServiceListView): service_class = MailService template_name = "musician/mail.html"