diff --git a/gestion/templates/gestion/stats.html b/gestion/templates/gestion/stats.html
new file mode 100644
index 0000000..d40f393
--- /dev/null
+++ b/gestion/templates/gestion/stats.html
@@ -0,0 +1,146 @@
+{% extends 'base.html' %}
+{% block entete %}Stats{% endblock %}
+{% block navbar%}
+
+{% endblock %}
+{% block content %}
+
+
+
+
+
+
+ Champ |
+ Valeur |
+
+
+
+
+ Nombre d'adhérents |
+ {{adherents|length}} |
+
+
+ Nombre de comptes |
+ {{users.count}} |
+
+
+ Nombre de transactions |
+ {{transactions.count}} |
+
+
+ Somme des soldes positifs |
+ {{sum_positive_balance}} |
+
+
+ Somme des soldes positifs et négatifs |
+ {{sum_balance}} |
+
+
+ Nombre d'écoles |
+ {{schools.count}} |
+
+
+ Nombre de groupes |
+ {{groups.count}} |
+
+ {% for group in groups %}
+
+ Nombre dans le groupe {{group}} |
+ {{group.user_set.count}} |
+
+ {% endfor %}
+
+ Nombre d'admins |
+ {{admins.count}} |
+
+
+ Nombre de superusers |
+ {{superusers.count}} |
+
+
+ Nombre 8 |
+ 8 |
+
+
+
+
+
+
+
+ Stats produits et catégories
+
+
+
+
+
+ Champ |
+ Valeur |
+
+
+
+
+ Nombre de catégories |
+ {{categories.count}} |
+
+
+ Nombre de catégories affichées |
+ {{categories_shown.count}} |
+
+
+ Nombre de produits |
+ {{products.count}} |
+
+
+ Nombre de produits actifs |
+ {{active_products.count}} |
+
+
+ Nombre de fûts actifs |
+ {{active_kegs.count}} |
+
+
+ Nombre de menus |
+ {{menus.count}} |
+
+
+
+
+
+
+
+ Stats moyens de paiement et cotisations
+
+
+
+
+
+ Champ |
+ Valeur |
+
+
+
+
+ Nombre de moyens de paiement |
+ {{payment_methods.count}} |
+
+
+ Nombre de types de cotisations |
+ {{cotisations.count}} |
+
+ {% for cotisation in cotisations %}
+
+ Nombre de {{cotisation}} |
+ {{cotisation.cotisationhistory_set.count}} |
+
+ {% endfor %}
+
+
+
+
+{% endblock %}
diff --git a/gestion/urls.py b/gestion/urls.py
index 0b68c60..3e1cb1e 100644
--- a/gestion/urls.py
+++ b/gestion/urls.py
@@ -52,4 +52,5 @@ urlpatterns = [
path('categoryProfile/', views.categoryProfile, name="categoryProfile"),
path('categoriesList', views.categoriesList, name="categoriesList"),
path('categories-autocomplete', views.CategoriesAutocomplete.as_view(), name="categories-autocomplete"),
+ path('stats', views.stats, name="stats"),
]
\ No newline at end of file
diff --git a/gestion/views.py b/gestion/views.py
index 07a459f..93e42d1 100644
--- a/gestion/views.py
+++ b/gestion/views.py
@@ -2,7 +2,7 @@ from django.shortcuts import render, redirect, get_object_or_404
from django.contrib import messages
from django.urls import reverse
from django.http import HttpResponse, Http404
-from django.contrib.auth.models import User
+from django.contrib.auth.models import User, Group
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.decorators import login_required, permission_required
from django.utils import timezone
@@ -20,6 +20,7 @@ from decimal import *
from .forms import ReloadForm, RefundForm, ProductForm, KegForm, MenuForm, GestionForm, SearchMenuForm, SearchProductForm, SelectPositiveKegForm, SelectActiveKegForm, PinteForm, GenerateReleveForm, CategoryForm, SearchCategoryForm
from .models import Product, Menu, Keg, ConsumptionHistory, KegHistory, Consumption, MenuHistory, Pinte, Reload, Refund, Category
+from users.models import School
from preferences.models import PaymentMethod, GeneralPreferences, Cotisation
from users.models import CotisationHistory
@@ -955,4 +956,45 @@ class CategoriesAutocomplete(autocomplete.Select2QuerySetView):
qs = Category.objects.all()
if self.q:
qs = qs.filter(name__icontains=self.q)
- return qs
\ No newline at end of file
+ return qs
+
+@active_required
+@login_required
+@admin_required
+def stats(request):
+ users = User.objects.all()
+ adherents = [x for x in users if x.profile.is_adherent]
+ transactions = ConsumptionHistory.objects.all()
+ categories = Category.objects.all()
+ categories_shown = Category.objects.exclude(order=0)
+ products = Product.objects.all()
+ active_products = Product.objects.filter(is_active=True)
+ active_kegs = Keg.objects.filter(is_active=True)
+ sum_positive_balance = sum([x.profile.balance for x in users if x.profile.balance > 0])
+ sum_balance = sum([x.profile.balance for x in users])
+ schools = School.objects.all()
+ groups = Group.objects.all()
+ admins = User.objects.filter(is_staff=True)
+ superusers = User.objects.filter(is_superuser=True)
+ menus = Menu.objects.all()
+ payment_methods = PaymentMethod.objects.all()
+ cotisations = Cotisation.objects.all()
+ return render(request, "gestion/stats.html", {
+ "users": users,
+ "adherents": adherents,
+ "transactions": transactions,
+ "categories": categories,
+ "categories_shown": categories_shown,
+ "products": products,
+ "active_products": active_products,
+ "active_kegs": active_kegs,
+ "sum_positive_balance": sum_positive_balance,
+ "sum_balance": sum_balance,
+ "schools": schools,
+ "groups": groups,
+ "admins": admins,
+ "superusers": superusers,
+ "menus": menus,
+ "payment_methods": payment_methods,
+ "cotisations": cotisations,
+ })
\ No newline at end of file
diff --git a/templates/nav.html b/templates/nav.html
index 0c636e5..db0e34d 100644
--- a/templates/nav.html
+++ b/templates/nav.html
@@ -30,6 +30,9 @@
{% endif %}
{% if request.user.is_staff %}
+
+ Stats
+
Comptabilité