From 84e2a529c6f32adf0936d3c631a0d0ef1e8a022c Mon Sep 17 00:00:00 2001 From: Nanoy Date: Wed, 27 Feb 2019 08:59:41 +0100 Subject: [PATCH] Admin --- gestion/admin.py | 69 +++++- gestion/migrations/0006_auto_20190227_0859.py | 165 +++++++++++++++ gestion/models.py | 40 ++-- preferences/admin.py | 19 +- .../migrations/0009_auto_20190227_0859.py | 199 ++++++++++++++++++ preferences/models.py | 42 ++-- users/admin.py | 42 +++- users/migrations/0005_auto_20190227_0859.py | 84 ++++++++ users/models.py | 17 +- 9 files changed, 617 insertions(+), 60 deletions(-) create mode 100644 gestion/migrations/0006_auto_20190227_0859.py create mode 100644 preferences/migrations/0009_auto_20190227_0859.py create mode 100644 users/migrations/0005_auto_20190227_0859.py diff --git a/gestion/admin.py b/gestion/admin.py index 253981b..67fafef 100644 --- a/gestion/admin.py +++ b/gestion/admin.py @@ -3,12 +3,63 @@ from simple_history.admin import SimpleHistoryAdmin from .models import Reload, Refund, Product, Keg, ConsumptionHistory, KegHistory, Consumption, Menu, MenuHistory -admin.site.register(Reload, SimpleHistoryAdmin) -admin.site.register(Refund, SimpleHistoryAdmin) -admin.site.register(Product, SimpleHistoryAdmin) -admin.site.register(Keg, SimpleHistoryAdmin) -admin.site.register(ConsumptionHistory, SimpleHistoryAdmin) -admin.site.register(KegHistory, SimpleHistoryAdmin) -admin.site.register(Consumption, SimpleHistoryAdmin) -admin.site.register(Menu, SimpleHistoryAdmin) -admin.site.register(MenuHistory, SimpleHistoryAdmin) \ No newline at end of file +class ConsumptionAdmin(SimpleHistoryAdmin): + list_display = ('customer', 'product', 'quantity') + ordering = ('-quantity', ) + search_fields = ('customer', 'product') + +class ConsumptionHistoryAdmin(SimpleHistoryAdmin): + list_display = ('customer', 'product', 'quantity', 'paymentMethod', 'date', 'amount') + ordering = ('-date', ) + search_fields = ('customer', 'product') + list_filter = ('paymentMethod',) + +class KegAdmin(SimpleHistoryAdmin): + list_display = ('name', 'stockHold', 'capacity', 'is_active') + ordering = ('name', ) + search_fields = ('name',) + list_filter = ('capacity', 'is_active') + +class KegHistoryAdmin(SimpleHistoryAdmin): + list_display = ('keg', 'openingDate', 'closingDate', 'isCurrentKegHistory', 'quantitySold') + ordering = ('-openingDate', 'quantitySold') + search_fields = ('keg',) + list_filter = ('isCurrentKegHistory', 'keg') + +class MenuHistoryAdmin(SimpleHistoryAdmin): + list_display = ('customer', 'menu', 'paymentMethod', 'date', 'quantity', 'amount') + ordering = ('-date',) + search_fields = ('customer', 'menu') + +class MenuAdmin(SimpleHistoryAdmin): + list_display = ('name', 'amount', 'is_active') + ordering = ('name', 'amount') + search_fields = ('name',) + list_filter = ('is_active', ) + +class ProductAdmin(SimpleHistoryAdmin): + list_display = ('name', 'amount', 'is_active', 'category', 'adherentRequired', 'stockHold', 'stockBar', 'volume', 'deg') + ordering = ('name', 'amount', 'stockHold', 'stockBar', 'deg') + search_fields = ('name',) + list_filter = ('is_active', 'adherentRequired', 'category') + +class ReloadAdmin(SimpleHistoryAdmin): + list_display = ('customer', 'amount', 'date', 'PaymentMethod') + ordering = ('-date', 'amount', 'customer') + search_fields = ('customer',) + list_filter = ('PaymentMethod', ) + +class RefundAdmin(SimpleHistoryAdmin): + list_display = ('customer', 'amount', 'date') + ordering = ('-date', 'amount', 'customer') + search_fields = ('customer',) + +admin.site.register(Reload, ReloadAdmin) +admin.site.register(Refund, RefundAdmin) +admin.site.register(Product, ProductAdmin) +admin.site.register(Keg, KegAdmin) +admin.site.register(ConsumptionHistory, ConsumptionHistoryAdmin) +admin.site.register(KegHistory, KegHistoryAdmin) +admin.site.register(Consumption, ConsumptionAdmin) +admin.site.register(Menu, MenuAdmin) +admin.site.register(MenuHistory, MenuHistoryAdmin) \ No newline at end of file diff --git a/gestion/migrations/0006_auto_20190227_0859.py b/gestion/migrations/0006_auto_20190227_0859.py new file mode 100644 index 0000000..05c16ac --- /dev/null +++ b/gestion/migrations/0006_auto_20190227_0859.py @@ -0,0 +1,165 @@ +# Generated by Django 2.1 on 2019-02-27 07:59 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('gestion', '0005_auto_20190106_0018'), + ] + + operations = [ + migrations.AlterField( + model_name='consumption', + name='customer', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='consumption_global_taken', to=settings.AUTH_USER_MODEL, verbose_name='Client'), + ), + migrations.AlterField( + model_name='consumption', + name='product', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='gestion.Product', verbose_name='Produit'), + ), + migrations.AlterField( + model_name='consumption', + name='quantity', + field=models.PositiveIntegerField(default=0, verbose_name='Quantité'), + ), + migrations.AlterField( + model_name='consumptionhistory', + name='amount', + field=models.DecimalField(decimal_places=2, default=0, max_digits=7, verbose_name='Montant'), + ), + migrations.AlterField( + model_name='consumptionhistory', + name='customer', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='consumption_taken', to=settings.AUTH_USER_MODEL, verbose_name='Client'), + ), + migrations.AlterField( + model_name='consumptionhistory', + name='paymentMethod', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='preferences.PaymentMethod', verbose_name='Moyen de paiement'), + ), + migrations.AlterField( + model_name='consumptionhistory', + name='product', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='gestion.Product', verbose_name='Produit'), + ), + migrations.AlterField( + model_name='consumptionhistory', + name='quantity', + field=models.PositiveIntegerField(default=0, verbose_name='Quantité'), + ), + migrations.AlterField( + model_name='historicalconsumption', + name='quantity', + field=models.PositiveIntegerField(default=0, verbose_name='Quantité'), + ), + migrations.AlterField( + model_name='historicalconsumptionhistory', + name='amount', + field=models.DecimalField(decimal_places=2, default=0, max_digits=7, verbose_name='Montant'), + ), + migrations.AlterField( + model_name='historicalconsumptionhistory', + name='quantity', + field=models.PositiveIntegerField(default=0, verbose_name='Quantité'), + ), + migrations.AlterField( + model_name='historicalkeghistory', + name='amountSold', + field=models.DecimalField(decimal_places=2, default=0, max_digits=5, verbose_name='Somme vendue'), + ), + migrations.AlterField( + model_name='historicalkeghistory', + name='closingDate', + field=models.DateTimeField(blank=True, null=True, verbose_name='Date fermeture'), + ), + migrations.AlterField( + model_name='historicalkeghistory', + name='isCurrentKegHistory', + field=models.BooleanField(default=True, verbose_name='Actuel'), + ), + migrations.AlterField( + model_name='historicalkeghistory', + name='openingDate', + field=models.DateTimeField(blank=True, editable=False, verbose_name='Date ouverture'), + ), + migrations.AlterField( + model_name='historicalkeghistory', + name='quantitySold', + field=models.DecimalField(decimal_places=2, default=0, max_digits=5, verbose_name='Quantité vendue'), + ), + migrations.AlterField( + model_name='historicalmenuhistory', + name='amount', + field=models.DecimalField(decimal_places=2, default=0, max_digits=7, verbose_name='Montant'), + ), + migrations.AlterField( + model_name='historicalmenuhistory', + name='quantity', + field=models.PositiveIntegerField(default=0, verbose_name='Quantité'), + ), + migrations.AlterField( + model_name='historicalproduct', + name='category', + field=models.CharField(choices=[('PP', 'Pinte Pression'), ('DP', 'Demi Pression'), ('GP', 'Galopin pression'), ('BT', 'Bouteille'), ('SO', 'Soft'), ('FO', 'En-cas'), ('PA', 'Ingredients panini')], default='FO', max_length=2, verbose_name='Catégorie'), + ), + migrations.AlterField( + model_name='keghistory', + name='amountSold', + field=models.DecimalField(decimal_places=2, default=0, max_digits=5, verbose_name='Somme vendue'), + ), + migrations.AlterField( + model_name='keghistory', + name='closingDate', + field=models.DateTimeField(blank=True, null=True, verbose_name='Date fermeture'), + ), + migrations.AlterField( + model_name='keghistory', + name='isCurrentKegHistory', + field=models.BooleanField(default=True, verbose_name='Actuel'), + ), + migrations.AlterField( + model_name='keghistory', + name='keg', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='gestion.Keg', verbose_name='Fût'), + ), + migrations.AlterField( + model_name='keghistory', + name='openingDate', + field=models.DateTimeField(auto_now_add=True, verbose_name='Date ouverture'), + ), + migrations.AlterField( + model_name='keghistory', + name='quantitySold', + field=models.DecimalField(decimal_places=2, default=0, max_digits=5, verbose_name='Quantité vendue'), + ), + migrations.AlterField( + model_name='menuhistory', + name='amount', + field=models.DecimalField(decimal_places=2, default=0, max_digits=7, verbose_name='Montant'), + ), + migrations.AlterField( + model_name='menuhistory', + name='customer', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='menu_taken', to=settings.AUTH_USER_MODEL, verbose_name='Client'), + ), + migrations.AlterField( + model_name='menuhistory', + name='paymentMethod', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='preferences.PaymentMethod', verbose_name='Moyen de paiement'), + ), + migrations.AlterField( + model_name='menuhistory', + name='quantity', + field=models.PositiveIntegerField(default=0, verbose_name='Quantité'), + ), + migrations.AlterField( + model_name='product', + name='category', + field=models.CharField(choices=[('PP', 'Pinte Pression'), ('DP', 'Demi Pression'), ('GP', 'Galopin pression'), ('BT', 'Bouteille'), ('SO', 'Soft'), ('FO', 'En-cas'), ('PA', 'Ingredients panini')], default='FO', max_length=2, verbose_name='Catégorie'), + ), + ] diff --git a/gestion/models.py b/gestion/models.py index e608ff5..7aa1f74 100644 --- a/gestion/models.py +++ b/gestion/models.py @@ -23,8 +23,8 @@ class Product(models.Model): (G_PRESSION, "Galopin pression"), (BOTTLE, "Bouteille"), (SOFT, "Soft"), - (FOOD, "Bouffe autre que panini"), - (PANINI, "Bouffe pour panini"), + (FOOD, "En-cas"), + (PANINI, "Ingredients panini"), ) class Meta: verbose_name = "Produit" @@ -118,12 +118,12 @@ class KegHistory(models.Model): class Meta: verbose_name = "Historique de fût" - keg = models.ForeignKey(Keg, on_delete=models.PROTECT) - openingDate = models.DateTimeField(auto_now_add=True) - quantitySold = models.DecimalField(decimal_places=2, max_digits=5, default=0) - amountSold = models.DecimalField(decimal_places=2, max_digits=5, default=0) - closingDate = models.DateTimeField(null=True, blank=True) - isCurrentKegHistory = models.BooleanField(default=True) + keg = models.ForeignKey(Keg, on_delete=models.PROTECT, verbose_name="Fût") + openingDate = models.DateTimeField(auto_now_add=True, verbose_name="Date ouverture") + quantitySold = models.DecimalField(decimal_places=2, max_digits=5, default=0, verbose_name="Quantité vendue") + amountSold = models.DecimalField(decimal_places=2, max_digits=5, default=0, verbose_name="Somme vendue") + closingDate = models.DateTimeField(null=True, blank=True, verbose_name="Date fermeture") + isCurrentKegHistory = models.BooleanField(default=True, verbose_name="Actuel") history = HistoricalRecords() def __str__(self): @@ -196,12 +196,12 @@ class MenuHistory(models.Model): class Meta: verbose_name = "Historique de menu" - customer = models.ForeignKey(User, on_delete=models.PROTECT, related_name="menu_taken") - quantity = models.PositiveIntegerField(default=0) - paymentMethod = models.ForeignKey(PaymentMethod, on_delete=models.PROTECT) + customer = models.ForeignKey(User, on_delete=models.PROTECT, related_name="menu_taken", verbose_name="Client") + quantity = models.PositiveIntegerField(default=0, verbose_name="Quantité") + paymentMethod = models.ForeignKey(PaymentMethod, on_delete=models.PROTECT, verbose_name="Moyen de paiement") date = models.DateTimeField(auto_now_add=True) menu = models.ForeignKey(Menu, on_delete=models.PROTECT) - amount = models.DecimalField(max_digits=7, decimal_places=2, default=0) + amount = models.DecimalField(max_digits=7, decimal_places=2, default=0, verbose_name="Montant") coopeman = models.ForeignKey(User, on_delete=models.PROTECT, related_name="menu_selled") history = HistoricalRecords() @@ -215,12 +215,12 @@ class ConsumptionHistory(models.Model): class Meta: verbose_name = "Consommation" - customer = models.ForeignKey(User, on_delete=models.PROTECT, related_name="consumption_taken") - quantity = models.PositiveIntegerField(default=0) - paymentMethod = models.ForeignKey(PaymentMethod, on_delete=models.PROTECT) + customer = models.ForeignKey(User, on_delete=models.PROTECT, related_name="consumption_taken", verbose_name="Client") + quantity = models.PositiveIntegerField(default=0, verbose_name="Quantité") + paymentMethod = models.ForeignKey(PaymentMethod, on_delete=models.PROTECT, verbose_name="Moyen de paiement") date = models.DateTimeField(auto_now_add=True) - product = models.ForeignKey(Product, on_delete=models.PROTECT) - amount = models.DecimalField(max_digits=7, decimal_places=2, default=0) + product = models.ForeignKey(Product, on_delete=models.PROTECT, verbose_name="Produit") + amount = models.DecimalField(max_digits=7, decimal_places=2, default=0, verbose_name="Montant") coopeman = models.ForeignKey(User, on_delete=models.PROTECT, related_name="consumption_selled") history = HistoricalRecords() @@ -234,9 +234,9 @@ class Consumption(models.Model): class Meta: verbose_name = "Consommation totale" - customer = models.ForeignKey(User, on_delete=models.PROTECT, related_name="consumption_global_taken") - product = models.ForeignKey(Product, on_delete=models.PROTECT) - quantity = models.PositiveIntegerField(default=0) + customer = models.ForeignKey(User, on_delete=models.PROTECT, related_name="consumption_global_taken", verbose_name="Client") + product = models.ForeignKey(Product, on_delete=models.PROTECT, verbose_name="Produit") + quantity = models.PositiveIntegerField(default=0, verbose_name="Quantité") history = HistoricalRecords() def __str__(self): diff --git a/preferences/admin.py b/preferences/admin.py index f90378e..308e3c1 100644 --- a/preferences/admin.py +++ b/preferences/admin.py @@ -2,6 +2,19 @@ from django.contrib import admin from simple_history.admin import SimpleHistoryAdmin from .models import PaymentMethod, GeneralPreferences, Cotisation -admin.site.register(PaymentMethod, SimpleHistoryAdmin) -admin.site.register(GeneralPreferences, SimpleHistoryAdmin) -admin.site.register(Cotisation, SimpleHistoryAdmin) \ No newline at end of file +class CotisationAdmin(SimpleHistoryAdmin): + list_display = ('__str__', 'amount', 'duration') + ordering = ('-duration', '-amount') + +class GeneralPreferencesAdmin(SimpleHistoryAdmin): + list_display = ('is_active', 'president', 'vice_president', 'treasurer', 'secretary', 'brewer', 'grocer', 'use_pinte_monitoring', 'lost_pintes_allowed', 'floating_buttons', 'automatic_logout_time') + +class PaymentMethodAdmin(SimpleHistoryAdmin): + list_display = ('name', 'is_active', 'is_usable_in_cotisation', 'is_usable_in_reload', 'affect_balance') + ordering = ('name',) + search_fields = ('name',) + list_filter = ('is_active', 'is_usable_in_cotisation', 'is_usable_in_reload', 'affect_balance') + +admin.site.register(PaymentMethod, PaymentMethodAdmin) +admin.site.register(GeneralPreferences, GeneralPreferencesAdmin) +admin.site.register(Cotisation, CotisationAdmin) \ No newline at end of file diff --git a/preferences/migrations/0009_auto_20190227_0859.py b/preferences/migrations/0009_auto_20190227_0859.py new file mode 100644 index 0000000..6c1b49f --- /dev/null +++ b/preferences/migrations/0009_auto_20190227_0859.py @@ -0,0 +1,199 @@ +# Generated by Django 2.1 on 2019-02-27 07:59 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('preferences', '0008_auto_20190218_1802'), + ] + + operations = [ + migrations.AlterModelOptions( + name='generalpreferences', + options={'verbose_name': 'Préférences générales', 'verbose_name_plural': 'Préférences générales'}, + ), + migrations.AlterModelOptions( + name='historicalgeneralpreferences', + options={'get_latest_by': 'history_date', 'ordering': ('-history_date', '-history_id'), 'verbose_name': 'historical Préférences générales'}, + ), + migrations.AlterModelOptions( + name='historicalpaymentmethod', + options={'get_latest_by': 'history_date', 'ordering': ('-history_date', '-history_id'), 'verbose_name': 'historical Moyen de paiement'}, + ), + migrations.AlterModelOptions( + name='paymentmethod', + options={'verbose_name': 'Moyen de paiement', 'verbose_name_plural': 'Moyens de paiement'}, + ), + migrations.AlterField( + model_name='generalpreferences', + name='active_message', + field=models.TextField(blank=True, verbose_name='Message non actif'), + ), + migrations.AlterField( + model_name='generalpreferences', + name='automatic_logout_time', + field=models.PositiveIntegerField(null=True, verbose_name='Temps de déconnexion automatique'), + ), + migrations.AlterField( + model_name='generalpreferences', + name='brewer', + field=models.CharField(blank=True, max_length=255, verbose_name='Maître Brasseur'), + ), + migrations.AlterField( + model_name='generalpreferences', + name='floating_buttons', + field=models.BooleanField(default=False, verbose_name='Boutons flottants'), + ), + migrations.AlterField( + model_name='generalpreferences', + name='global_message', + field=models.TextField(blank=True, verbose_name='Message global'), + ), + migrations.AlterField( + model_name='generalpreferences', + name='grocer', + field=models.CharField(blank=True, max_length=255, verbose_name='Épic Épicier'), + ), + migrations.AlterField( + model_name='generalpreferences', + name='home_text', + field=models.TextField(blank=True, verbose_name="Message d'accueil"), + ), + migrations.AlterField( + model_name='generalpreferences', + name='is_active', + field=models.BooleanField(default=True, verbose_name='Site actif'), + ), + migrations.AlterField( + model_name='generalpreferences', + name='lost_pintes_allowed', + field=models.PositiveIntegerField(default=0, verbose_name='Nombre de pintes perdus admises'), + ), + migrations.AlterField( + model_name='generalpreferences', + name='menu', + field=models.FileField(blank=True, null=True, upload_to='', verbose_name='Menu'), + ), + migrations.AlterField( + model_name='generalpreferences', + name='president', + field=models.CharField(blank=True, max_length=255, verbose_name='Président'), + ), + migrations.AlterField( + model_name='generalpreferences', + name='rules', + field=models.FileField(blank=True, null=True, upload_to='', verbose_name='Règlement intérieur'), + ), + migrations.AlterField( + model_name='generalpreferences', + name='secretary', + field=models.CharField(blank=True, max_length=255, verbose_name='Secrétaire'), + ), + migrations.AlterField( + model_name='generalpreferences', + name='statutes', + field=models.FileField(blank=True, null=True, upload_to='', verbose_name='Statuts'), + ), + migrations.AlterField( + model_name='generalpreferences', + name='treasurer', + field=models.CharField(blank=True, max_length=255, verbose_name='Trésorier'), + ), + migrations.AlterField( + model_name='generalpreferences', + name='use_pinte_monitoring', + field=models.BooleanField(default=False, verbose_name='Suivi de pintes'), + ), + migrations.AlterField( + model_name='generalpreferences', + name='vice_president', + field=models.CharField(blank=True, max_length=255, verbose_name='Vice Président'), + ), + migrations.AlterField( + model_name='historicalgeneralpreferences', + name='active_message', + field=models.TextField(blank=True, verbose_name='Message non actif'), + ), + migrations.AlterField( + model_name='historicalgeneralpreferences', + name='automatic_logout_time', + field=models.PositiveIntegerField(null=True, verbose_name='Temps de déconnexion automatique'), + ), + migrations.AlterField( + model_name='historicalgeneralpreferences', + name='brewer', + field=models.CharField(blank=True, max_length=255, verbose_name='Maître Brasseur'), + ), + migrations.AlterField( + model_name='historicalgeneralpreferences', + name='floating_buttons', + field=models.BooleanField(default=False, verbose_name='Boutons flottants'), + ), + migrations.AlterField( + model_name='historicalgeneralpreferences', + name='global_message', + field=models.TextField(blank=True, verbose_name='Message global'), + ), + migrations.AlterField( + model_name='historicalgeneralpreferences', + name='grocer', + field=models.CharField(blank=True, max_length=255, verbose_name='Épic Épicier'), + ), + migrations.AlterField( + model_name='historicalgeneralpreferences', + name='home_text', + field=models.TextField(blank=True, verbose_name="Message d'accueil"), + ), + migrations.AlterField( + model_name='historicalgeneralpreferences', + name='is_active', + field=models.BooleanField(default=True, verbose_name='Site actif'), + ), + migrations.AlterField( + model_name='historicalgeneralpreferences', + name='lost_pintes_allowed', + field=models.PositiveIntegerField(default=0, verbose_name='Nombre de pintes perdus admises'), + ), + migrations.AlterField( + model_name='historicalgeneralpreferences', + name='menu', + field=models.TextField(blank=True, max_length=100, null=True, verbose_name='Menu'), + ), + migrations.AlterField( + model_name='historicalgeneralpreferences', + name='president', + field=models.CharField(blank=True, max_length=255, verbose_name='Président'), + ), + migrations.AlterField( + model_name='historicalgeneralpreferences', + name='rules', + field=models.TextField(blank=True, max_length=100, null=True, verbose_name='Règlement intérieur'), + ), + migrations.AlterField( + model_name='historicalgeneralpreferences', + name='secretary', + field=models.CharField(blank=True, max_length=255, verbose_name='Secrétaire'), + ), + migrations.AlterField( + model_name='historicalgeneralpreferences', + name='statutes', + field=models.TextField(blank=True, max_length=100, null=True, verbose_name='Statuts'), + ), + migrations.AlterField( + model_name='historicalgeneralpreferences', + name='treasurer', + field=models.CharField(blank=True, max_length=255, verbose_name='Trésorier'), + ), + migrations.AlterField( + model_name='historicalgeneralpreferences', + name='use_pinte_monitoring', + field=models.BooleanField(default=False, verbose_name='Suivi de pintes'), + ), + migrations.AlterField( + model_name='historicalgeneralpreferences', + name='vice_president', + field=models.CharField(blank=True, max_length=255, verbose_name='Vice Président'), + ), + ] diff --git a/preferences/models.py b/preferences/models.py index ec5f357..63ab791 100644 --- a/preferences/models.py +++ b/preferences/models.py @@ -7,6 +7,10 @@ class PaymentMethod(models.Model): """ Stores payment methods """ + class Meta: + verbose_name="Moyen de paiement" + verbose_name_plural = "Moyens de paiement" + name = models.CharField(max_length=255, verbose_name="Nom") is_active = models.BooleanField(default=True, verbose_name="Actif") is_usable_in_cotisation = models.BooleanField(default=True, verbose_name="Cotisations ?") @@ -22,23 +26,27 @@ class GeneralPreferences(models.Model): """ Stores a unique line of general preferences """ - is_active = models.BooleanField(default=True) - active_message = models.TextField(blank=True) - global_message = models.TextField(blank=True) - president = models.CharField(max_length=255, blank=True) - vice_president = models.CharField(max_length=255, blank=True) - treasurer = models.CharField(max_length=255, blank=True) - secretary = models.CharField(max_length=255, blank=True) - brewer = models.CharField(max_length=255, blank=True) - grocer = models.CharField(max_length=255, blank=True) - use_pinte_monitoring = models.BooleanField(default=False) - lost_pintes_allowed = models.PositiveIntegerField(default=0) - floating_buttons = models.BooleanField(default=False) - home_text = models.TextField(blank=True) - automatic_logout_time = models.PositiveIntegerField(null=True) - statutes = models.FileField(blank=True, null=True) - rules = models.FileField(blank=True, null=True) - menu = models.FileField(blank=True, null=True) + class Meta: + verbose_name="Préférences générales" + verbose_name_plural = "Préférences générales" + + is_active = models.BooleanField(default=True, verbose_name="Site actif") + active_message = models.TextField(blank=True, verbose_name="Message non actif") + global_message = models.TextField(blank=True, verbose_name="Message global") + president = models.CharField(max_length=255, blank=True, verbose_name="Président") + vice_president = models.CharField(max_length=255, blank=True, verbose_name="Vice Président") + treasurer = models.CharField(max_length=255, blank=True, verbose_name="Trésorier") + secretary = models.CharField(max_length=255, blank=True, verbose_name="Secrétaire") + brewer = models.CharField(max_length=255, blank=True, verbose_name="Maître Brasseur") + grocer = models.CharField(max_length=255, blank=True, verbose_name="Épic Épicier") + use_pinte_monitoring = models.BooleanField(default=False, verbose_name="Suivi de pintes") + lost_pintes_allowed = models.PositiveIntegerField(default=0, verbose_name="Nombre de pintes perdus admises") + floating_buttons = models.BooleanField(default=False, verbose_name="Boutons flottants") + home_text = models.TextField(blank=True, verbose_name="Message d'accueil") + automatic_logout_time = models.PositiveIntegerField(null=True, verbose_name="Temps de déconnexion automatique") + statutes = models.FileField(blank=True, null=True, verbose_name="Statuts") + rules = models.FileField(blank=True, null=True, verbose_name="Règlement intérieur") + menu = models.FileField(blank=True, null=True, verbose_name="Menu") history = HistoricalRecords() class Cotisation(models.Model): diff --git a/users/admin.py b/users/admin.py index c3737f8..7aa8840 100644 --- a/users/admin.py +++ b/users/admin.py @@ -1,13 +1,49 @@ from django.contrib import admin from django.contrib.auth.models import Permission from simple_history.admin import SimpleHistoryAdmin +from django.db.models import F + +from .models import School, Profile, CotisationHistory, WhiteListHistory + +class CotisationHistoryAdmin(SimpleHistoryAdmin): + list_display = ('user', 'amount', 'duration', 'paymentDate', 'endDate', 'paymentMethod') + ordering = ('user', 'amount', 'duration', 'paymentDate', 'endDate') + search_fields = ('user',) + list_filter = ('paymentMethod', ) + +class BalanceFilter(admin.SimpleListFilter): + title = 'Solde' + parameter_name = 'solde' + + def lookups(self, request, model_admin): + return ( + ('po', '>0'), + ('nu', '=0'), + ('ne', '<0'), + ) + + def queryset(self, request, queryset): + if self.value() == 'po': + return queryset.filter(credit__gt=F('debit')) + elif self.value() == 'nu': + return queryset.filter(credit=F('debit')) + elif self.value() == 'ne': + return queryset.filter(credit__lt=F('debit')) -from .models import School, Profile, CotisationHistory class ProfileAdmin(SimpleHistoryAdmin): - search_fields = ('user__username', 'user__first_name', 'user__last_name') + list_display = ('user', 'credit', 'debit', 'balance', 'school', 'cotisationEnd', 'is_adherent') + ordering = ('user', '-credit', '-debit') + search_fields = ('user',) + list_filter = ('school', BalanceFilter) + +class WhiteListHistoryAdmin(SimpleHistoryAdmin): + list_display = ('user', 'paymentDate', 'endDate', 'duration') + ordering = ('user', 'duration', 'paymentDate', 'endDate') + search_fields = ('user',) admin.site.register(Permission, SimpleHistoryAdmin) admin.site.register(School, SimpleHistoryAdmin) +admin.site.register(WhiteListHistory, WhiteListHistoryAdmin) admin.site.register(Profile, ProfileAdmin) -admin.site.register(CotisationHistory, SimpleHistoryAdmin) \ No newline at end of file +admin.site.register(CotisationHistory, CotisationHistoryAdmin) \ No newline at end of file diff --git a/users/migrations/0005_auto_20190227_0859.py b/users/migrations/0005_auto_20190227_0859.py new file mode 100644 index 0000000..6227788 --- /dev/null +++ b/users/migrations/0005_auto_20190227_0859.py @@ -0,0 +1,84 @@ +# Generated by Django 2.1 on 2019-02-27 07:59 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0004_auto_20190226_2313'), + ] + + operations = [ + migrations.AlterModelOptions( + name='whitelisthistory', + options={'verbose_name': 'Historique accès gracieux', 'verbose_name_plural': 'Historique accès gracieux'}, + ), + migrations.AlterField( + model_name='historicalprofile', + name='cotisationEnd', + field=models.DateTimeField(blank=True, null=True, verbose_name='Fin de cotisation'), + ), + migrations.AlterField( + model_name='historicalprofile', + name='credit', + field=models.DecimalField(decimal_places=2, default=0, max_digits=7, verbose_name='Crédit'), + ), + migrations.AlterField( + model_name='historicalprofile', + name='debit', + field=models.DecimalField(decimal_places=2, default=0, max_digits=7, verbose_name='Débit'), + ), + migrations.AlterField( + model_name='historicalwhitelisthistory', + name='endDate', + field=models.DateTimeField(verbose_name='Date de fin'), + ), + migrations.AlterField( + model_name='historicalwhitelisthistory', + name='paymentDate', + field=models.DateTimeField(blank=True, editable=False, verbose_name='Date de début'), + ), + migrations.AlterField( + model_name='profile', + name='cotisationEnd', + field=models.DateTimeField(blank=True, null=True, verbose_name='Fin de cotisation'), + ), + migrations.AlterField( + model_name='profile', + name='credit', + field=models.DecimalField(decimal_places=2, default=0, max_digits=7, verbose_name='Crédit'), + ), + migrations.AlterField( + model_name='profile', + name='debit', + field=models.DecimalField(decimal_places=2, default=0, max_digits=7, verbose_name='Débit'), + ), + migrations.AlterField( + model_name='profile', + name='school', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='users.School', verbose_name='École'), + ), + migrations.AlterField( + model_name='profile', + name='user', + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='Utilisateur'), + ), + migrations.AlterField( + model_name='whitelisthistory', + name='endDate', + field=models.DateTimeField(verbose_name='Date de fin'), + ), + migrations.AlterField( + model_name='whitelisthistory', + name='paymentDate', + field=models.DateTimeField(auto_now_add=True, verbose_name='Date de début'), + ), + migrations.AlterField( + model_name='whitelisthistory', + name='user', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL, verbose_name='Client'), + ), + ] diff --git a/users/models.py b/users/models.py index 214894b..02ff428 100644 --- a/users/models.py +++ b/users/models.py @@ -42,10 +42,11 @@ class WhiteListHistory(models.Model): """ class Meta: verbose_name = "Historique accès gracieux" + verbose_name_plural = "Historique accès gracieux" - user = models.ForeignKey(User, on_delete=models.PROTECT) - paymentDate = models.DateTimeField(auto_now_add=True) - endDate = models.DateTimeField() + user = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name="Client") + paymentDate = models.DateTimeField(auto_now_add=True, verbose_name="Date de début") + endDate = models.DateTimeField(verbose_name="Date de fin") duration = models.PositiveIntegerField(verbose_name="Durée", help_text="Durée de l'accès gracieux en jour") coopeman = models.ForeignKey(User, on_delete=models.PROTECT, related_name="whitelist_made") history = HistoricalRecords() @@ -57,11 +58,11 @@ class Profile(models.Model): class Meta: verbose_name = "Profil" - user = models.OneToOneField(User, on_delete=models.CASCADE) - credit = models.DecimalField(max_digits=7, decimal_places=2, default=0) - debit = models.DecimalField(max_digits=7, decimal_places=2, default=0) - school = models.ForeignKey(School, on_delete=models.PROTECT, blank=True, null=True) - cotisationEnd = models.DateTimeField(blank=True, null=True) + user = models.OneToOneField(User, on_delete=models.CASCADE, verbose_name="Utilisateur") + credit = models.DecimalField(max_digits=7, decimal_places=2, default=0, verbose_name="Crédit") + debit = models.DecimalField(max_digits=7, decimal_places=2, default=0, verbose_name="Débit") + school = models.ForeignKey(School, on_delete=models.PROTECT, blank=True, null=True, verbose_name="École") + cotisationEnd = models.DateTimeField(blank=True, null=True, verbose_name="Fin de cotisation") history = HistoricalRecords() @property