diff --git a/cotisations/forms.py b/cotisations/forms.py index 303ee32e..c4e02397 100644 --- a/cotisations/forms.py +++ b/cotisations/forms.py @@ -41,6 +41,8 @@ from django.db.models import Q from django.forms import ModelForm, Form from django.core.validators import MinValueValidator,MaxValueValidator from .models import Article, Paiement, Facture, Banque +from preferences.models import OptionalUser +from users.models import User from re2o.field_permissions import FieldPermissionFormMixin @@ -287,3 +289,16 @@ class RechargeForm(Form): min_value=0.01, validators = [] ) + + def __init__(self, *args, **kwargs): + self.user = kwargs.pop('user') + super(RechargeForm, self).__init__(*args, **kwargs) + + def clean_value(self): + value = self.cleaned_data['value'] + options, _created = OptionalUser.objects.get_or_create() + if value < options.min_online_payment: + raise forms.ValidationError("Montant inférieur au montant minimal de paiement en ligne (%s) €" % options.min_online_payment) + if value + self.user.solde > options.max_solde: + raise forms.ValidationError("Le solde ne peux excéder %s " % options.max_solde) + return value diff --git a/cotisations/payment.py b/cotisations/payment.py index ab7260b2..b2e684d7 100644 --- a/cotisations/payment.py +++ b/cotisations/payment.py @@ -76,7 +76,8 @@ def ipn(request): return HttpResponse("HTTP/1.0 200 OK") -def comnpay(facture, host): +def comnpay(facture, request): + host = request.get_host() p = ComnpayPayment( "DEMO", "DEMO", diff --git a/cotisations/views.py b/cotisations/views.py index 10e85ed0..24320b2b 100644 --- a/cotisations/views.py +++ b/cotisations/views.py @@ -687,7 +687,7 @@ def new_facture_solde(request, userid): @login_required def recharge(request): - f = RechargeForm(request.POST or None) + f = RechargeForm(request.POST or None, user=request.user) if f.is_valid(): facture = Facture(user=request.user) paiement, _created = Paiement.objects.get_or_create(moyen='Rechargement en ligne') @@ -702,6 +702,6 @@ def recharge(request): ) v.save() options, _created = AssoOption.objects.get_or_create() - content = payment.PAYMENT_SYSTEM[options.payment](facture, request.get_host()) + content = payment.PAYMENT_SYSTEM[options.payment](facture, request) return render(request, 'cotisations/payment.html', content) return form({'rechargeform':f}, 'cotisations/recharge.html', request) diff --git a/preferences/forms.py b/preferences/forms.py index 1fa42efc..03fa6360 100644 --- a/preferences/forms.py +++ b/preferences/forms.py @@ -49,6 +49,8 @@ class EditOptionalUserForm(ModelForm): self.fields['user_solde'].label = 'Activation du solde pour\ les utilisateurs' self.fields['max_solde'].label = 'Solde maximum' + self.fields['min_online_payment'].label = 'Montant de rechargement minimum en ligne' + self.fields['self_adhesion'].label = 'Auto inscription' class EditOptionalMachineForm(ModelForm): diff --git a/preferences/migrations/0031_optionaluser_self_adhesion.py b/preferences/migrations/0031_optionaluser_self_adhesion.py new file mode 100644 index 00000000..48a95044 --- /dev/null +++ b/preferences/migrations/0031_optionaluser_self_adhesion.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2018-01-12 11:34 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('preferences', '0030_auto_20180111_2346'), + ] + + operations = [ + migrations.AddField( + model_name='optionaluser', + name='self_adhesion', + field=models.BooleanField(default=False, help_text='Un nouvel utilisateur peut se créer son compte sur re2o'), + ), + ] diff --git a/preferences/migrations/0032_optionaluser_min_online_payment.py b/preferences/migrations/0032_optionaluser_min_online_payment.py new file mode 100644 index 00000000..ef78d012 --- /dev/null +++ b/preferences/migrations/0032_optionaluser_min_online_payment.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2018-01-13 16:43 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('preferences', '0031_optionaluser_self_adhesion'), + ] + + operations = [ + migrations.AddField( + model_name='optionaluser', + name='min_online_payment', + field=models.DecimalField(decimal_places=2, default=10, max_digits=5), + ), + ] diff --git a/preferences/models.py b/preferences/models.py index 44bb6580..d4c25c24 100644 --- a/preferences/models.py +++ b/preferences/models.py @@ -46,11 +46,20 @@ class OptionalUser(models.Model): decimal_places=2, default=50 ) + min_online_payment = models.DecimalField( + max_digits=5, + decimal_places=2, + default=10 + ) gpg_fingerprint = models.BooleanField(default=True) all_can_create = models.BooleanField( default=False, help_text="Tous les users peuvent en créer d'autres", ) + self_adhesion = models.BooleanField( + default=False, + help_text="Un nouvel utilisateur peut se créer son compte sur re2o" + ) class Meta: permissions = ( diff --git a/preferences/templates/preferences/display_preferences.html b/preferences/templates/preferences/display_preferences.html index d483cdb4..45a4fd11 100644 --- a/preferences/templates/preferences/display_preferences.html +++ b/preferences/templates/preferences/display_preferences.html @@ -54,11 +54,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,