Commit beff1bbd authored by Levy--Falk Hugo's avatar Levy--Falk Hugo

Ne montre pas tous les articles en vente aux utilisateurs lambdas

parent 27f646c2
......@@ -131,6 +131,14 @@ class SelectUserArticleForm(
required=True
)
def __init__(self, *args, **kwargs):
self_subscription = kwargs.pop('is_self_subscription', False)
super(SelectUserArticleForm, self).__init__(*args, **kwargs)
if self_subscription:
self.fields['article'].queryset = Article.objects.filter(
Q(type_user='All') | Q(type_user='Adherent')
).filter(allow_self_subscription=True)
class SelectClubArticleForm(Form):
"""
......@@ -150,6 +158,14 @@ class SelectClubArticleForm(Form):
required=True
)
def __init__(self, *args, **kwargs):
self_subscription = kwargs.pop('is_self_subscription', False)
super(SelectClubArticleForm, self).__init__(*args, **kwargs)
if self_subscription:
self.fields['article'].queryset = Article.objects.filter(
Q(type_user='All') | Q(type_user='Club')
).filter(allow_self_subscription=True)
# TODO : change Facture to Invoice
class NewFactureFormPdf(Form):
......
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-06-17 17:13
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('cotisations', '0030_paiement_allow_self_subscription'),
]
operations = [
migrations.AddField(
model_name='article',
name='allow_self_subscription',
field=models.BooleanField(default=False, verbose_name='Is available for self subscription'),
),
]
......@@ -518,6 +518,10 @@ class Article(RevMixin, AclMixin, models.Model):
max_length=255,
verbose_name=_l("Type of cotisation")
)
allow_self_subscription = models.BooleanField(
default=False,
verbose_name=_l("Is available for self subscription")
)
unique_together = ('name', 'type_user')
......
......@@ -99,18 +99,32 @@ 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
is_self_subscription = False
if not request.user.has_perm('cotisations.add_facture') and OptionalUser.get_cached_value('allow_self_subscription'):
is_self_subscription = True
article_list = article_list.filter(allow_self_subscription=True)
allowed_payment = Paiement.objects.filter(allow_self_subscription=True)
invoice_form = NewFactureForm(request.POST or None, instance=invoice, allowed_payment=allowed_payment)
elif not OptionalUser.get_cached_value('allow_self_subscription'):
messages.error(
request,
_("You cannot subscribe. Please ask to the staff.")
)
return redirect(reverse(
'users:profil',
kwargs={'userid': userid}
))
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
request.POST or None,
form_kwargs={'is_self_subscription':is_self_subscription}
)
else:
article_formset = formset_factory(SelectUserArticleForm)(
request.POST or None
request.POST or None,
form_kwargs={'is_self_subscription':is_self_subscription}
)
if invoice_form.is_valid() and article_formset.is_valid():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment