mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-25 00:13:45 +00:00
Adpatation des articles en fonction du type user
This commit is contained in:
parent
225164273f
commit
6393d49e92
2 changed files with 40 additions and 8 deletions
|
@ -38,6 +38,7 @@ ArticleForm, BanqueForm, PaiementForm permettent aux admin d'ajouter,
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from django import forms
|
||||
from django.db.models import Q
|
||||
from django.forms import ModelForm, Form
|
||||
from django.core.validators import MinValueValidator
|
||||
from .models import Article, Paiement, Facture, Banque
|
||||
|
@ -90,10 +91,24 @@ class CreditSoldeForm(NewFactureForm):
|
|||
montant = forms.DecimalField(max_digits=5, decimal_places=2, required=True)
|
||||
|
||||
|
||||
class SelectArticleForm(Form):
|
||||
class SelectUserArticleForm(Form):
|
||||
"""Selection d'un article lors de la creation d'une facture"""
|
||||
article = forms.ModelChoiceField(
|
||||
queryset=Article.objects.all(),
|
||||
queryset=Article.objects.filter(Q(type_user='All') | Q(type_user='Adherent')),
|
||||
label="Article",
|
||||
required=True
|
||||
)
|
||||
quantity = forms.IntegerField(
|
||||
label="Quantité",
|
||||
validators=[MinValueValidator(1)],
|
||||
required=True
|
||||
)
|
||||
|
||||
|
||||
class SelectClubArticleForm(Form):
|
||||
"""Selection d'un article lors de la creation d'une facture"""
|
||||
article = forms.ModelChoiceField(
|
||||
queryset=Article.objects.filter(Q(type_user='All') | Q(type_user='Club')),
|
||||
label="Article",
|
||||
required=True
|
||||
)
|
||||
|
|
|
@ -31,6 +31,7 @@ from django.contrib.auth.decorators import login_required, permission_required
|
|||
from django.contrib import messages
|
||||
from django.db.models import ProtectedError
|
||||
from django.db import transaction
|
||||
from django.db.models import Q
|
||||
from django.forms import modelformset_factory, formset_factory
|
||||
from django.utils import timezone
|
||||
from reversion import revisions as reversion
|
||||
|
@ -43,10 +44,21 @@ from re2o.views import form
|
|||
from re2o.utils import SortTable
|
||||
from preferences.models import OptionalUser, AssoOption, GeneralOption
|
||||
from .models import Facture, Article, Vente, Paiement, Banque
|
||||
from .forms import NewFactureForm, TrezEditFactureForm, EditFactureForm
|
||||
from .forms import ArticleForm, DelArticleForm, PaiementForm, DelPaiementForm
|
||||
from .forms import BanqueForm, DelBanqueForm, NewFactureFormPdf
|
||||
from .forms import SelectArticleForm, CreditSoldeForm
|
||||
from .forms import (
|
||||
NewFactureForm,
|
||||
TrezEditFactureForm,
|
||||
EditFactureForm,
|
||||
ArticleForm,
|
||||
DelArticleForm,
|
||||
PaiementForm,
|
||||
DelPaiementForm,
|
||||
BanqueForm,
|
||||
DelBanqueForm,
|
||||
NewFactureFormPdf,
|
||||
SelectUserArticleForm,
|
||||
SelectClubArticleForm,
|
||||
CreditSoldeForm
|
||||
)
|
||||
from .tex import render_tex
|
||||
|
||||
|
||||
|
@ -67,10 +79,15 @@ def new_facture(request, userid):
|
|||
return redirect("/cotisations/")
|
||||
facture = Facture(user=user)
|
||||
# Le template a besoin de connaitre les articles pour le js
|
||||
article_list = Article.objects.all()
|
||||
article_list = Article.objects.filter(
|
||||
Q(type_user='All') | Q(type_user=request.user.class_name)
|
||||
)
|
||||
# On envoie la form fature et un formset d'articles
|
||||
facture_form = NewFactureForm(request.POST or None, instance=facture)
|
||||
article_formset = formset_factory(SelectArticleForm)(request.POST or None)
|
||||
if request.user.is_class_club:
|
||||
article_formset = formset_factory(SelectClubArticleForm)(request.POST or None)
|
||||
else:
|
||||
article_formset = formset_factory(SelectUserArticleForm)(request.POST or None)
|
||||
if facture_form.is_valid() and article_formset.is_valid():
|
||||
new_facture_instance = facture_form.save(commit=False)
|
||||
articles = article_formset
|
||||
|
|
Loading…
Reference in a new issue