Fix total amount computation for event comptability
This commit is contained in:
parent
af1b5826b6
commit
410f74802e
|
@ -3,7 +3,8 @@ import math
|
|||
import datetime
|
||||
from django import forms
|
||||
from .models import Transaction
|
||||
|
||||
from eventCompta.models import Event
|
||||
from django_select2.forms import Select2MultipleWidget, ModelSelect2Widget
|
||||
|
||||
class TransactionForm(forms.ModelForm):
|
||||
class Meta:
|
||||
|
@ -21,6 +22,7 @@ class TransactionForm(forms.ModelForm):
|
|||
"amount",
|
||||
"otherDescription",
|
||||
"account_number",
|
||||
"event",
|
||||
]
|
||||
|
||||
widgets = {
|
||||
|
@ -60,6 +62,11 @@ class TransactionForm(forms.ModelForm):
|
|||
"account_number": forms.TextInput(
|
||||
attrs={"class": "form-control", }
|
||||
),
|
||||
"event": ModelSelect2Widget(
|
||||
search_fields=["event_name__icontains"],
|
||||
max_results=10,
|
||||
attrs={"data-minimum-input-length": 0, "class": "form-control"},
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
|
|
BIN
src/db.sqlite3
BIN
src/db.sqlite3
Binary file not shown.
|
@ -8,6 +8,7 @@ class Event(models.Model):
|
|||
class Meta:
|
||||
verbose_name = "Evènement"
|
||||
verbose_name_plural = "Evènements"
|
||||
ordering = ['name', 'year']
|
||||
|
||||
name = models.CharField(max_length=255, verbose_name="Nom")
|
||||
year = models.IntegerField(verbose_name="Année")
|
||||
|
|
|
@ -8,6 +8,7 @@ from collections import OrderedDict
|
|||
from django.views.decorators.http import require_http_methods
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.urls import reverse
|
||||
import decimal
|
||||
|
||||
from .models import (
|
||||
# Transaction,
|
||||
|
@ -102,22 +103,29 @@ def event_details(request, event_id):
|
|||
transaction_type__transaction_type=0
|
||||
).aggregate(Sum("totalAmount"))["totalAmount__sum"]
|
||||
|
||||
if not isinstance(sum_recette, float):
|
||||
if not isinstance(sum_recette, decimal.Decimal):
|
||||
sum_recette = 0
|
||||
|
||||
if not isinstance(sum_depense, float):
|
||||
if not isinstance(sum_depense, decimal.Decimal):
|
||||
sum_depense = 0
|
||||
|
||||
total_simulated_amount = sum_recette - sum_depense
|
||||
|
||||
nonsimulated_sum_recette = event.transactions.filter(
|
||||
transaction_type__transaction_type=1, is_simulated=False
|
||||
).aggregate(Sum("totalAmount"))
|
||||
).aggregate(Sum("totalAmount"))["totalAmount__sum"]
|
||||
nonsimulated_sum_depense = event.transactions.filter(
|
||||
transaction_type__transaction_type=0, is_simulated=False
|
||||
).aggregate(Sum("totalAmount"))
|
||||
).aggregate(Sum("totalAmount"))["totalAmount__sum"]
|
||||
|
||||
if not isinstance(nonsimulated_sum_recette, decimal.Decimal):
|
||||
nonsimulated_sum_recette = 0
|
||||
|
||||
if not isinstance(nonsimulated_sum_depense, decimal.Decimal):
|
||||
nonsimulated_sum_depense = 0
|
||||
|
||||
total_amount = nonsimulated_sum_recette - nonsimulated_sum_depense
|
||||
|
||||
total_amount = 0
|
||||
previous_date = None
|
||||
date_sum = OrderedDict()
|
||||
previous_date_with_simulated = None
|
||||
|
@ -133,9 +141,10 @@ def event_details(request, event_id):
|
|||
|
||||
if len(date_sum) == len(date_sum_with_simulated):
|
||||
date_sum_with_simulated = None
|
||||
total_amount = total_simulated_amount
|
||||
# total_amount = total_simulated_amount
|
||||
else:
|
||||
total_amount = __compute_sum_amount(transaction_list)
|
||||
# total_amount = __compute_sum_amount(transaction_list)
|
||||
pass
|
||||
|
||||
context = {
|
||||
"event": event,
|
||||
|
@ -146,8 +155,8 @@ def event_details(request, event_id):
|
|||
"date_sum_simulated": date_sum_with_simulated,
|
||||
"sum_recette": sum_recette,
|
||||
"sum_depense": sum_depense,
|
||||
"nonsimulated_sum_recette": nonsimulated_sum_recette["totalAmount__sum"],
|
||||
"nonsimulated_sum_depense": nonsimulated_sum_depense["totalAmount__sum"],
|
||||
"nonsimulated_sum_recette": nonsimulated_sum_recette,
|
||||
"nonsimulated_sum_depense": nonsimulated_sum_depense,
|
||||
}
|
||||
|
||||
return render(request, "event/details.html", context)
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
{% if transaction.event %}
|
||||
<tr class="alert alert-danger">
|
||||
<td><p class="text-muted">Evènement</p></td>
|
||||
<td><p class="text-primary">{{ transaction.event }} (du {{ transaction.event.date_begin }} au {{ transaction.event.date_end }})</p></td>
|
||||
<td><p class="text-primary"><a href="{% url 'event_details' transaction.event.id %}">{{ transaction.event }} (du {{ transaction.event.date_begin }} au {{ transaction.event.date_end }})</a></p></td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if transaction.to_markdown %}
|
||||
|
|
|
@ -47,21 +47,21 @@
|
|||
<tfoot>
|
||||
<tr class="simulated">
|
||||
<td colspan="4" class="push-right"><b>Totaux simulés</b></td>
|
||||
<td class="push-right alert alert-success"><b>{{ sum_recette }}</b></td>
|
||||
<td class="push-right alert alert-danger"><b>-{{ sum_depense }}</b></td>
|
||||
<td class="push-right alert alert-success"><b>{{ sum_recette|floatformat:2 }}</b></td>
|
||||
<td class="push-right alert alert-danger"><b>-{{ sum_depense|floatformat:2 }}</b></td>
|
||||
</tr>
|
||||
<tr class="simulated">
|
||||
<td colspan="4" class="push-right"><b>Total simulé</b></td>
|
||||
<td class="centered alert alert-{% if total_simulated_Amount >= 0 %}success{% else %}danger{% endif %}" colspan="2"><b>{{ total_simulated_Amount }}</b></td>
|
||||
<td class="centered alert alert-{% if total_simulated_Amount >= 0 %}success{% else %}danger{% endif %}" colspan="2"><b>{{ total_simulated_Amount|floatformat:2 }}</b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="4" class="push-right"><b>Totaux non-simulés</b></td>
|
||||
<td class="push-right"><b>{{ nonsimulated_sum_recette }}</b></td>
|
||||
<td class="push-right"><b>-{{ nonsimulated_sum_dépense }}</b></td>
|
||||
<td class="push-right alert alert-success"><b>{{ nonsimulated_sum_recette|floatformat:2 }}</b></td>
|
||||
<td class="push-right alert alert-danger"><b>-{{ nonsimulated_sum_depense|floatformat:2 }}</b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="4" class="push-right"><b>Total</b></td>
|
||||
<td class="centered alert alert-{% if total_Amount >= 0 %}success{% else %}danger{% endif %}" colspan="2"><b>{{ total_Amount }}</b></td>
|
||||
<td class="centered alert alert-{% if total_Amount >= 0 %}success{% else %}danger{% endif %}" colspan="2"><b>{{ total_Amount|floatformat:2 }}</b></td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
|
|
Loading…
Reference in New Issue