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

Paiement de cotisation en ligne possible pour les utilisateurs normaux (désactivable)

This commit is contained in:
Hugo LEVY-FALK 2018-06-17 17:33:49 +02:00
parent 6e416eacfd
commit 2eb0fc816d
7 changed files with 82 additions and 5 deletions

View file

@ -55,9 +55,12 @@ class NewFactureForm(FormRevMixin, ModelForm):
"""
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
allowed_payment = kwargs.pop('allowed_payment', None)
super(NewFactureForm, self).__init__(*args, prefix=prefix, **kwargs)
# TODO : remove the use of cheque and banque and paiement
# for something more generic or at least in English
if allowed_payment:
self.fields['paiement'].queryset = allowed_payment
self.fields['cheque'].required = False
self.fields['banque'].required = False
self.fields['cheque'].label = _("Cheque number")
@ -69,6 +72,7 @@ class NewFactureForm(FormRevMixin, ModelForm):
self.fields['paiement'].widget\
.attrs['data-cheque'] = paiement_list.first().id
class Meta:
model = Facture
fields = ['paiement', 'banque', 'cheque']
@ -231,7 +235,7 @@ class PaiementForm(FormRevMixin, ModelForm):
class Meta:
model = Paiement
# TODO : change moyen to method and type_paiement to payment_type
fields = ['moyen', 'type_paiement']
fields = ['moyen', 'type_paiement', 'allow_self_subscription']
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-06-17 14:59
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('cotisations', '0029_auto_20180414_2056'),
]
operations = [
migrations.AddField(
model_name='paiement',
name='allow_self_subscription',
field=models.BooleanField(default=False, verbose_name='Is available for self subscription'),
),
]

View file

@ -46,6 +46,7 @@ from django.utils.translation import ugettext_lazy as _l
from machines.models import regen
from re2o.field_permissions import FieldPermissionModelMixin
from re2o.mixins import AclMixin, RevMixin
from preferences.models import OptionalUser
# TODO : change facture to invoice
@ -213,6 +214,22 @@ class Facture(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
_("You don't have the right to edit an invoice.")
)
@staticmethod
def can_create(user_request, *_args, **_kwargs):
"""Check if an user can create an invoice.
:param user_request: The user who wants to create an invoice.
:return: a message and a boolean which is True if the user can create
an invoice or if the `options.allow_self_subscription` is set.
"""
if OptionalUser.get_cached_value('allow_self_subscription'):
return True, None
return (
user_request.has_perm('cotisations.add_facture'),
_("You don't have the right to create an invoice.")
)
def __init__(self, *args, **kwargs):
super(Facture, self).__init__(*args, **kwargs)
self.field_permissions = {
@ -576,6 +593,10 @@ class Paiement(RevMixin, AclMixin, models.Model):
default=0,
verbose_name=_l("Payment type")
)
allow_self_subscription = models.BooleanField(
default=False,
verbose_name=_l("Is available for self subscription")
)
class Meta:
permissions = (

View file

@ -99,7 +99,11 @@ def new_facture(request, user, userid):
Q(type_user='All') | Q(type_user=request.user.class_name)
)
# Building the invocie form and the article formset
invoice_form = NewFactureForm(request.POST or None, instance=invoice)
if not request.user.has_perm('cotisations.add_facture') and OptionalUser.get_cached_value('allow_self_subscription'):
allowed_payment = Paiement.objects.filter(allow_self_subscription=True)
invoice_form = NewFactureForm(request.POST or None, instance=invoice, allowed_payment=allowed_payment)
else:
invoice_form = NewFactureForm(request.POST or None, instance=invoice)
if request.user.is_class_club:
article_formset = formset_factory(SelectClubArticleForm)(
request.POST or None

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-06-17 15:12
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('preferences', '0034_auto_20180416_1120'),
]
operations = [
migrations.AddField(
model_name='optionaluser',
name='allow_self_subscription',
field=models.BooleanField(default=False, help_text="Autoriser les utilisateurs à cotiser par eux mêmes via les moyens de paiement permettant l'auto-cotisation."),
),
]

View file

@ -96,6 +96,13 @@ class OptionalUser(AclMixin, PreferencesModel):
default=False,
help_text="Un nouvel utilisateur peut se créer son compte sur re2o"
)
allow_self_subscription = models.BooleanField(
default=False,
help_text=(
"Autoriser les utilisateurs à cotiser par eux mêmes via les"
" moyens de paiement permettant l'auto-cotisation."
)
)
shell_default = models.OneToOneField(
'users.ListShell',
on_delete=models.PROTECT,

View file

@ -166,7 +166,7 @@ non adhérent</span>{% endif %} et votre connexion est {% if users.has_access %}
<tr>
<th>Solde</th>
<td>{{ users.solde }} €
{% if allow_online_payment %}
{% if user_solde and allow_online_payment %}
<a class="btn btn-primary btn-sm" style='float:right' role="button" href="{% url 'cotisations:recharge' %}">
<i class="fa fa-euro-sign"></i>
Recharger
@ -287,8 +287,9 @@ non adhérent</span>{% endif %} et votre connexion est {% if users.has_access %}
{% if user_solde %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:new_facture_solde' user.id %}">
<i class="fa fa-euro-sign"></i>
Ajouter une cotisation par solde</a>{% endif %}{% acl_end %}
</a>
Ajouter une cotisation par solde</a>
{% endif %}
{% acl_end %}
</div>
<div class="panel-body">
{% if facture_list %}