3
0
Fork 0
mirror of https://github.com/nanoy42/coope synced 2024-11-16 16:33:12 +00:00
coope/gestion/forms.py

57 lines
2.5 KiB
Python
Raw Normal View History

2018-10-05 22:03:02 +00:00
from django import forms
2018-11-22 21:52:15 +00:00
from django.core.exceptions import ValidationError
2018-10-05 22:03:02 +00:00
from django.contrib.auth.models import User
from dal import autocomplete
from .models import Reload, Refund, Product, Keg, Menu
from preferences.models import PaymentMethod
from coopeV3.widgets import SearchField
class ReloadForm(forms.ModelForm):
2018-11-22 21:52:15 +00:00
def __init__(self, *args, **kwargs):
super(ReloadForm, self).__init__(*args, **kwargs)
self.fields['PaymentMethod'].queryset = PaymentMethod.objects.filter(is_usable_in_reload=True)
2018-10-05 22:03:02 +00:00
class Meta:
model = Reload
fields = ("customer", "amount", "PaymentMethod")
2018-11-22 21:52:15 +00:00
widgets = {'customer': autocomplete.ModelSelect2(url='users:active-users-autocomplete', attrs={'data-minimum-input-length':2})}
2018-10-05 22:03:02 +00:00
class RefundForm(forms.ModelForm):
class Meta:
model = Refund
fields = ("customer", "amount")
2018-11-22 21:52:15 +00:00
widgets = {'customer': autocomplete.ModelSelect2(url='users:active-users-autocomplete', attrs={'data-minimum-input-length':2})}
2018-10-05 22:03:02 +00:00
class ProductForm(forms.ModelForm):
class Meta:
model = Product
fields = "__all__"
class KegForm(forms.ModelForm):
class Meta:
model = Keg
2018-12-05 00:43:21 +00:00
exclude = ("is_active", )
2018-10-05 22:03:02 +00:00
class MenuForm(forms.ModelForm):
class Meta:
model = Menu
fields = "__all__"
2018-11-22 21:52:15 +00:00
class SearchProductForm(forms.Form):
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):
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-05 22:03:02 +00:00
class GestionForm(forms.Form):
2018-11-25 12:52:32 +00: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}))
class SelectPositiveKegForm(forms.Form):
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):
keg = forms.ModelChoiceField(queryset=Keg.objects.filter(is_active = True), required=True, label="Fût", widget=autocomplete.ModelSelect2(url='gestion:kegs-active-autocomplete'))