From daafef703a8608884f9d79e10d32555199f2edec Mon Sep 17 00:00:00 2001 From: nanoy Date: Sun, 23 Jun 2019 17:11:58 +0200 Subject: [PATCH] Add direct_debit --- gestion/templates/gestion/ranking.html | 4 ++- gestion/views.py | 13 ++++++-- users/migrations/0010_auto_20190623_1656.py | 34 +++++++++++++++++++++ users/models.py | 6 +++- users/templates/users/profile.html | 3 +- 5 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 users/migrations/0010_auto_20190623_1656.py diff --git a/gestion/templates/gestion/ranking.html b/gestion/templates/gestion/ranking.html index 0f1d00c..9b6114b 100644 --- a/gestion/templates/gestion/ranking.html +++ b/gestion/templates/gestion/ranking.html @@ -23,6 +23,7 @@ Place Pseudo Debit + Débit direct (non pris en compte pour le classement) @@ -30,7 +31,8 @@ {{ forloop.counter }} {{ customer.username }} - {{ customer.profile.debit }}€ + {{ customer.profile.debit }} € + {{ customer.profile.direct_debit }} € {%endfor%} diff --git a/gestion/views.py b/gestion/views.py index 3b01e78..3249606 100644 --- a/gestion/views.py +++ b/gestion/views.py @@ -100,6 +100,8 @@ def order(request): else: error_message = "Solde insuffisant" raise Exception(error_message) + else: + user.profile.direct_debit += cotisation_history.cotisation.amount cotisation_history.user = user cotisation_history.coopeman = request.user cotisation_history.amount = cotisation.amount @@ -174,6 +176,8 @@ def order(request): else: error_message = "Solde insuffisant" raise Exception(error_message) + else: + user.profile.direct_debit += Decimal(product.amount*quantity) for m in menus: menu = get_object_or_404(Menu, pk=m["pk"]) quantity = int(m["quantity"]) @@ -185,6 +189,8 @@ def order(request): else: error_message = "Solde insuffisant" raise Exception(error_message) + else: + user.profile.direct_debit += Decimal(product.amount*quantity) for article in menu.articles.all(): consumption, _ = Consumption.objects.get_or_create(customer=user, product=article) consumption.quantity += quantity @@ -278,6 +284,8 @@ def cancel_consumption(request, pk): user = consumption.customer if consumption.paymentMethod.affect_balance: user.profile.debit -= consumption.amount + else: + user.profile.direct_debit -= consumption.amount user.profile.alcohol -= Decimal(consumption.quantity * float(consumption.product.deg) * consumption.product.volume * 0.79 /10 /1000) user.save() consumptionT = Consumption.objects.get(customer=user, product=consumption.product) @@ -301,13 +309,14 @@ def cancel_menu(request, pk): user = menu_history.customer if menu_history.paymentMethod.affect_balance: user.profile.debit -= menu_history.amount - user.save() + else: + user.profile.direct_debit -= menu_history.amount for product in manu_history.menu.articles: consumptionT = Consumption.objects.get(customer=user, product=product) consumptionT -= menu_history.quantity consumptionT.save() user.profile.alcohol -= Decimal(menu_history.quantity * float(menu_history.product.deg) * menu_history.product.volume * 0.79 /10 /1000) - user.save() + user.save() menu_history.delete() messages.success(request, "La consommation du menu a bien été annulée") return redirect(reverse('users:profile', kwargs={'pk': user.pk})) diff --git a/users/migrations/0010_auto_20190623_1656.py b/users/migrations/0010_auto_20190623_1656.py new file mode 100644 index 0000000..d0392f0 --- /dev/null +++ b/users/migrations/0010_auto_20190623_1656.py @@ -0,0 +1,34 @@ +# Generated by Django 2.1 on 2019-06-23 14:56 + +from django.db import migrations, models + +def update(apps, schema_editor): + User = apps.get_model('auth', 'User') + ConsumptionHistory = apps.get_model('gestion', 'ConsumptionHistory') + for u in User.objects.all(): + chs = ConsumptionHistory.objects.filter(customer=u).filter(paymentMethod__affect_balance=False) + u.profile.direct_debit = sum([x.amount for x in chs]) + u.profile.save() + +def reverse(apps, schema_editor): + pass + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0009_auto_20190623_1437'), + ] + + operations = [ + migrations.AddField( + model_name='historicalprofile', + name='direct_debit', + field=models.DecimalField(decimal_places=2, default=0, max_digits=7, verbose_name='Débit (non compte)'), + ), + migrations.AddField( + model_name='profile', + name='direct_debit', + field=models.DecimalField(decimal_places=2, default=0, max_digits=7, verbose_name='Débit (non compte)'), + ), + migrations.RunPython(update, reverse) + ] diff --git a/users/models.py b/users/models.py index b58c509..c719268 100644 --- a/users/models.py +++ b/users/models.py @@ -123,7 +123,11 @@ class Profile(models.Model): """ debit = models.DecimalField(max_digits=7, decimal_places=2, default=0, verbose_name="Débit") """ - Amount of money, in euros, spent form the account + Amount of money, in euros, spent from the account + """ + direct_debit = models.DecimalField(max_digits=7, decimal_places=2, default=0, verbose_name="Débit (non compte)") + """ + Amount of money, in euro, spent with other mean than the account """ school = models.ForeignKey(School, on_delete=models.PROTECT, blank=True, null=True, verbose_name="École") """ diff --git a/users/templates/users/profile.html b/users/templates/users/profile.html index 45ede49..0b90ecf 100644 --- a/users/templates/users/profile.html +++ b/users/templates/users/profile.html @@ -38,7 +38,8 @@
  • Solde : {{user.profile.balance}} € Crédit : {{user.profile.credit}} € - Débit : {{user.profile.debit}} € + Débit : {{user.profile.debit}} € + Débit direct : {{user.profile.direct_debit}}
  • Groupe(s) : {{user.groups.all|join:", "}}