mirror of
https://github.com/nanoy42/coope
synced 2024-11-22 03:13:12 +00:00
Add direct_debit
This commit is contained in:
parent
ce0acde3d0
commit
daafef703a
5 changed files with 55 additions and 5 deletions
|
@ -23,6 +23,7 @@
|
||||||
<th>Place</th>
|
<th>Place</th>
|
||||||
<th>Pseudo</th>
|
<th>Pseudo</th>
|
||||||
<th>Debit</th>
|
<th>Debit</th>
|
||||||
|
<th>Débit direct (non pris en compte pour le classement)</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -30,7 +31,8 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th>{{ forloop.counter }}</th>
|
<th>{{ forloop.counter }}</th>
|
||||||
<th><a href="{% url 'users:profile' customer.pk %}">{{ customer.username }}</a></th>
|
<th><a href="{% url 'users:profile' customer.pk %}">{{ customer.username }}</a></th>
|
||||||
<th>{{ customer.profile.debit }}€</th>
|
<th>{{ customer.profile.debit }} €</th>
|
||||||
|
<th>{{ customer.profile.direct_debit }} €</th>
|
||||||
</tr>
|
</tr>
|
||||||
{%endfor%}
|
{%endfor%}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
@ -100,6 +100,8 @@ def order(request):
|
||||||
else:
|
else:
|
||||||
error_message = "Solde insuffisant"
|
error_message = "Solde insuffisant"
|
||||||
raise Exception(error_message)
|
raise Exception(error_message)
|
||||||
|
else:
|
||||||
|
user.profile.direct_debit += cotisation_history.cotisation.amount
|
||||||
cotisation_history.user = user
|
cotisation_history.user = user
|
||||||
cotisation_history.coopeman = request.user
|
cotisation_history.coopeman = request.user
|
||||||
cotisation_history.amount = cotisation.amount
|
cotisation_history.amount = cotisation.amount
|
||||||
|
@ -174,6 +176,8 @@ def order(request):
|
||||||
else:
|
else:
|
||||||
error_message = "Solde insuffisant"
|
error_message = "Solde insuffisant"
|
||||||
raise Exception(error_message)
|
raise Exception(error_message)
|
||||||
|
else:
|
||||||
|
user.profile.direct_debit += Decimal(product.amount*quantity)
|
||||||
for m in menus:
|
for m in menus:
|
||||||
menu = get_object_or_404(Menu, pk=m["pk"])
|
menu = get_object_or_404(Menu, pk=m["pk"])
|
||||||
quantity = int(m["quantity"])
|
quantity = int(m["quantity"])
|
||||||
|
@ -185,6 +189,8 @@ def order(request):
|
||||||
else:
|
else:
|
||||||
error_message = "Solde insuffisant"
|
error_message = "Solde insuffisant"
|
||||||
raise Exception(error_message)
|
raise Exception(error_message)
|
||||||
|
else:
|
||||||
|
user.profile.direct_debit += Decimal(product.amount*quantity)
|
||||||
for article in menu.articles.all():
|
for article in menu.articles.all():
|
||||||
consumption, _ = Consumption.objects.get_or_create(customer=user, product=article)
|
consumption, _ = Consumption.objects.get_or_create(customer=user, product=article)
|
||||||
consumption.quantity += quantity
|
consumption.quantity += quantity
|
||||||
|
@ -278,6 +284,8 @@ def cancel_consumption(request, pk):
|
||||||
user = consumption.customer
|
user = consumption.customer
|
||||||
if consumption.paymentMethod.affect_balance:
|
if consumption.paymentMethod.affect_balance:
|
||||||
user.profile.debit -= consumption.amount
|
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.profile.alcohol -= Decimal(consumption.quantity * float(consumption.product.deg) * consumption.product.volume * 0.79 /10 /1000)
|
||||||
user.save()
|
user.save()
|
||||||
consumptionT = Consumption.objects.get(customer=user, product=consumption.product)
|
consumptionT = Consumption.objects.get(customer=user, product=consumption.product)
|
||||||
|
@ -301,13 +309,14 @@ def cancel_menu(request, pk):
|
||||||
user = menu_history.customer
|
user = menu_history.customer
|
||||||
if menu_history.paymentMethod.affect_balance:
|
if menu_history.paymentMethod.affect_balance:
|
||||||
user.profile.debit -= menu_history.amount
|
user.profile.debit -= menu_history.amount
|
||||||
user.save()
|
else:
|
||||||
|
user.profile.direct_debit -= menu_history.amount
|
||||||
for product in manu_history.menu.articles:
|
for product in manu_history.menu.articles:
|
||||||
consumptionT = Consumption.objects.get(customer=user, product=product)
|
consumptionT = Consumption.objects.get(customer=user, product=product)
|
||||||
consumptionT -= menu_history.quantity
|
consumptionT -= menu_history.quantity
|
||||||
consumptionT.save()
|
consumptionT.save()
|
||||||
user.profile.alcohol -= Decimal(menu_history.quantity * float(menu_history.product.deg) * menu_history.product.volume * 0.79 /10 /1000)
|
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()
|
menu_history.delete()
|
||||||
messages.success(request, "La consommation du menu a bien été annulée")
|
messages.success(request, "La consommation du menu a bien été annulée")
|
||||||
return redirect(reverse('users:profile', kwargs={'pk': user.pk}))
|
return redirect(reverse('users:profile', kwargs={'pk': user.pk}))
|
||||||
|
|
34
users/migrations/0010_auto_20190623_1656.py
Normal file
34
users/migrations/0010_auto_20190623_1656.py
Normal file
|
@ -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)
|
||||||
|
]
|
|
@ -123,7 +123,11 @@ class Profile(models.Model):
|
||||||
"""
|
"""
|
||||||
debit = models.DecimalField(max_digits=7, decimal_places=2, default=0, verbose_name="Débit")
|
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")
|
school = models.ForeignKey(School, on_delete=models.PROTECT, blank=True, null=True, verbose_name="École")
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -38,7 +38,8 @@
|
||||||
</li>
|
</li>
|
||||||
<li><b>Solde : </b>{{user.profile.balance}} €<span class="tabulation">
|
<li><b>Solde : </b>{{user.profile.balance}} €<span class="tabulation">
|
||||||
<b>Crédit : </b>{{user.profile.credit}} €</span><span class="tabulation">
|
<b>Crédit : </b>{{user.profile.credit}} €</span><span class="tabulation">
|
||||||
<b>Débit : </b>{{user.profile.debit}} €</span>
|
<b>Débit : </b>{{user.profile.debit}} €</span><span class="tabulation">
|
||||||
|
<b>Débit direct : </b>{{user.profile.direct_debit}}</b></span>
|
||||||
</li>
|
</li>
|
||||||
<li><b>Groupe(s) : </b>{{user.groups.all|join:", "}}</li>
|
<li><b>Groupe(s) : </b>{{user.groups.all|join:", "}}</li>
|
||||||
<li>
|
<li>
|
||||||
|
|
Loading…
Reference in a new issue