Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

Commit 36741e21 authored by Levy--Falk Hugo's avatar Levy--Falk Hugo

Plafond de solde optionnel + affiche le plafond de solde lors de la recharge.

parent 8c985a6e
......@@ -284,7 +284,7 @@ class RechargeForm(FormRevMixin, Form):
_("Select a payment method")
self.fields['payment'].queryset = Paiement.find_allowed_payments(user)
def clean_value(self):
def clean(self):
Returns a cleaned value from the received form by validating
the value is well inside the possible limits
......@@ -292,18 +292,12 @@ class RechargeForm(FormRevMixin, Form):
value = self.cleaned_data['value']
balance_method, _created = balance.PaymentMethod\
if value < balance_method.minimum_balance:
raise forms.ValidationError(
_("Requested amount is too small. Minimum amount possible : \
%(min_online_amount)s €.") % {
'min_online_amount': balance_method.minimum_balance
if value + self.user.solde > balance_method.maximum_balance:
if balance_method.maximum_balance is not None and \
value + self.user.solde > balance_method.maximum_balance:
raise forms.ValidationError(
_("Requested amount is too high. Your balance can't exceed \
%(max_online_balance)s €.") % {
'max_online_balance': balance_method.maximum_balance
return value
return self.cleaned_data
......@@ -112,7 +112,7 @@ class Migration(migrations.Migration):
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('minimum_balance', models.DecimalField(decimal_places=2, default=0, help_text='The minimal amount of money allowed for the balance at the end of a payment. You can specify negative amount.', max_digits=5, verbose_name='Minimum balance')),
('payment', models.OneToOneField(editable=False, on_delete=django.db.models.deletion.CASCADE, related_name='payment_method', to='cotisations.Paiement')),
('maximum_balance', models.DecimalField(decimal_places=2, default=50, help_text='The maximal amount of money allowed for the balance.', max_digits=5, verbose_name='Maximum balance')),
('maximum_balance', models.DecimalField(decimal_places=2, default=50, help_text='The maximal amount of money allowed for the balance.', max_digits=5, verbose_name='Maximum balance', null=True, blank=True)),
bases=(cotisations.payment_methods.mixins.PaymentMethodMixin, models.Model),
......@@ -55,7 +55,9 @@ class BalancePayment(PaymentMethodMixin, models.Model):
help_text=_l("The maximal amount of money allowed for the balance."),
def end_payment(self, invoice, request):
......@@ -39,6 +39,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% else %}
<h3>{% trans "New invoice" %}</h3>
{% endif %}
{% if max_balance %}
<h4>{% trans "Maximum allowed balance : "%}{{max_balance}} €</h4>
{% endif %}
{% if balance is not None %}
{% trans "Current balance :" %} {{ balance }} €
......@@ -32,7 +32,7 @@ from __future__ import unicode_literals
import os
from django.urls import reverse
from django.shortcuts import render, redirect
from django.shortcuts import render, redirect, get_object_or_404
from django.contrib.auth.decorators import login_required
from django.contrib import messages
from django.db.models import ProtectedError
......@@ -696,9 +696,11 @@ def credit_solde(request, user, **_kwargs):
return invoice.paiement.end_payment(invoice, request)
p = get_object_or_404(Paiement, is_balance=True)
return form({
'factureform': refill_form,
'balance': request.user.solde,
'title': _("Refill your balance"),
'action_name': _("Pay")
'action_name': _("Pay"),
'max_balance': p.payment_method.maximum_balance,
}, 'cotisations/facture.html', request)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment