mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-27 15:12:25 +00:00
Vérification de la permission de créditer le solde cohérente.
This commit is contained in:
parent
3dc863a635
commit
f28ad9a12d
4 changed files with 40 additions and 4 deletions
|
@ -116,6 +116,7 @@ class Migration(migrations.Migration):
|
||||||
('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')),
|
('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')),
|
('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', null=True, blank=True)),
|
('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)),
|
||||||
|
('credit_balance_allowed', models.BooleanField(default=False, verbose_name='Allow user to credit their balance')),
|
||||||
],
|
],
|
||||||
bases=(cotisations.payment_methods.mixins.PaymentMethodMixin, models.Model),
|
bases=(cotisations.payment_methods.mixins.PaymentMethodMixin, models.Model),
|
||||||
options={'verbose_name': 'User Balance'},
|
options={'verbose_name': 'User Balance'},
|
||||||
|
|
|
@ -63,6 +63,10 @@ class BalancePayment(PaymentMethodMixin, models.Model):
|
||||||
blank=True,
|
blank=True,
|
||||||
null=True,
|
null=True,
|
||||||
)
|
)
|
||||||
|
credit_balance_allowed = models.BooleanField(
|
||||||
|
verbose_name=_l("Allow user to credit their balance"),
|
||||||
|
default=False,
|
||||||
|
)
|
||||||
|
|
||||||
def end_payment(self, invoice, request):
|
def end_payment(self, invoice, request):
|
||||||
"""Changes the user's balance to pay the invoice. If it is not
|
"""Changes the user's balance to pay the invoice. If it is not
|
||||||
|
@ -108,3 +112,9 @@ class BalancePayment(PaymentMethodMixin, models.Model):
|
||||||
float(user.solde) - float(price) >= self.minimum_balance,
|
float(user.solde) - float(price) >= self.minimum_balance,
|
||||||
_("Your balance is too low for this operation.")
|
_("Your balance is too low for this operation.")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def can_credit_balance(self, user_request):
|
||||||
|
return (
|
||||||
|
len(Paiement.find_allowed_payments(user_request)
|
||||||
|
.exclude(is_balance=True)) > 0
|
||||||
|
) and self.credit_balance_allowed
|
||||||
|
|
|
@ -699,13 +699,31 @@ def index(request):
|
||||||
|
|
||||||
# TODO : change solde to balance
|
# TODO : change solde to balance
|
||||||
@login_required
|
@login_required
|
||||||
@can_create(Facture)
|
|
||||||
@can_edit(User)
|
@can_edit(User)
|
||||||
def credit_solde(request, user, **_kwargs):
|
def credit_solde(request, user, **_kwargs):
|
||||||
"""
|
"""
|
||||||
View used to edit the balance of a user.
|
View used to edit the balance of a user.
|
||||||
Can be use either to increase or decrease a user's balance.
|
Can be use either to increase or decrease a user's balance.
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
|
balance = find_payment_method(Paiement.objects.get(is_balance=True))
|
||||||
|
except Paiement.DoesNotExist:
|
||||||
|
credit_allowed = False
|
||||||
|
else:
|
||||||
|
credit_allowed = (
|
||||||
|
balance is not None
|
||||||
|
and balance.can_credit_balance(request.user)
|
||||||
|
)
|
||||||
|
if not credit_allowed:
|
||||||
|
messages.error(
|
||||||
|
request,
|
||||||
|
_("You are not allowed to credit your balance.")
|
||||||
|
)
|
||||||
|
return redirect(reverse(
|
||||||
|
'users:profil',
|
||||||
|
kwargs={'userid': user.id}
|
||||||
|
))
|
||||||
|
|
||||||
refill_form = RechargeForm(request.POST or None, user=request.user)
|
refill_form = RechargeForm(request.POST or None, user=request.user)
|
||||||
if refill_form.is_valid():
|
if refill_form.is_valid():
|
||||||
price = refill_form.cleaned_data['value']
|
price = refill_form.cleaned_data['value']
|
||||||
|
|
|
@ -67,6 +67,7 @@ from re2o.acl import (
|
||||||
can_view_all,
|
can_view_all,
|
||||||
can_change
|
can_change
|
||||||
)
|
)
|
||||||
|
from cotisations.utils import find_payment_method
|
||||||
|
|
||||||
from .serializers import MailingSerializer, MailingMemberSerializer
|
from .serializers import MailingSerializer, MailingMemberSerializer
|
||||||
from .models import (
|
from .models import (
|
||||||
|
@ -898,9 +899,15 @@ def profil(request, users, **_kwargs):
|
||||||
request.GET.get('order'),
|
request.GET.get('order'),
|
||||||
SortTable.USERS_INDEX_WHITE
|
SortTable.USERS_INDEX_WHITE
|
||||||
)
|
)
|
||||||
balance, _created = Paiement.objects.get_or_create(moyen="solde")
|
try:
|
||||||
user_solde = Facture.can_create(request.user)[0] \
|
balance = find_payment_method(Paiement.objects.get(is_balance=True))
|
||||||
and balance.can_use_payment(request.user)[0]
|
except Paiement.DoesNotExist:
|
||||||
|
user_solde = False
|
||||||
|
else:
|
||||||
|
user_solde = (
|
||||||
|
balance is not None
|
||||||
|
and balance.can_credit_balance(request.user)
|
||||||
|
)
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
'users/profil.html',
|
'users/profil.html',
|
||||||
|
|
Loading…
Reference in a new issue