3
0
Fork 0
mirror of https://github.com/nanoy42/coope synced 2025-01-24 09:04:21 +00:00
coope/gestion/forms.py

125 lines
5.1 KiB
Python
Raw Normal View History

2018-10-06 00:03:02 +02:00
from django import forms
2018-11-22 22:52:15 +01:00
from django.core.exceptions import ValidationError
2018-10-06 00:03:02 +02:00
from django.contrib.auth.models import User
from dal import autocomplete
2019-05-03 21:09:32 +02:00
from .models import Reload, Refund, Product, Keg, Menu, Category
2018-10-06 00:03:02 +02:00
from preferences.models import PaymentMethod
class ReloadForm(forms.ModelForm):
2019-02-28 13:18:41 +01:00
"""
A form to create a :class:`~gestion.models.Reload`.
"""
2018-11-22 22:52:15 +01:00
def __init__(self, *args, **kwargs):
super(ReloadForm, self).__init__(*args, **kwargs)
2018-12-16 11:20:02 +01:00
self.fields['PaymentMethod'].queryset = PaymentMethod.objects.filter(is_usable_in_reload=True).filter(is_active=True)
2018-11-22 22:52:15 +01:00
2018-10-06 00:03:02 +02:00
class Meta:
model = Reload
fields = ("customer", "amount", "PaymentMethod")
2019-01-17 23:25:56 +01:00
widgets = {'customer': autocomplete.ModelSelect2(url='users:active-users-autocomplete', attrs={'data-minimum-input-length':2}), 'amount': forms.TextInput}
2018-11-22 22:52:15 +01:00
2018-10-06 00:03:02 +02:00
class RefundForm(forms.ModelForm):
2019-02-28 13:18:41 +01:00
"""
A form to create a :class:`~gestion.models.Refund`.
"""
2018-10-06 00:03:02 +02:00
class Meta:
model = Refund
fields = ("customer", "amount")
2019-01-17 23:25:56 +01:00
widgets = {'customer': autocomplete.ModelSelect2(url='users:active-users-autocomplete', attrs={'data-minimum-input-length':2}), 'amount': forms.TextInput}
2018-11-22 22:52:15 +01:00
2018-10-06 00:03:02 +02:00
class ProductForm(forms.ModelForm):
2019-02-28 13:18:41 +01:00
"""
A form to create and edit a :class:`~gestion.models.Product`.
"""
2018-10-06 00:03:02 +02:00
class Meta:
model = Product
fields = "__all__"
2019-01-17 23:25:56 +01:00
widgets = {'amount': forms.TextInput}
2018-10-06 00:03:02 +02:00
class KegForm(forms.ModelForm):
2019-02-28 13:18:41 +01:00
"""
A form to create and edit a :class:`~gestion.models.Keg`.
"""
def __init__(self, *args, **kwargs):
super(KegForm, self).__init__(*args, **kwargs)
2019-05-17 16:19:28 +02:00
self.fields['pinte'].queryset = Product.objects.filter(draft_category=Product.DRAFT_PINTE)
self.fields['demi'].queryset = Product.objects.filter(draft_category=Product.DRAFT_DEMI)
self.fields['galopin'].queryset = Product.objects.filter(draft_category=Product.DRAFT_GALOPIN)
2018-10-06 00:03:02 +02:00
class Meta:
model = Keg
2019-04-28 13:13:30 +02:00
fields = "__all__"
2019-01-17 23:25:56 +01:00
widgets = {'amount': forms.TextInput}
2018-10-06 00:03:02 +02:00
class MenuForm(forms.ModelForm):
2019-02-28 13:18:41 +01:00
"""
A form to create and edit a :class:`~gestion.models.Menu`.
"""
2018-10-06 00:03:02 +02:00
class Meta:
model = Menu
fields = "__all__"
2019-01-17 23:25:56 +01:00
widgets = {'amount': forms.TextInput}
2018-10-06 00:03:02 +02:00
2018-11-22 22:52:15 +01:00
class SearchProductForm(forms.Form):
2019-02-28 13:18:41 +01:00
"""
A form to search a :class:`~gestion.models.Product`.
"""
2018-11-22 22:52:15 +01:00
product = forms.ModelChoiceField(queryset=Product.objects.all(), required=True, label="Produit", widget=autocomplete.ModelSelect2(url='gestion:products-autocomplete', attrs={'data-minimum-input-length':2}))
class SearchMenuForm(forms.Form):
2019-02-28 13:18:41 +01:00
"""
A form to search a :class:`~gestion.models.Menu`.
"""
2018-11-22 22:52:15 +01:00
menu = forms.ModelChoiceField(queryset=Menu.objects.all(), required=True, label="Menu", widget=autocomplete.ModelSelect2(url='gestion:menus-autocomplete', attrs={'data-minimum-input-length':2}))
2018-10-06 00:03:02 +02:00
class GestionForm(forms.Form):
2019-02-28 13:18:41 +01:00
"""
A form for the :func:`~gestion.views.manage` view.
"""
2018-11-25 13:52:32 +01:00
client = forms.ModelChoiceField(queryset=User.objects.filter(is_active=True), required=True, label="Client", widget=autocomplete.ModelSelect2(url='users:active-users-autocomplete', attrs={'data-minimum-input-length':2}))
2018-12-23 23:55:27 +01:00
product = forms.ModelChoiceField(queryset=Product.objects.filter(is_active=True), required=True, label="Produit", widget=autocomplete.ModelSelect2(url='gestion:active-products-autocomplete', attrs={'data-minimum-input-length':2}))
2018-11-25 13:52:32 +01:00
class SelectPositiveKegForm(forms.Form):
2019-02-28 13:18:41 +01:00
"""
A form to search a :class:`~gestion.models.Keg` with a positive stockhold.
"""
2018-11-25 13:52:32 +01:00
keg = forms.ModelChoiceField(queryset=Keg.objects.filter(stockHold__gt = 0), required=True, label="Fût", widget=autocomplete.ModelSelect2(url='gestion:kegs-positive-autocomplete'))
class SelectActiveKegForm(forms.Form):
2019-02-28 13:18:41 +01:00
"""
A form to search an active :class:`~gestion.models.Keg`.
"""
2018-12-23 12:54:37 +01:00
keg = forms.ModelChoiceField(queryset=Keg.objects.filter(is_active = True), required=True, label="Fût", widget=autocomplete.ModelSelect2(url='gestion:kegs-active-autocomplete'))
2018-12-23 13:05:41 +01:00
class PinteForm(forms.Form):
2019-02-28 13:18:41 +01:00
"""
A form to free :class:`Pints <gestion.models.Pinte>`.
"""
2018-12-23 12:54:37 +01:00
ids = forms.CharField(widget=forms.Textarea, label="Numéros", help_text="Numéros séparés par un espace. Laissez vide pour utiliser le range.", required=False)
begin = forms.IntegerField(label="Début", help_text="Début du range", required=False)
2019-01-06 00:01:30 +01:00
end = forms.IntegerField(label="Fin", help_text="Fin du range", required=False)
class GenerateReleveForm(forms.Form):
2019-02-28 13:18:41 +01:00
"""
A form to generate a releve.
"""
2019-01-06 00:01:30 +01:00
begin = forms.DateTimeField(label="Date de début")
2019-05-03 21:09:32 +02:00
end = forms.DateTimeField(label="Date de fin")
class CategoryForm(forms.ModelForm):
"""
A form to create and edit a :class:`~gestion.models.Category`.
"""
class Meta:
model = Category
fields = "__all__"
class SearchCategoryForm(forms.Form):
"""
A form to search a :class:`~gestion.models.Category`.
"""
category = forms.ModelChoiceField(queryset=Category.objects.all(), required=True, label="Catégorie", widget=autocomplete.ModelSelect2(url='gestion:categories-autocomplete', attrs={'data-minimum-input-length':2}))