Add latest refunds view

This commit is contained in:
Gabriel Augendre 2016-06-04 01:55:27 +02:00
parent c128e5b524
commit 27c599f0a9
No known key found for this signature in database
GPG key ID: D2B6A5B41FC438B1
5 changed files with 35 additions and 5 deletions

View file

@ -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)

View file

@ -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):

View 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 %}

View file

@ -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'),
]

View file

@ -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)