Add latest refunds view
This commit is contained in:
parent
c128e5b524
commit
27c599f0a9
5 changed files with 35 additions and 5 deletions
|
@ -10,7 +10,7 @@ class RefundAdmin(admin.ModelAdmin):
|
|||
search_fields = ('title',)
|
||||
date_hierarchy = 'date'
|
||||
form = RefundForm
|
||||
readonly_fields = ('amount',)
|
||||
readonly_fields = ('eur_value',)
|
||||
|
||||
|
||||
@admin.register(Payment)
|
||||
|
|
|
@ -15,11 +15,11 @@ class Refund(models.Model):
|
|||
on_delete=models.PROTECT
|
||||
)
|
||||
|
||||
def amount(self) -> float:
|
||||
def eur_value(self) -> float:
|
||||
return self.payment_set.all().aggregate(Sum('value')).get('value__sum') / 100
|
||||
|
||||
def __str__(self) -> str:
|
||||
return "{0} on {1} for {2}".format(self.title, self.date, self.amount())
|
||||
return "{0} on {1} for {2}".format(self.title, self.date, self.eur_value())
|
||||
|
||||
|
||||
class Payment(models.Model):
|
||||
|
|
19
refunding/templates/refunding/refunds_list.html
Normal file
19
refunding/templates/refunding/refunds_list.html
Normal file
|
@ -0,0 +1,19 @@
|
|||
{% extends 'base.html' %}
|
||||
{% load l10n %}
|
||||
|
||||
{% block content %}
|
||||
<h1>{% block title %}Latest refunds{% endblock %}</h1>
|
||||
{% if refunds %}
|
||||
<div class="list-group">
|
||||
{% for refund in refunds %}
|
||||
<div class="list-group-item">
|
||||
{{ refund.title }} le {{ refund.date|date:"SHORT_DATE_FORMAT" }} : {{ payment.amount }}€
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<p>
|
||||
{% firstof default_nothing "Nothing here..." %}
|
||||
</p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
|
@ -1,6 +1,7 @@
|
|||
from django.conf.urls import url
|
||||
from refunding.views import not_refunded_payments
|
||||
from refunding.views import not_refunded_payments, latest_refunds
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^payments/$', not_refunded_payments, name='not_refunded_payments'),
|
||||
url(r'^refunds/$', latest_refunds, name='latest_refunds'),
|
||||
]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from django.contrib.auth.decorators import login_required
|
||||
from django.db.models import Sum
|
||||
from django.shortcuts import render
|
||||
from refunding.models import Payment
|
||||
from refunding.models import Payment, Refund
|
||||
|
||||
|
||||
@login_required
|
||||
|
@ -14,3 +14,13 @@ def not_refunded_payments(request):
|
|||
'default_nothing': 'No payment to be refunded.'
|
||||
}
|
||||
return render(request, "refunding/payments_list.html", context)
|
||||
|
||||
|
||||
@login_required
|
||||
def latest_refunds(request):
|
||||
refunds = Refund.objects.all().order_by('date')[:20]
|
||||
context = {
|
||||
'refunds': refunds,
|
||||
'default_nothing': 'No refund to show.'
|
||||
}
|
||||
return render(request, "refunding/refunds_list.html", context)
|
||||
|
|
Loading…
Reference in a new issue