mirror of
https://github.com/nanoy42/coope
synced 2024-11-28 23:52:27 +00:00
Création de pintes
This commit is contained in:
parent
6b3136dece
commit
1a1b5cf60b
4 changed files with 48 additions and 3 deletions
|
@ -60,4 +60,9 @@ 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'))
|
||||
keg = forms.ModelChoiceField(queryset=Keg.objects.filter(is_active = True), required=True, label="Fût", widget=autocomplete.ModelSelect2(url='gestion:kegs-active-autocomplete'))
|
||||
|
||||
class CreatePinteForm(forms.Form):
|
||||
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)
|
||||
end = forms.IntegerField(label="Fin", help_text="Fin du range", required=False)
|
|
@ -5,6 +5,7 @@
|
|||
<li><a href="#first">Produits</a></li>
|
||||
<li><a href="#second">Futs</a></li>
|
||||
<li><a href="#third">Menus</a></li>
|
||||
<li><a href="#fourth">Pintes</a></li>
|
||||
</ul>
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
|
@ -58,4 +59,21 @@
|
|||
{% endif %}
|
||||
</ul>
|
||||
</section>
|
||||
<section id="fourth" class="main">
|
||||
<header class="major">
|
||||
<h2>Pintes</h2>
|
||||
</header>
|
||||
Actions possibles :
|
||||
<ul>
|
||||
{% if perms.gestion.add_pinte %}
|
||||
<li><a href="{% url 'gestion:createPintes' %}">Créer une ou plusieurs pintes</a></li>
|
||||
{% endif %}
|
||||
{% if perms.gestion.change_pinte %}
|
||||
<li><a href="">Libérer des pintes</a></li>
|
||||
{% endif %}
|
||||
{% if perms.gestion.view_pinte %}
|
||||
<li><a href="{% url 'gestion:menusList' %}">Lister les pintes</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
|
|
@ -33,6 +33,7 @@ urlpatterns = [
|
|||
path('cancelConsumption/<int:pk>', views.cancel_consumption, name="cancelConsumption"),
|
||||
path('cancelMenu/<int:pk>', views.cancel_menu, name="cancelMenu"),
|
||||
path('productProfile/<int:pk>', views.productProfile, name="productProfile"),
|
||||
path('createPintes', views.create_pintes, name="createPintes"),
|
||||
path('products-autocomplete', views.ProductsAutocomplete.as_view(), name="products-autocomplete"),
|
||||
path('kegs-positive-autocomplete', views.KegPositiveAutocomplete.as_view(), name="kegs-positive-autocomplete"),
|
||||
path('kegs-active-autocomplete', views.KegActiveAutocomplete.as_view(), name="kegs-active-autocomplete"),
|
||||
|
|
|
@ -13,7 +13,7 @@ import simplejson as json
|
|||
from dal import autocomplete
|
||||
from decimal import *
|
||||
|
||||
from .forms import ReloadForm, RefundForm, ProductForm, KegForm, MenuForm, GestionForm, SearchMenuForm, SearchProductForm, SelectPositiveKegForm, SelectActiveKegForm
|
||||
from .forms import ReloadForm, RefundForm, ProductForm, KegForm, MenuForm, GestionForm, SearchMenuForm, SearchProductForm, SelectPositiveKegForm, SelectActiveKegForm, CreatePinteForm
|
||||
from .models import Product, Menu, Keg, ConsumptionHistory, KegHistory, Consumption, MenuHistory, Pinte
|
||||
from preferences.models import PaymentMethod
|
||||
|
||||
|
@ -912,4 +912,25 @@ def allocate(pinte_pk, user):
|
|||
pinte.save()
|
||||
return True
|
||||
except Pinte.DoesNotExist:
|
||||
return False
|
||||
return False
|
||||
|
||||
@active_required
|
||||
@login_required
|
||||
@permission_required('gestion.add_pinte')
|
||||
def create_pintes(request):
|
||||
form = CreatePinteForm(request.POST or None)
|
||||
if form.is_valid():
|
||||
ids = form.cleaned_data['ids']
|
||||
if ids != "":
|
||||
ids = ids.split(" ")
|
||||
else:
|
||||
ids = range(form.cleaned_data['begin'], form.cleaned_data['end'] + 1)
|
||||
i = 0
|
||||
for id in ids:
|
||||
if not Pinte.objects.filter(pk=id).exists():
|
||||
new_pinte = Pinte(pk=int(id))
|
||||
new_pinte.save()
|
||||
i += 1
|
||||
messages.success(request, str(i) + " pinte(s) a(ont) été ajoutée(s)")
|
||||
return redirect(reverse('gestion:productsIndex'))
|
||||
return render(request, "form.html", {"form": form, "form_title": "Ajouter des pintes", "form_button": "Ajouter"})
|
Loading…
Reference in a new issue