8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 11:23:10 +00:00

Montant minimal de rechargement + refactor de la fonction payment + self adhesion

This commit is contained in:
Gabriel Detraz 2018-01-14 20:15:21 +01:00 committed by root
parent 5319ed266c
commit a71e01e18a
8 changed files with 80 additions and 7 deletions

View file

@ -41,6 +41,8 @@ from django.db.models import Q
from django.forms import ModelForm, Form from django.forms import ModelForm, Form
from django.core.validators import MinValueValidator,MaxValueValidator from django.core.validators import MinValueValidator,MaxValueValidator
from .models import Article, Paiement, Facture, Banque from .models import Article, Paiement, Facture, Banque
from preferences.models import OptionalUser
from users.models import User
from re2o.field_permissions import FieldPermissionFormMixin from re2o.field_permissions import FieldPermissionFormMixin
@ -287,3 +289,16 @@ class RechargeForm(Form):
min_value=0.01, min_value=0.01,
validators = [] 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

View file

@ -76,7 +76,8 @@ def ipn(request):
return HttpResponse("HTTP/1.0 200 OK") return HttpResponse("HTTP/1.0 200 OK")
def comnpay(facture, host): def comnpay(facture, request):
host = request.get_host()
p = ComnpayPayment( p = ComnpayPayment(
"DEMO", "DEMO",
"DEMO", "DEMO",

View file

@ -687,7 +687,7 @@ def new_facture_solde(request, userid):
@login_required @login_required
def recharge(request): def recharge(request):
f = RechargeForm(request.POST or None) f = RechargeForm(request.POST or None, user=request.user)
if f.is_valid(): if f.is_valid():
facture = Facture(user=request.user) facture = Facture(user=request.user)
paiement, _created = Paiement.objects.get_or_create(moyen='Rechargement en ligne') paiement, _created = Paiement.objects.get_or_create(moyen='Rechargement en ligne')
@ -702,6 +702,6 @@ def recharge(request):
) )
v.save() v.save()
options, _created = AssoOption.objects.get_or_create() 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 render(request, 'cotisations/payment.html', content)
return form({'rechargeform':f}, 'cotisations/recharge.html', request) return form({'rechargeform':f}, 'cotisations/recharge.html', request)

View file

@ -49,6 +49,8 @@ class EditOptionalUserForm(ModelForm):
self.fields['user_solde'].label = 'Activation du solde pour\ self.fields['user_solde'].label = 'Activation du solde pour\
les utilisateurs' les utilisateurs'
self.fields['max_solde'].label = 'Solde maximum' 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): class EditOptionalMachineForm(ModelForm):

View file

@ -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'),
),
]

View file

@ -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),
),
]

View file

@ -46,11 +46,20 @@ class OptionalUser(models.Model):
decimal_places=2, decimal_places=2,
default=50 default=50
) )
min_online_payment = models.DecimalField(
max_digits=5,
decimal_places=2,
default=10
)
gpg_fingerprint = models.BooleanField(default=True) gpg_fingerprint = models.BooleanField(default=True)
all_can_create = models.BooleanField( all_can_create = models.BooleanField(
default=False, default=False,
help_text="Tous les users peuvent en créer d'autres", 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: class Meta:
permissions = ( permissions = (

View file

@ -54,11 +54,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<tr> <tr>
<th>Creations d'users par tous</th> <th>Creations d'users par tous</th>
<td>{{ useroptions.all_can_create }}</td> <td>{{ useroptions.all_can_create }}</td>
{% if useroptions.user_solde %} <th>Auto inscription</th>
<th>Solde maximum</th> <td>{{ useroptions.self_adhesion }}</td>
<td>{{ useroptions.max_solde }}</td>
{% endif %}
</tr> </tr>
{% if useroptions.user_solde %}
<tr>
<th>Solde maximum</th>
<td>{{ useroptions.max_solde }}</td>
<th>Montant minimal de rechargement en ligne</th>
<td>{{ useroptions.min_online_payment }}</td>
</tr>
{% endif %}
</table> </table>
<h4>Préférences machines</h4> <h4>Préférences machines</h4>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:edit-options' 'OptionalMachine' %}"> <a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:edit-options' 'OptionalMachine' %}">