8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-27 15:12:25 +00:00

Ne montre pas tous les articles en vente aux utilisateurs lambdas

This commit is contained in:
Hugo LEVY-FALK 2018-06-17 21:49:59 +02:00
parent 27f646c200
commit beff1bbd1a
4 changed files with 56 additions and 2 deletions

View file

@ -131,6 +131,14 @@ class SelectUserArticleForm(
required=True 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): class SelectClubArticleForm(Form):
""" """
@ -150,6 +158,14 @@ class SelectClubArticleForm(Form):
required=True 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 # TODO : change Facture to Invoice
class NewFactureFormPdf(Form): class NewFactureFormPdf(Form):

View file

@ -0,0 +1,20 @@
# -*- 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'),
),
]

View file

@ -518,6 +518,10 @@ class Article(RevMixin, AclMixin, models.Model):
max_length=255, max_length=255,
verbose_name=_l("Type of cotisation") 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') unique_together = ('name', 'type_user')

View file

@ -99,18 +99,32 @@ 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
is_self_subscription = False
if not request.user.has_perm('cotisations.add_facture') and OptionalUser.get_cached_value('allow_self_subscription'): 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) allowed_payment = Paiement.objects.filter(allow_self_subscription=True)
invoice_form = NewFactureForm(request.POST or None, instance=invoice, allowed_payment=allowed_payment) 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: else:
invoice_form = NewFactureForm(request.POST or None, instance=invoice) 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,
form_kwargs={'is_self_subscription':is_self_subscription}
) )
else: else:
article_formset = formset_factory(SelectUserArticleForm)( 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(): if invoice_form.is_valid() and article_formset.is_valid():