3
0
Fork 0
mirror of https://github.com/nanoy42/coope synced 2024-05-09 10:42:24 +00:00

Add direct_debit

This commit is contained in:
Yoann Pétri 2019-06-23 17:11:58 +02:00
parent ce0acde3d0
commit daafef703a
5 changed files with 55 additions and 5 deletions

View file

@ -23,6 +23,7 @@
<th>Place</th>
<th>Pseudo</th>
<th>Debit</th>
<th>Débit direct (non pris en compte pour le classement)</th>
</tr>
</thead>
<tbody>
@ -30,7 +31,8 @@
<tr>
<th>{{ forloop.counter }}</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>
{%endfor%}
</tbody>

View file

@ -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}))

View 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)
]

View file

@ -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")
"""

View file

@ -38,7 +38,8 @@
</li>
<li><b>Solde : </b>{{user.profile.balance}} €<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><b>Groupe(s) : </b>{{user.groups.all|join:", "}}</li>
<li>