3
0
Fork 0
mirror of https://github.com/nanoy42/coope synced 2024-12-23 23:43:47 +00:00

Some verifications in order

This commit is contained in:
Yoann Pétri 2019-09-22 20:44:33 +02:00
parent 4273692005
commit 40bacfa40c

View file

@ -93,8 +93,12 @@ def order(request):
raise Exception("Pas de commande.") raise Exception("Pas de commande.")
if(reloads): if(reloads):
for reload in reloads: for reload in reloads:
reload_payment_method = get_object_or_404(PaymentMethod, pk=reload["payment_method"])
reload_amount = Decimal(reload["value"])*Decimal(reload["quantity"]) reload_amount = Decimal(reload["value"])*Decimal(reload["quantity"])
if(reload_amount <= 0):
raise Exception("Impossible d'effectuer un rechargement négatif")
reload_payment_method = get_object_or_404(PaymentMethod, pk=reload["payment_method"])
if not reload_payment_method.is_usable_in_reload:
raise Exception("Le moyen de paiement ne peut pas être utilisé pour les rechargements.")
reload_entry = Reload(customer=user, amount=reload_amount, PaymentMethod=reload_payment_method, coopeman=request.user) reload_entry = Reload(customer=user, amount=reload_amount, PaymentMethod=reload_payment_method, coopeman=request.user)
reload_entry.save() reload_entry.save()
user.profile.credit += reload_amount user.profile.credit += reload_amount
@ -104,6 +108,8 @@ def order(request):
cotisation = Cotisation.objects.get(pk=co['pk']) cotisation = Cotisation.objects.get(pk=co['pk'])
for i in range(co['quantity']): for i in range(co['quantity']):
cotisation_history = CotisationHistory(cotisation=cotisation) cotisation_history = CotisationHistory(cotisation=cotisation)
if not paymentMethod.is_usable_in_cotisation:
raise Exception("Le moyen de paiement ne peut pas être utilisé pour les cotisations.")
if(paymentMethod.affect_balance): if(paymentMethod.affect_balance):
if(user.profile.balance >= cotisation_history.cotisation.amount): if(user.profile.balance >= cotisation_history.cotisation.amount):
user.profile.debit += cotisation_history.cotisation.amount user.profile.debit += cotisation_history.cotisation.amount