mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-23 23:43:47 +00:00
Plafond de solde optionnel + affiche le plafond de solde lors de la recharge.
This commit is contained in:
parent
8c985a6e3a
commit
36741e21a6
5 changed files with 15 additions and 14 deletions
|
@ -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\
|
||||
.objects.get_or_create()
|
||||
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."),
|
||||
max_digits=5,
|
||||
decimal_places=2,
|
||||
default=50
|
||||
default=50,
|
||||
blank=True,
|
||||
null=True,
|
||||
)
|
||||
|
||||
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 %}
|
||||
<p>
|
||||
{% 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):
|
|||
number=1
|
||||
)
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue