Display the monthly expense in already refunded.
This commit is contained in:
parent
81c954e662
commit
bdb5582352
2 changed files with 17 additions and 1 deletions
|
@ -1,7 +1,7 @@
|
||||||
{% if elements %}
|
{% if elements %}
|
||||||
{% if sum %}
|
{% if sum %}
|
||||||
<p>
|
<p>
|
||||||
Total : {{ sum|floatformat:-2 }}€
|
Total : {{ sum|floatformat:-2 }}€{% if refunded %} (soit {{ monthly|floatformat:-2 }}€ par mois){% endif %}
|
||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="list-group">
|
<div class="list-group">
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import calendar
|
||||||
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth.decorators import login_required, permission_required
|
from django.contrib.auth.decorators import login_required, permission_required
|
||||||
from django.db.models import Sum
|
from django.db.models import Sum
|
||||||
|
@ -174,9 +176,23 @@ def already_refunded_payments(request):
|
||||||
else:
|
else:
|
||||||
value_sum = 0
|
value_sum = 0
|
||||||
|
|
||||||
|
start_date = refunded.last().date
|
||||||
|
start_date = start_date.replace(day=1)
|
||||||
|
|
||||||
|
end_date = refunded.first().date
|
||||||
|
month = end_date.month
|
||||||
|
year = end_date.year + month // 12
|
||||||
|
month = month % 12 + 1
|
||||||
|
end_date = end_date.replace(year=year, month=month, day=1)
|
||||||
|
|
||||||
|
diff = (end_date.year - start_date.year) * 12 + end_date.month - start_date.month
|
||||||
|
|
||||||
|
monthly = value_sum / diff
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
'refunded': refunded,
|
'refunded': refunded,
|
||||||
'sum': value_sum,
|
'sum': value_sum,
|
||||||
|
'monthly': monthly,
|
||||||
'default_nothing': 'Aucun paiement remboursé :)'
|
'default_nothing': 'Aucun paiement remboursé :)'
|
||||||
}
|
}
|
||||||
return render(request, "refunding/refunded_payments.html", context)
|
return render(request, "refunding/refunded_payments.html", context)
|
||||||
|
|
Loading…
Reference in a new issue