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:
parent
6e416eacfd
commit
2eb0fc816d
7 changed files with 82 additions and 5 deletions
|
@ -55,9 +55,12 @@ class NewFactureForm(FormRevMixin, ModelForm):
|
||||||
"""
|
"""
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
||||||
|
allowed_payment = kwargs.pop('allowed_payment', None)
|
||||||
super(NewFactureForm, self).__init__(*args, prefix=prefix, **kwargs)
|
super(NewFactureForm, self).__init__(*args, prefix=prefix, **kwargs)
|
||||||
# TODO : remove the use of cheque and banque and paiement
|
# TODO : remove the use of cheque and banque and paiement
|
||||||
# for something more generic or at least in English
|
# 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['cheque'].required = False
|
||||||
self.fields['banque'].required = False
|
self.fields['banque'].required = False
|
||||||
self.fields['cheque'].label = _("Cheque number")
|
self.fields['cheque'].label = _("Cheque number")
|
||||||
|
@ -69,6 +72,7 @@ class NewFactureForm(FormRevMixin, ModelForm):
|
||||||
self.fields['paiement'].widget\
|
self.fields['paiement'].widget\
|
||||||
.attrs['data-cheque'] = paiement_list.first().id
|
.attrs['data-cheque'] = paiement_list.first().id
|
||||||
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Facture
|
model = Facture
|
||||||
fields = ['paiement', 'banque', 'cheque']
|
fields = ['paiement', 'banque', 'cheque']
|
||||||
|
@ -231,7 +235,7 @@ class PaiementForm(FormRevMixin, ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Paiement
|
model = Paiement
|
||||||
# TODO : change moyen to method and type_paiement to payment_type
|
# 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):
|
def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
||||||
|
|
|
@ -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'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -46,6 +46,7 @@ from django.utils.translation import ugettext_lazy as _l
|
||||||
from machines.models import regen
|
from machines.models import regen
|
||||||
from re2o.field_permissions import FieldPermissionModelMixin
|
from re2o.field_permissions import FieldPermissionModelMixin
|
||||||
from re2o.mixins import AclMixin, RevMixin
|
from re2o.mixins import AclMixin, RevMixin
|
||||||
|
from preferences.models import OptionalUser
|
||||||
|
|
||||||
|
|
||||||
# TODO : change facture to invoice
|
# 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.")
|
_("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):
|
def __init__(self, *args, **kwargs):
|
||||||
super(Facture, self).__init__(*args, **kwargs)
|
super(Facture, self).__init__(*args, **kwargs)
|
||||||
self.field_permissions = {
|
self.field_permissions = {
|
||||||
|
@ -576,6 +593,10 @@ class Paiement(RevMixin, AclMixin, models.Model):
|
||||||
default=0,
|
default=0,
|
||||||
verbose_name=_l("Payment type")
|
verbose_name=_l("Payment type")
|
||||||
)
|
)
|
||||||
|
allow_self_subscription = models.BooleanField(
|
||||||
|
default=False,
|
||||||
|
verbose_name=_l("Is available for self subscription")
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
permissions = (
|
permissions = (
|
||||||
|
|
|
@ -99,7 +99,11 @@ def new_facture(request, user, userid):
|
||||||
Q(type_user='All') | Q(type_user=request.user.class_name)
|
Q(type_user='All') | Q(type_user=request.user.class_name)
|
||||||
)
|
)
|
||||||
# Building the invocie form and the article formset
|
# 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:
|
if request.user.is_class_club:
|
||||||
article_formset = formset_factory(SelectClubArticleForm)(
|
article_formset = formset_factory(SelectClubArticleForm)(
|
||||||
request.POST or None
|
request.POST or None
|
||||||
|
|
|
@ -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."),
|
||||||
|
),
|
||||||
|
]
|
|
@ -96,6 +96,13 @@ class OptionalUser(AclMixin, PreferencesModel):
|
||||||
default=False,
|
default=False,
|
||||||
help_text="Un nouvel utilisateur peut se créer son compte sur re2o"
|
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(
|
shell_default = models.OneToOneField(
|
||||||
'users.ListShell',
|
'users.ListShell',
|
||||||
on_delete=models.PROTECT,
|
on_delete=models.PROTECT,
|
||||||
|
|
|
@ -166,7 +166,7 @@ non adhérent</span>{% endif %} et votre connexion est {% if users.has_access %}
|
||||||
<tr>
|
<tr>
|
||||||
<th>Solde</th>
|
<th>Solde</th>
|
||||||
<td>{{ users.solde }} €
|
<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' %}">
|
<a class="btn btn-primary btn-sm" style='float:right' role="button" href="{% url 'cotisations:recharge' %}">
|
||||||
<i class="fa fa-euro-sign"></i>
|
<i class="fa fa-euro-sign"></i>
|
||||||
Recharger
|
Recharger
|
||||||
|
@ -287,8 +287,9 @@ non adhérent</span>{% endif %} et votre connexion est {% if users.has_access %}
|
||||||
{% if user_solde %}
|
{% if user_solde %}
|
||||||
<a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:new_facture_solde' user.id %}">
|
<a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:new_facture_solde' user.id %}">
|
||||||
<i class="fa fa-euro-sign"></i>
|
<i class="fa fa-euro-sign"></i>
|
||||||
Ajouter une cotisation par solde</a>{% endif %}{% acl_end %}
|
Ajouter une cotisation par solde</a>
|
||||||
</a>
|
{% endif %}
|
||||||
|
{% acl_end %}
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
{% if facture_list %}
|
{% if facture_list %}
|
||||||
|
|
Loading…
Reference in a new issue