Retrieve user bills.

This commit is contained in:
Santiago Lamora 2019-12-17 14:48:21 +01:00
parent 770c6c9c9b
commit 186d20ec20
4 changed files with 29 additions and 25 deletions

View File

@ -27,6 +27,7 @@ API_PATHS = {
'saas-list': 'saas/', 'saas-list': 'saas/',
# other # other
'bill-list': 'bills/',
'payment-source-list': 'payment-sources/', 'payment-source-list': 'payment-sources/',
} }

View File

@ -48,6 +48,25 @@ class OrchestraModel:
return '%s object (%s)' % (self.__class__.__name__, self.id) 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): class BillingContact(OrchestraModel):
param_defaults = { param_defaults = {
'name': None, 'name': None,

View File

@ -1,5 +1,5 @@
{% extends "musician/base.html" %} {% extends "musician/base.html" %}
{% load i18n %} {% load i18n l10n %}
{% block content %} {% block content %}
@ -13,7 +13,6 @@
<col span="1" style="width: 40%;"> <col span="1" style="width: 40%;">
<col span="1" style="width: 10%;"> <col span="1" style="width: 10%;">
<col span="1" style="width: 10%;"> <col span="1" style="width: 10%;">
<col span="1" style="width: 10%;">
</colgroup> </colgroup>
<thead class="thead-dark"> <thead class="thead-dark">
<tr> <tr>
@ -21,7 +20,6 @@
<th scope="col">Bill date</th> <th scope="col">Bill date</th>
<th scope="col">Type</th> <th scope="col">Type</th>
<th scope="col">Total</th> <th scope="col">Total</th>
<th scope="col">Status</th>
<th scope="col">Download PDF</th> <th scope="col">Download PDF</th>
</tr> </tr>
</thead> </thead>
@ -29,10 +27,9 @@
{% for bill in object_list %} {% for bill in object_list %}
<tr> <tr>
<th scope="row">{{ bill.number }}</th> <th scope="row">{{ bill.number }}</th>
<td>{{ bill.date|date:"SHORT_DATE_FORMAT" }}</td> <td>{{ bill.created_on }}</td>
<td>{{ bill.type }}</td> <td>{{ bill.type }}</td>
<td>{{ bill.total_amount }}</td> <td>{{ bill.total|floatformat:2|localize }}€</td>
<td class="font-weight-bold">{{ bill.status }}</td>
<td><a class="text-dark" href="{{ bill.pdf_url }}" target="_blank" rel="noopener noreferrer"><i class="fas fa-file-pdf"></i></a></td> <td><a class="text-dark" href="{{ bill.pdf_url }}" target="_blank" rel="noopener noreferrer"><i class="fas fa-file-pdf"></i></a></td>
</tr> </tr>
{% endfor %} {% endfor %}

View File

@ -17,7 +17,7 @@ from .auth import logout as auth_logout
from .forms import LoginForm from .forms import LoginForm
from .mixins import (CustomContextMixin, ExtendedPaginationMixin, from .mixins import (CustomContextMixin, ExtendedPaginationMixin,
UserTokenRequiredMixin) UserTokenRequiredMixin)
from .models import (DatabaseService, MailinglistService, MailService, from .models import (Bill, DatabaseService, MailinglistService, MailService,
PaymentSource, SaasService, UserAccount) PaymentSource, SaasService, UserAccount)
from .settings import ALLOWED_RESOURCES from .settings import ALLOWED_RESOURCES
@ -82,24 +82,6 @@ class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView):
return context 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): class ProfileView(CustomContextMixin, UserTokenRequiredMixin, TemplateView):
template_name = "musician/profile.html" template_name = "musician/profile.html"
@ -146,6 +128,11 @@ class ServiceListView(CustomContextMixin, ExtendedPaginationMixin, UserTokenRequ
return context return context
class BillingView(ServiceListView):
service_class = Bill
template_name = "musician/billing.html"
class MailView(ServiceListView): class MailView(ServiceListView):
service_class = MailService service_class = MailService
template_name = "musician/mail.html" template_name = "musician/mail.html"