From 2eb0fc816d07bbc6c2b6a44ba77d47e55310ddbc Mon Sep 17 00:00:00 2001 From: Hugo LEVY-FALK Date: Sun, 17 Jun 2018 17:33:49 +0200 Subject: [PATCH] =?UTF-8?q?Paiement=20de=20cotisation=20en=20ligne=20possi?= =?UTF-8?q?ble=20pour=20les=20utilisateurs=20normaux=20(d=C3=A9sactivable)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cotisations/forms.py | 6 +++++- .../0030_paiement_allow_self_subscription.py | 20 ++++++++++++++++++ cotisations/models.py | 21 +++++++++++++++++++ cotisations/views.py | 6 +++++- ...35_optionaluser_allow_self_subscription.py | 20 ++++++++++++++++++ preferences/models.py | 7 +++++++ users/templates/users/profil.html | 7 ++++--- 7 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 cotisations/migrations/0030_paiement_allow_self_subscription.py create mode 100644 preferences/migrations/0035_optionaluser_allow_self_subscription.py diff --git a/cotisations/forms.py b/cotisations/forms.py index a6647a45..d73ad6a3 100644 --- a/cotisations/forms.py +++ b/cotisations/forms.py @@ -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__) diff --git a/cotisations/migrations/0030_paiement_allow_self_subscription.py b/cotisations/migrations/0030_paiement_allow_self_subscription.py new file mode 100644 index 00000000..4e9ab60b --- /dev/null +++ b/cotisations/migrations/0030_paiement_allow_self_subscription.py @@ -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'), + ), + ] diff --git a/cotisations/models.py b/cotisations/models.py index c4c6d4af..5c3a310a 100644 --- a/cotisations/models.py +++ b/cotisations/models.py @@ -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 = ( diff --git a/cotisations/views.py b/cotisations/views.py index 25b676c1..1b8fc80b 100644 --- a/cotisations/views.py +++ b/cotisations/views.py @@ -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 diff --git a/preferences/migrations/0035_optionaluser_allow_self_subscription.py b/preferences/migrations/0035_optionaluser_allow_self_subscription.py new file mode 100644 index 00000000..5fc45714 --- /dev/null +++ b/preferences/migrations/0035_optionaluser_allow_self_subscription.py @@ -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."), + ), + ] diff --git a/preferences/models.py b/preferences/models.py index 560fa30f..eeae30f9 100644 --- a/preferences/models.py +++ b/preferences/models.py @@ -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, diff --git a/users/templates/users/profil.html b/users/templates/users/profil.html index abba61a2..25b4992e 100644 --- a/users/templates/users/profil.html +++ b/users/templates/users/profil.html @@ -166,7 +166,7 @@ non adhérent{% endif %} et votre connexion est {% if users.has_access %} Solde {{ users.solde }} € - {% if allow_online_payment %} + {% if user_solde and allow_online_payment %} Recharger @@ -287,8 +287,9 @@ non adhérent{% endif %} et votre connexion est {% if users.has_access %} {% if user_solde %} - Ajouter une cotisation par solde{% endif %}{% acl_end %} - + Ajouter une cotisation par solde + {% endif %} + {% acl_end %}
{% if facture_list %}