8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-25 08:23:46 +00:00

Adpatation des articles en fonction du type user

This commit is contained in:
Gabriel Detraz 2017-10-28 06:02:53 +02:00 committed by root
parent 225164273f
commit 6393d49e92
2 changed files with 40 additions and 8 deletions

View file

@ -38,6 +38,7 @@ ArticleForm, BanqueForm, PaiementForm permettent aux admin d'ajouter,
from __future__ import unicode_literals from __future__ import unicode_literals
from django import forms from django import forms
from django.db.models import Q
from django.forms import ModelForm, Form from django.forms import ModelForm, Form
from django.core.validators import MinValueValidator from django.core.validators import MinValueValidator
from .models import Article, Paiement, Facture, Banque 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) 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""" """Selection d'un article lors de la creation d'une facture"""
article = forms.ModelChoiceField( 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", label="Article",
required=True required=True
) )

View file

@ -31,6 +31,7 @@ from django.contrib.auth.decorators import login_required, permission_required
from django.contrib import messages from django.contrib import messages
from django.db.models import ProtectedError from django.db.models import ProtectedError
from django.db import transaction from django.db import transaction
from django.db.models import Q
from django.forms import modelformset_factory, formset_factory from django.forms import modelformset_factory, formset_factory
from django.utils import timezone from django.utils import timezone
from reversion import revisions as reversion from reversion import revisions as reversion
@ -43,10 +44,21 @@ from re2o.views import form
from re2o.utils import SortTable from re2o.utils import SortTable
from preferences.models import OptionalUser, AssoOption, GeneralOption from preferences.models import OptionalUser, AssoOption, GeneralOption
from .models import Facture, Article, Vente, Paiement, Banque from .models import Facture, Article, Vente, Paiement, Banque
from .forms import NewFactureForm, TrezEditFactureForm, EditFactureForm from .forms import (
from .forms import ArticleForm, DelArticleForm, PaiementForm, DelPaiementForm NewFactureForm,
from .forms import BanqueForm, DelBanqueForm, NewFactureFormPdf TrezEditFactureForm,
from .forms import SelectArticleForm, CreditSoldeForm EditFactureForm,
ArticleForm,
DelArticleForm,
PaiementForm,
DelPaiementForm,
BanqueForm,
DelBanqueForm,
NewFactureFormPdf,
SelectUserArticleForm,
SelectClubArticleForm,
CreditSoldeForm
)
from .tex import render_tex from .tex import render_tex
@ -67,10 +79,15 @@ def new_facture(request, userid):
return redirect("/cotisations/") return redirect("/cotisations/")
facture = Facture(user=user) facture = Facture(user=user)
# Le template a besoin de connaitre les articles pour le js # 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 # On envoie la form fature et un formset d'articles
facture_form = NewFactureForm(request.POST or None, instance=facture) 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(): if facture_form.is_valid() and article_formset.is_valid():
new_facture_instance = facture_form.save(commit=False) new_facture_instance = facture_form.save(commit=False)
articles = article_formset articles = article_formset