From d531c7dd5b6ebf8ab4ab9a8ea91b7cadc42b0a49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Sat, 27 Aug 2016 22:55:31 +0200 Subject: [PATCH] Fournisseur MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Liste des fournisseurs sur la page commande (`/orders/`) - Possibilité d'éditer les infos d'un fournisseur depuis cette page - Ajout vérification permission pour enregistrer un inventaire - Fix messages sur vue inventaire create --- kfet/templates/kfet/inventory_create.html | 2 + kfet/templates/kfet/order.html | 62 +++++++++++++++++++++++ kfet/templates/kfet/supplier_form.html | 19 +++++++ kfet/urls.py | 12 +++++ kfet/views.py | 45 ++++++++++++++-- 5 files changed, 136 insertions(+), 4 deletions(-) create mode 100644 kfet/templates/kfet/order.html create mode 100644 kfet/templates/kfet/supplier_form.html diff --git a/kfet/templates/kfet/inventory_create.html b/kfet/templates/kfet/inventory_create.html index da06d061..d4f53c3c 100644 --- a/kfet/templates/kfet/inventory_create.html +++ b/kfet/templates/kfet/inventory_create.html @@ -5,6 +5,8 @@ {% block content %} +{% include 'kfet/base_messages.html' %} +
diff --git a/kfet/templates/kfet/order.html b/kfet/templates/kfet/order.html new file mode 100644 index 00000000..7901a654 --- /dev/null +++ b/kfet/templates/kfet/order.html @@ -0,0 +1,62 @@ +{% extends 'kfet/base.html' %} + +{% block title %}Commandes{% endblock %} +{% block content-header-title %}Commandes{% endblock %} + +{% block content %} + +
+
+
+
+
+
+
+
+
+
+ {% include 'kfet/base_messages.html' %} +
+
+

Liste des commandes

+
+
+
+ + +
+

Fournisseurs

+
+ + + + + + + + + + + {% for supplier in suppliers %} + + + + + + + + + {% endfor %} + +
NomMailTél.AdresseCommentaire
+ + + + {{ supplier.name }}{{ supplier.email }}{{ supplier.phone }}{{ supplier.address }}{{ supplier.comment }}
+
+
+ + + + +{% endblock %} diff --git a/kfet/templates/kfet/supplier_form.html b/kfet/templates/kfet/supplier_form.html new file mode 100644 index 00000000..d1e10a5c --- /dev/null +++ b/kfet/templates/kfet/supplier_form.html @@ -0,0 +1,19 @@ +{% extends 'kfet/base.html' %} + +{% block title %}Fournisseur - Modification{% endblock %} +{% block content-header-title %}Fournisseur - Modification{% endblock %} + +{% block content %} + +{% include 'kfet/base_messages.html' %} + + + {% csrf_token %} + {{ form.as_p }} + {% if not perms.kfet.change_supplier %} + + {% endif %} + +
+ +{% endblock %} diff --git a/kfet/urls.py b/kfet/urls.py index 55286d00..5ac6047b 100644 --- a/kfet/urls.py +++ b/kfet/urls.py @@ -164,10 +164,22 @@ urlpatterns = [ # ----- # Inventories urls + # ----- url(r'^inventaires/$', permission_required('kfet.is_team')(views.InventoryList.as_view()), name = 'kfet.inventory'), url(r'^inventaires/new$', views.inventory_create, name = 'kfet.inventory.create'), + + # ----- + # Order urls + # ----- + + url(r'^orders/$', + permission_required('kfet.is_team')(views.OrderList.as_view()), + name = 'kfet.order'), + url(r'^orders/suppliers/(?P\d+)/edit$', + permission_required('kfet.is_team')(views.SupplierUpdate.as_view()), + name = 'kfet.order.supplier.update'), ] diff --git a/kfet/views.py b/kfet/views.py index b46747e8..985acec4 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -19,7 +19,7 @@ from django.utils.crypto import get_random_string from gestioncof.models import CofProfile, Clipper from kfet.models import (Account, Checkout, Article, Settings, AccountNegative, CheckoutStatement, GenericTeamToken, Supplier, SupplierArticle, Inventory, - InventoryArticle) + InventoryArticle, Order) from kfet.forms import * from collections import defaultdict from kfet import consumers @@ -1310,7 +1310,10 @@ def inventory_create(request): if request.POST: formset = cls_formset(request.POST, initial=initial) - if formset.is_valid(): + + if not request.user.has_perm('kfet.add_inventory'): + messages.error(request, 'Permission refusée') + elif formset.is_valid(): with transaction.atomic(): articles = Article.objects.select_for_update() @@ -1332,12 +1335,46 @@ def inventory_create(request): stock_new = stock_new) article.stock = stock_new article.save() - print('ok') + if saved: + messages.success(request, 'Inventaire créé') + return redirect('kfet.inventory') + messages.warning(request, 'Bah alors ? On a rien compté ?') else: - messages.error('Pas marché') + messages.error(request, 'Pas marché') else: formset = cls_formset(initial = initial) return render(request, 'kfet/inventory_create.html', { 'formset': formset, }) + + +# ----- +# Order views +# ----- + +class OrderList(ListView): + model = Order + template_name = 'kfet/order.html' + context_object_name = 'inventories' + + def get_context_data(self, **kwargs): + context = super(OrderList, self).get_context_data(**kwargs) + context['suppliers'] = Supplier.objects.order_by('name') + return context + +class SupplierUpdate(SuccessMessageMixin, UpdateView): + model = Supplier + template_name = 'kfet/supplier_form.html' + fields = ['name', 'address', 'email', 'phone', 'comment'] + success_url = reverse_lazy('kfet.order') + sucess_message = 'Données fournisseur mis à jour' + + # Surcharge de la validation + def form_valid(self, form): + # Checking permission + if not self.request.user.has_perm('kfet.change_supplier'): + form.add_error(None, 'Permission refusée') + return self.form_invalid(form) + # Updating + return super(SupplierUpdate, self).form_valid(form)