From 9b080450ab3d474625bcaca94fabd6fade1681c9 Mon Sep 17 00:00:00 2001 From: Hugo LEVY-FALK Date: Sat, 1 Sep 2018 12:26:15 +0200 Subject: [PATCH] Fix le choix des articles pour les custom invoices --- cotisations/forms.py | 2 +- cotisations/models.py | 6 ++++-- cotisations/views.py | 5 ++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cotisations/forms.py b/cotisations/forms.py index 9194597a..5ada2fa0 100644 --- a/cotisations/forms.py +++ b/cotisations/forms.py @@ -102,7 +102,7 @@ class SelectArticleForm(FormRevMixin, Form): def __init__(self, *args, **kwargs): user = kwargs.pop('user') - target_user = kwargs.pop('target_user') + target_user = kwargs.pop('target_user', None) super(SelectArticleForm, self).__init__(*args, **kwargs) self.fields['article'].queryset = Article.find_allowed_articles(user, target_user) diff --git a/cotisations/models.py b/cotisations/models.py index 0c9ef171..e05330bc 100644 --- a/cotisations/models.py +++ b/cotisations/models.py @@ -50,7 +50,7 @@ from machines.models import regen from re2o.field_permissions import FieldPermissionModelMixin from re2o.mixins import AclMixin, RevMixin -from cotisations.utils import find_payment_method, send_mail_invoice +from cotisations.utils import find_payment_method, send_mail_invoice from cotisations.validators import check_no_balance @@ -610,7 +610,9 @@ class Article(RevMixin, AclMixin, models.Model): user: The user requesting articles. target_user: The user to sell articles """ - if target_user.is_class_club: + if target_user is None: + objects_pool = cls.objects.filter(Q(type_user='All')) + elif target_user.is_class_club: objects_pool = cls.objects.filter( Q(type_user='All') | Q(type_user='Club') ) diff --git a/cotisations/views.py b/cotisations/views.py index e28a7bf0..35a97545 100644 --- a/cotisations/views.py +++ b/cotisations/views.py @@ -191,9 +191,9 @@ def new_custom_invoice(request): # Building the invocie form and the article formset invoice_form = CustomInvoiceForm(request.POST or None) - article_formset = formset_factory(SelectArticleForm)( + articles_formset = formset_factory(SelectArticleForm)( request.POST or None, - form_kwargs={'user': request.user, 'target_user': user} + form_kwargs={'user': request.user} ) if invoice_form.is_valid() and articles_formset.is_valid(): @@ -216,7 +216,6 @@ def new_custom_invoice(request): ) return redirect(reverse('cotisations:index-custom-invoice')) - return form({ 'factureform': invoice_form, 'action_name': _("Create"),