From 40bacfa40cd838741c758188ec3a217be2696f23 Mon Sep 17 00:00:00 2001 From: nanoy Date: Sun, 22 Sep 2019 20:44:33 +0200 Subject: [PATCH] Some verifications in order --- gestion/views.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gestion/views.py b/gestion/views.py index 4faf317..810d5bf 100644 --- a/gestion/views.py +++ b/gestion/views.py @@ -93,8 +93,12 @@ def order(request): raise Exception("Pas de commande.") if(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"]) + 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.save() user.profile.credit += reload_amount @@ -104,6 +108,8 @@ def order(request): cotisation = Cotisation.objects.get(pk=co['pk']) for i in range(co['quantity']): 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(user.profile.balance >= cotisation_history.cotisation.amount): user.profile.debit += cotisation_history.cotisation.amount