diff --git a/coopeV3/settings.py b/coopeV3/settings.py index 0cb6d72..62250b1 100644 --- a/coopeV3/settings.py +++ b/coopeV3/settings.py @@ -43,7 +43,8 @@ INSTALLED_APPS = [ 'preferences', 'coopeV3', 'dal', - 'dal_select2', + 'dal_select2', + 'simple_history', ] MIDDLEWARE = [ @@ -54,6 +55,7 @@ MIDDLEWARE = [ 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'simple_history.middleware.HistoryRequestMiddleware', ] ROOT_URLCONF = 'coopeV3.urls' diff --git a/gestion/admin.py b/gestion/admin.py index 1fa3040..253981b 100644 --- a/gestion/admin.py +++ b/gestion/admin.py @@ -1,11 +1,14 @@ from django.contrib import admin +from simple_history.admin import SimpleHistoryAdmin -from .models import Reload, Refund, Product, Keg, ConsumptionHistory, KegHistory, Consumption +from .models import Reload, Refund, Product, Keg, ConsumptionHistory, KegHistory, Consumption, Menu, MenuHistory -admin.site.register(Reload) -admin.site.register(Refund) -admin.site.register(Product) -admin.site.register(Keg) -admin.site.register(ConsumptionHistory) -admin.site.register(KegHistory) -admin.site.register(Consumption) \ No newline at end of file +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 diff --git a/gestion/forms.py b/gestion/forms.py index 89a694f..6c364b7 100644 --- a/gestion/forms.py +++ b/gestion/forms.py @@ -18,14 +18,6 @@ class ReloadForm(forms.ModelForm): fields = ("customer", "amount", "PaymentMethod") widgets = {'customer': autocomplete.ModelSelect2(url='users:active-users-autocomplete', attrs={'data-minimum-input-length':2})} - def clean_amount(self): - if self.cleaned_data['amount'] <= 0: - raise ValidationError( - "Le montant doit être strictement positif" - ) - else: - return self.cleaned_data['amount'] - class RefundForm(forms.ModelForm): class Meta: @@ -33,14 +25,6 @@ class RefundForm(forms.ModelForm): fields = ("customer", "amount") widgets = {'customer': autocomplete.ModelSelect2(url='users:active-users-autocomplete', attrs={'data-minimum-input-length':2})} - def clean_amount(self): - if self.cleaned_data['amount'] <= 0: - raise ValidationError( - "Le montant doit être strictement positif" - ) - else: - return self.cleaned_data['amount'] - class ProductForm(forms.ModelForm): class Meta: diff --git a/gestion/migrations/0005_historicalconsumption_historicalconsumptionhistory_historicalkeg_historicalkeghistory_historicalmenu.py b/gestion/migrations/0005_historicalconsumption_historicalconsumptionhistory_historicalkeg_historicalkeghistory_historicalmenu.py new file mode 100644 index 0000000..ae67db9 --- /dev/null +++ b/gestion/migrations/0005_historicalconsumption_historicalconsumptionhistory_historicalkeg_historicalkeghistory_historicalmenu.py @@ -0,0 +1,266 @@ +# Generated by Django 2.1 on 2018-11-26 07:57 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import simple_history.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('preferences', '0003_historicalcotisation_historicalgeneralpreferences_historicalpaymentmethod'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('gestion', '0004_consumption'), + ] + + operations = [ + migrations.CreateModel( + name='HistoricalConsumption', + fields=[ + ('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')), + ('quantity', models.PositiveIntegerField(default=0)), + ('history_id', models.AutoField(primary_key=True, serialize=False)), + ('history_change_reason', models.CharField(max_length=100, null=True)), + ('history_date', models.DateTimeField()), + ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)), + ('customer', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)), + ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)), + ('product', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='gestion.Product')), + ], + options={ + 'verbose_name': 'historical consumption', + 'ordering': ('-history_date', '-history_id'), + 'get_latest_by': 'history_date', + }, + bases=(simple_history.models.HistoricalChanges, models.Model), + ), + migrations.CreateModel( + name='HistoricalConsumptionHistory', + fields=[ + ('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')), + ('quantity', models.PositiveIntegerField(default=0)), + ('date', models.DateTimeField(blank=True, editable=False)), + ('amount', models.DecimalField(decimal_places=2, default=0, max_digits=7)), + ('history_id', models.AutoField(primary_key=True, serialize=False)), + ('history_change_reason', models.CharField(max_length=100, null=True)), + ('history_date', models.DateTimeField()), + ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)), + ('coopeman', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)), + ('customer', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)), + ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)), + ('menu', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='gestion.MenuHistory')), + ('paymentMethod', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='preferences.PaymentMethod')), + ('product', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='gestion.Product')), + ], + options={ + 'verbose_name': 'historical consumption history', + 'ordering': ('-history_date', '-history_id'), + 'get_latest_by': 'history_date', + }, + bases=(simple_history.models.HistoricalChanges, models.Model), + ), + migrations.CreateModel( + name='HistoricalKeg', + fields=[ + ('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')), + ('name', models.CharField(db_index=True, max_length=20, verbose_name='Nom')), + ('stockHold', models.IntegerField(default=0, verbose_name='Stock en soute')), + ('barcode', models.CharField(db_index=True, max_length=20, verbose_name='Code barre')), + ('amount', models.DecimalField(decimal_places=2, max_digits=5, verbose_name='Prix du fût')), + ('capacity', models.IntegerField(default=30, verbose_name='Capacité (L)')), + ('is_active', models.BooleanField(default=False, verbose_name='Actif')), + ('history_id', models.AutoField(primary_key=True, serialize=False)), + ('history_change_reason', models.CharField(max_length=100, null=True)), + ('history_date', models.DateTimeField()), + ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)), + ('demi', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='gestion.Product')), + ('galopin', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='gestion.Product')), + ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)), + ('pinte', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='gestion.Product')), + ], + options={ + 'verbose_name': 'historical keg', + 'ordering': ('-history_date', '-history_id'), + 'get_latest_by': 'history_date', + }, + bases=(simple_history.models.HistoricalChanges, models.Model), + ), + migrations.CreateModel( + name='HistoricalKegHistory', + fields=[ + ('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')), + ('openingDate', models.DateTimeField(blank=True, editable=False)), + ('quantitySold', models.DecimalField(decimal_places=2, default=0, max_digits=5)), + ('amountSold', models.DecimalField(decimal_places=2, default=0, max_digits=5)), + ('closingDate', models.DateTimeField(blank=True, null=True)), + ('isCurrentKegHistory', models.BooleanField(default=True)), + ('history_id', models.AutoField(primary_key=True, serialize=False)), + ('history_change_reason', models.CharField(max_length=100, null=True)), + ('history_date', models.DateTimeField()), + ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)), + ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)), + ('keg', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='gestion.Keg')), + ], + options={ + 'verbose_name': 'historical keg history', + 'ordering': ('-history_date', '-history_id'), + 'get_latest_by': 'history_date', + }, + bases=(simple_history.models.HistoricalChanges, models.Model), + ), + migrations.CreateModel( + name='HistoricalMenu', + fields=[ + ('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')), + ('name', models.CharField(max_length=255, verbose_name='Nom')), + ('amount', models.DecimalField(decimal_places=2, max_digits=5, verbose_name='Montant')), + ('barcode', models.CharField(db_index=True, max_length=20, verbose_name='Code barre')), + ('is_active', models.BooleanField(default=False, verbose_name='Actif')), + ('history_id', models.AutoField(primary_key=True, serialize=False)), + ('history_change_reason', models.CharField(max_length=100, null=True)), + ('history_date', models.DateTimeField()), + ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)), + ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)), + ], + options={ + 'verbose_name': 'historical menu', + 'ordering': ('-history_date', '-history_id'), + 'get_latest_by': 'history_date', + }, + bases=(simple_history.models.HistoricalChanges, models.Model), + ), + migrations.CreateModel( + name='HistoricalMenuHistory', + fields=[ + ('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')), + ('quantity', models.PositiveIntegerField(default=0)), + ('date', models.DateTimeField(blank=True, editable=False)), + ('amount', models.DecimalField(decimal_places=2, default=0, max_digits=5)), + ('history_id', models.AutoField(primary_key=True, serialize=False)), + ('history_change_reason', models.CharField(max_length=100, null=True)), + ('history_date', models.DateTimeField()), + ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)), + ('PaymentMethod', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='preferences.PaymentMethod')), + ('coopeman', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)), + ('customer', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)), + ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)), + ('menu', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='gestion.Menu')), + ], + options={ + 'verbose_name': 'historical menu history', + 'ordering': ('-history_date', '-history_id'), + 'get_latest_by': 'history_date', + }, + bases=(simple_history.models.HistoricalChanges, models.Model), + ), + migrations.CreateModel( + name='HistoricalProduct', + fields=[ + ('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')), + ('name', models.CharField(db_index=True, max_length=40, verbose_name='Nom')), + ('amount', models.DecimalField(decimal_places=2, max_digits=5, verbose_name='Prix de vente')), + ('stockHold', models.IntegerField(default=0, verbose_name='Stock en soute')), + ('stockBar', models.IntegerField(default=0, verbose_name='Stock en bar')), + ('barcode', models.CharField(db_index=True, max_length=20, verbose_name='Code barre')), + ('category', models.CharField(choices=[('PP', 'Pinte Pression'), ('DP', 'Demi Pression'), ('GP', 'Galopin pression'), ('BT', 'Bouteille'), ('SO', 'Soft'), ('FO', 'Bouffe autre que panini'), ('PA', 'Bouffe pour panini')], default='FO', max_length=2, verbose_name='Catégorie')), + ('needQuantityButton', models.BooleanField(default=False, verbose_name='Bouton quantité')), + ('is_active', models.BooleanField(default=True, verbose_name='Actif')), + ('volume', models.IntegerField(default=0)), + ('deg', models.DecimalField(decimal_places=2, default=0, max_digits=5, verbose_name='Degré')), + ('adherentRequired', models.BooleanField(default=True)), + ('history_id', models.AutoField(primary_key=True, serialize=False)), + ('history_change_reason', models.CharField(max_length=100, null=True)), + ('history_date', models.DateTimeField()), + ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)), + ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)), + ], + options={ + 'verbose_name': 'historical product', + 'ordering': ('-history_date', '-history_id'), + 'get_latest_by': 'history_date', + }, + bases=(simple_history.models.HistoricalChanges, models.Model), + ), + migrations.CreateModel( + name='HistoricalRaming', + fields=[ + ('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')), + ('date', models.DateTimeField(blank=True, editable=False)), + ('history_id', models.AutoField(primary_key=True, serialize=False)), + ('history_change_reason', models.CharField(max_length=100, null=True)), + ('history_date', models.DateTimeField()), + ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)), + ('coopeman', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)), + ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)), + ('keg', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='gestion.Keg')), + ], + options={ + 'verbose_name': 'historical raming', + 'ordering': ('-history_date', '-history_id'), + 'get_latest_by': 'history_date', + }, + bases=(simple_history.models.HistoricalChanges, models.Model), + ), + migrations.CreateModel( + name='HistoricalRefund', + fields=[ + ('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')), + ('date', models.DateTimeField(blank=True, editable=False)), + ('amount', models.DecimalField(decimal_places=2, max_digits=5, verbose_name='Montant')), + ('history_id', models.AutoField(primary_key=True, serialize=False)), + ('history_change_reason', models.CharField(max_length=100, null=True)), + ('history_date', models.DateTimeField()), + ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)), + ('coopeman', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)), + ('customer', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)), + ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)), + ], + options={ + 'verbose_name': 'historical refund', + 'ordering': ('-history_date', '-history_id'), + 'get_latest_by': 'history_date', + }, + bases=(simple_history.models.HistoricalChanges, models.Model), + ), + migrations.CreateModel( + name='HistoricalReload', + fields=[ + ('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')), + ('amount', models.DecimalField(decimal_places=2, max_digits=5, verbose_name='Montant')), + ('date', models.DateTimeField(blank=True, editable=False)), + ('history_id', models.AutoField(primary_key=True, serialize=False)), + ('history_change_reason', models.CharField(max_length=100, null=True)), + ('history_date', models.DateTimeField()), + ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)), + ('PaymentMethod', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='preferences.PaymentMethod')), + ('coopeman', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)), + ('customer', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)), + ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)), + ], + options={ + 'verbose_name': 'historical reload', + 'ordering': ('-history_date', '-history_id'), + 'get_latest_by': 'history_date', + }, + bases=(simple_history.models.HistoricalChanges, models.Model), + ), + migrations.CreateModel( + name='HistoricalStocking', + fields=[ + ('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')), + ('date', models.DateTimeField(blank=True, editable=False)), + ('history_id', models.AutoField(primary_key=True, serialize=False)), + ('history_change_reason', models.CharField(max_length=100, null=True)), + ('history_date', models.DateTimeField()), + ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)), + ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)), + ], + options={ + 'verbose_name': 'historical stocking', + 'ordering': ('-history_date', '-history_id'), + 'get_latest_by': 'history_date', + }, + bases=(simple_history.models.HistoricalChanges, models.Model), + ), + ] diff --git a/gestion/migrations/0006_auto_20181126_1408.py b/gestion/migrations/0006_auto_20181126_1408.py new file mode 100644 index 0000000..adf6b47 --- /dev/null +++ b/gestion/migrations/0006_auto_20181126_1408.py @@ -0,0 +1,84 @@ +# Generated by Django 2.1 on 2018-11-26 13:08 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('gestion', '0005_historicalconsumption_historicalconsumptionhistory_historicalkeg_historicalkeghistory_historicalmenu'), + ] + + operations = [ + migrations.AlterField( + model_name='historicalkeg', + name='amount', + field=models.DecimalField(decimal_places=2, max_digits=5, validators=[django.core.validators.MinValueValidator(0)], verbose_name='Prix du fût'), + ), + migrations.AlterField( + model_name='historicalmenu', + name='amount', + field=models.DecimalField(decimal_places=2, max_digits=5, validators=[django.core.validators.MinValueValidator(0)], verbose_name='Montant'), + ), + migrations.AlterField( + model_name='historicalproduct', + name='amount', + field=models.DecimalField(decimal_places=2, max_digits=5, validators=[django.core.validators.MinValueValidator(0)], verbose_name='Prix de vente'), + ), + migrations.AlterField( + model_name='historicalproduct', + name='deg', + field=models.DecimalField(decimal_places=2, default=0, max_digits=5, validators=[django.core.validators.MinValueValidator(0)], verbose_name='Degré'), + ), + migrations.AlterField( + model_name='historicalproduct', + name='volume', + field=models.PositiveIntegerField(default=0), + ), + migrations.AlterField( + model_name='historicalrefund', + name='amount', + field=models.DecimalField(decimal_places=2, max_digits=5, validators=[django.core.validators.MinValueValidator(0)], verbose_name='Montant'), + ), + migrations.AlterField( + model_name='historicalreload', + name='amount', + field=models.DecimalField(decimal_places=2, max_digits=5, validators=[django.core.validators.MinValueValidator(0)], verbose_name='Montant'), + ), + migrations.AlterField( + model_name='keg', + name='amount', + field=models.DecimalField(decimal_places=2, max_digits=5, validators=[django.core.validators.MinValueValidator(0)], verbose_name='Prix du fût'), + ), + migrations.AlterField( + model_name='menu', + name='amount', + field=models.DecimalField(decimal_places=2, max_digits=5, validators=[django.core.validators.MinValueValidator(0)], verbose_name='Montant'), + ), + migrations.AlterField( + model_name='product', + name='amount', + field=models.DecimalField(decimal_places=2, max_digits=5, validators=[django.core.validators.MinValueValidator(0)], verbose_name='Prix de vente'), + ), + migrations.AlterField( + model_name='product', + name='deg', + field=models.DecimalField(decimal_places=2, default=0, max_digits=5, validators=[django.core.validators.MinValueValidator(0)], verbose_name='Degré'), + ), + migrations.AlterField( + model_name='product', + name='volume', + field=models.PositiveIntegerField(default=0), + ), + migrations.AlterField( + model_name='refund', + name='amount', + field=models.DecimalField(decimal_places=2, max_digits=5, validators=[django.core.validators.MinValueValidator(0)], verbose_name='Montant'), + ), + migrations.AlterField( + model_name='reload', + name='amount', + field=models.DecimalField(decimal_places=2, max_digits=5, validators=[django.core.validators.MinValueValidator(0)], verbose_name='Montant'), + ), + ] diff --git a/gestion/migrations/0007_auto_20181127_0902.py b/gestion/migrations/0007_auto_20181127_0902.py new file mode 100644 index 0000000..b4c58bb --- /dev/null +++ b/gestion/migrations/0007_auto_20181127_0902.py @@ -0,0 +1,23 @@ +# Generated by Django 2.1 on 2018-11-27 08:02 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('gestion', '0006_auto_20181126_1408'), + ] + + operations = [ + migrations.RenameField( + model_name='historicalmenuhistory', + old_name='PaymentMethod', + new_name='paymentMethod', + ), + migrations.RenameField( + model_name='menuhistory', + old_name='PaymentMethod', + new_name='paymentMethod', + ), + ] diff --git a/gestion/models.py b/gestion/models.py index 0e019bf..8a5a21a 100644 --- a/gestion/models.py +++ b/gestion/models.py @@ -2,6 +2,9 @@ from django.db import models from django.contrib.auth.models import User from preferences.models import PaymentMethod from django.core.exceptions import ValidationError +from simple_history.models import HistoricalRecords +from django.core.validators import MinValueValidator + class Product(models.Model): P_PRESSION = 'PP' @@ -21,16 +24,17 @@ class Product(models.Model): (PANINI, "Bouffe pour panini"), ) name = models.CharField(max_length=40, verbose_name="Nom", unique=True) - amount = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="Prix de vente") + amount = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="Prix de vente", validators=[MinValueValidator(0)]) stockHold = models.IntegerField(default=0, verbose_name="Stock en soute") stockBar = models.IntegerField(default=0, verbose_name="Stock en bar") - barcode= models.CharField(max_length=20, unique=True, verbose_name="Code barre") + barcode = models.CharField(max_length=20, unique=True, verbose_name="Code barre") category = models.CharField(max_length=2, choices=TYPEINPUT_CHOICES_CATEGORIE, default=FOOD, verbose_name="Catégorie") needQuantityButton = models.BooleanField(default=False, verbose_name="Bouton quantité") is_active = models.BooleanField(default=True, verbose_name="Actif") - volume = models.IntegerField(default=0) - deg = models.DecimalField(default=0,max_digits=5, decimal_places=2, verbose_name="Degré") + volume = models.PositiveIntegerField(default=0) + deg = models.DecimalField(default=0,max_digits=5, decimal_places=2, verbose_name="Degré", validators=[MinValueValidator(0)]) adherentRequired = models.BooleanField(default=True) + history = HistoricalRecords() def __str__(self): return self.name @@ -71,12 +75,13 @@ class Keg(models.Model): name = models.CharField(max_length=20, unique=True, verbose_name="Nom") stockHold = models.IntegerField(default=0, verbose_name="Stock en soute") barcode = models.CharField(max_length=20, unique=True, verbose_name="Code barre") - amount = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="Prix du fût") + amount = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="Prix du fût", validators=[MinValueValidator(0)]) capacity = models.IntegerField(default=30, verbose_name="Capacité (L)") pinte = models.ForeignKey(Product, on_delete=models.PROTECT, related_name="futp", validators=[isPinte]) demi = models.ForeignKey(Product, on_delete=models.PROTECT, related_name="futd", validators=[isDemi]) galopin = models.ForeignKey(Product, on_delete=models.PROTECT, related_name="futg", validators=[isGalopin],null=True, blank=True) is_active = models.BooleanField(default=False, verbose_name="Actif") + history = HistoricalRecords() def __str__(self): return self.name @@ -88,6 +93,7 @@ class KegHistory(models.Model): amountSold = models.DecimalField(decimal_places=2, max_digits=5, default=0) closingDate = models.DateTimeField(null=True, blank=True) isCurrentKegHistory = models.BooleanField(default=True) + history = HistoricalRecords() def __str__(self): res = "Fût de " + str(self.keg) + " (" + str(self.openingDate) + " - " @@ -99,10 +105,11 @@ class KegHistory(models.Model): class Reload(models.Model): customer = models.ForeignKey(User, on_delete=models.PROTECT, related_name="reload_taken", verbose_name="Client") - amount = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="Montant") + amount = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="Montant", validators=[MinValueValidator(0)]) PaymentMethod = models.ForeignKey(PaymentMethod, on_delete=models.PROTECT, verbose_name="Moyen de paiement") coopeman = models.ForeignKey(User, on_delete=models.PROTECT, related_name="reload_realized") date = models.DateTimeField(auto_now_add=True) + history = HistoricalRecords() def __str__(self): return "Rechargement effectue par {0} le {1} ({2} euros, coopeman : {3})".format(self.customer, self.date, self.amount, self.coopeman) @@ -112,12 +119,14 @@ class Raming(models.Model): keg = models.ForeignKey(Keg, on_delete=models.PROTECT) coopeman = models.ForeignKey(User, on_delete=models.PROTECT) date = models.DateTimeField(auto_now_add=True) + history = HistoricalRecords() def __str__(self): return "Percussion d'un {0} effectué par {1} le {2}".format(self.keg, self.coopeman, self.date) class Stocking(models.Model): date = models.DateTimeField(auto_now_add=True) + history = HistoricalRecords() def __str__(self): return "Inventaire fait le {0}".format(self.date) @@ -126,8 +135,9 @@ class Stocking(models.Model): class Refund(models.Model): date = models.DateTimeField(auto_now_add=True) customer = models.ForeignKey(User, on_delete=models.PROTECT, related_name="refund_taken", verbose_name="Client") - amount = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="Montant") + amount = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="Montant", validators=[MinValueValidator(0)]) coopeman = models.ForeignKey(User, on_delete=models.PROTECT, related_name="refund_realized") + history = HistoricalRecords() def __str__(self): return "{0} remboursé de {1} le {2} (effectué par {3})".format(self.customer, self.amount, self.date, self.coopeman) @@ -135,22 +145,31 @@ class Refund(models.Model): class Menu(models.Model): name = models.CharField(max_length=255, verbose_name="Nom") - amount = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="Montant") + amount = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="Montant", validators=[MinValueValidator(0)]) barcode = models.CharField(max_length=20, unique=True, verbose_name="Code barre") articles = models.ManyToManyField(Product, verbose_name="Produits") is_active = models.BooleanField(default=False, verbose_name="Actif") + history = HistoricalRecords() def __str__(self): return self.name + @property + def adherent_required(self): + res = False + for article in self.articles.all(): + res = res or article.adherentRequired + return res + class MenuHistory(models.Model): 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) + paymentMethod = models.ForeignKey(PaymentMethod, on_delete=models.PROTECT) date = models.DateTimeField(auto_now_add=True) menu = models.ForeignKey(Menu, on_delete=models.PROTECT) amount = models.DecimalField(max_digits=5, decimal_places=2, default=0) coopeman = models.ForeignKey(User, on_delete=models.PROTECT, related_name="menu_selled") + history = HistoricalRecords() def __str__(self): return "{2} a consommé {0} {1}".format(self.quantity, self.menu, self.customer) @@ -164,6 +183,7 @@ class ConsumptionHistory(models.Model): menu = models.ForeignKey(MenuHistory, on_delete=models.CASCADE, null=True, blank=True) amount = models.DecimalField(max_digits=7, decimal_places=2, default=0) coopeman = models.ForeignKey(User, on_delete=models.PROTECT, related_name="consumption_selled") + history = HistoricalRecords() def __str__(self): return "{0} {1} consommé par {2} le {3} (encaissé par {4})".format(self.quantity, self.product, self.customer, self.date, self.coopeman) @@ -172,6 +192,7 @@ class Consumption(models.Model): 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) + history = HistoricalRecords() def __str__(self): return "Consommation de " + str(self.customer) + " concernant le produit " + str(self.product) diff --git a/gestion/templates/gestion/manage.html b/gestion/templates/gestion/manage.html index 7113482..3b107d6 100644 --- a/gestion/templates/gestion/manage.html +++ b/gestion/templates/gestion/manage.html @@ -97,7 +97,7 @@ {% if forloop.counter0|divisibleby:4 %}