From ee6de3562708a359767b9ecd01717f2c675f6084 Mon Sep 17 00:00:00 2001 From: Qwann Date: Fri, 10 Mar 2017 18:28:48 +0100 Subject: [PATCH 1/8] category addcost added --- .../0048_articlecategory_has_addcost.py | 19 +++++++++++++++++++ kfet/models.py | 5 ++++- kfet/views.py | 4 ++-- 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 kfet/migrations/0048_articlecategory_has_addcost.py diff --git a/kfet/migrations/0048_articlecategory_has_addcost.py b/kfet/migrations/0048_articlecategory_has_addcost.py new file mode 100644 index 00000000..e79ad7e6 --- /dev/null +++ b/kfet/migrations/0048_articlecategory_has_addcost.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('kfet', '0047_auto_20170104_1528'), + ] + + operations = [ + migrations.AddField( + model_name='articlecategory', + name='has_addcost', + field=models.BooleanField(default=True), + ), + ] diff --git a/kfet/models.py b/kfet/models.py index c6853577..129ea7f3 100644 --- a/kfet/models.py +++ b/kfet/models.py @@ -327,13 +327,16 @@ class CheckoutStatement(models.Model): balance=F('balance') - last_statement.balance_new + self.balance_new) super(CheckoutStatement, self).save(*args, **kwargs) + @python_2_unicode_compatible class ArticleCategory(models.Model): - name = models.CharField(max_length = 45) + name = models.CharField(max_length=45) + has_addcost = models.BooleanField(default=True) def __str__(self): return self.name + @python_2_unicode_compatible class Article(models.Model): name = models.CharField(max_length = 45) diff --git a/kfet/views.py b/kfet/views.py index 19574f11..2164de47 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -990,7 +990,7 @@ def kpsul_perform_operations(request): for operation in operations: if operation.type == Operation.PURCHASE: operation.amount = - operation.article.price * operation.article_nb - if is_addcost: + if is_addcost & operation.article.category.has_addcost: operation.addcost_for = addcost_for operation.addcost_amount = addcost_amount * operation.article_nb operation.amount -= operation.addcost_amount @@ -1001,7 +1001,7 @@ def kpsul_perform_operations(request): else: operation.is_checkout = False if operationgroup.on_acc.is_cof: - if is_addcost: + if is_addcost & operation.article.category.has_addcost: operation.addcost_amount = operation.addcost_amount / cof_grant_divisor operation.amount = operation.amount / cof_grant_divisor to_articles_stocks[operation.article] -= operation.article_nb From fcc2ab8810adb8a5a937ca21948b65c54c2660ec Mon Sep 17 00:00:00 2001 From: Qwann Date: Fri, 17 Mar 2017 19:17:36 +0100 Subject: [PATCH 2/8] frontend working --- kfet/templates/kfet/kpsul.html | 9 ++++++--- kfet/views.py | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index 264422f0..7b907f80 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -646,7 +646,7 @@ $(document).ready(function() { }); $after.after(article_html); // Pour l'autocomplétion - articlesList.push([article['name'],article['id'],article['category_id'],article['price'], article['stock']]); + articlesList.push([article['name'],article['id'],article['category_id'],article['price'], article['stock'],article['category__has_addcost']]); } function getArticles() { @@ -830,8 +830,11 @@ $(document).ready(function() { while (i Date: Fri, 17 Mar 2017 19:23:44 +0100 Subject: [PATCH 3/8] migration renamed --- .../{0048_article_hidden.py => 0049_article_hidden.py} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename kfet/migrations/{0048_article_hidden.py => 0049_article_hidden.py} (88%) diff --git a/kfet/migrations/0048_article_hidden.py b/kfet/migrations/0049_article_hidden.py similarity index 88% rename from kfet/migrations/0048_article_hidden.py rename to kfet/migrations/0049_article_hidden.py index 63869f77..13c25508 100644 --- a/kfet/migrations/0048_article_hidden.py +++ b/kfet/migrations/0049_article_hidden.py @@ -7,7 +7,7 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('kfet', '0047_auto_20170104_1528'), + ('kfet', '0048_articlecategory_has_addcost'), ] operations = [ From de724a2c0d85ff4eaebbb850eaffe22b292d721c Mon Sep 17 00:00:00 2001 From: Qwann Date: Fri, 17 Mar 2017 19:53:23 +0100 Subject: [PATCH 4/8] PEP8 for perform_operation --- kfet/views.py | 93 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 39 deletions(-) diff --git a/kfet/views.py b/kfet/views.py index b0415c30..7a2700d1 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -921,13 +921,14 @@ def kpsul_update_addcost(request): addcost_form = AddcostForm(request.POST) if not addcost_form.is_valid(): - data = { 'errors': { 'addcost': list(addcost_form.errors) } } + data = {'errors': {'addcost': list(addcost_form.errors)}} return JsonResponse(data, status=400) required_perms = ['kfet.manage_addcosts'] if not request.user.has_perms(required_perms): data = { 'errors': { - 'missing_perms': get_missing_perms(required_perms, request.user) + 'missing_perms': get_missing_perms(required_perms, + request.user) } } return JsonResponse(data, status=403) @@ -935,7 +936,8 @@ def kpsul_update_addcost(request): trigramme = addcost_form.cleaned_data['trigramme'] account = trigramme and Account.objects.get(trigramme=trigramme) or None Settings.objects.filter(name='ADDCOST_FOR').update(value_account=account) - Settings.objects.filter(name='ADDCOST_AMOUNT').update(value_decimal=addcost_form.cleaned_data['amount']) + (Settings.objects.filter(name='ADDCOST_AMOUNT') + .update(value_decimal=addcost_form.cleaned_data['amount'])) cache.delete('ADDCOST_FOR') cache.delete('ADDCOST_AMOUNT') data = { @@ -947,20 +949,23 @@ def kpsul_update_addcost(request): consumers.KPsul.group_send('kfet.kpsul', data) return JsonResponse(data) + def get_missing_perms(required_perms, user): - missing_perms_codenames = [ (perm.split('.'))[1] - for perm in required_perms if not user.has_perm(perm)] + missing_perms_codenames = [(perm.split('.'))[1] + for perm in required_perms + if not user.has_perm(perm)] missing_perms = list( - Permission.objects - .filter(codename__in=missing_perms_codenames) - .values_list('name', flat=True)) + Permission.objects + .filter(codename__in=missing_perms_codenames) + .values_list('name', flat=True)) return missing_perms + @teamkfet_required def kpsul_perform_operations(request): # Initializing response data - data = { 'operationgroup': 0, 'operations': [], - 'warnings': {}, 'errors': {} } + data = {'operationgroup': 0, 'operations': [], + 'warnings': {}, 'errors': {}} # Checking operationgroup operationgroup_form = KPsulOperationGroupForm(request.POST) @@ -968,7 +973,7 @@ def kpsul_perform_operations(request): data['errors']['operation_group'] = list(operationgroup_form.errors) # Checking operation_formset - operation_formset = KPsulOperationFormSet(request.POST) + operation_formset = KPsulOperationFormSet(request.POST) if not operation_formset.is_valid(): data['errors']['operations'] = list(operation_formset.errors) @@ -977,34 +982,36 @@ def kpsul_perform_operations(request): return JsonResponse(data, status=400) # Pre-saving (no commit) - operationgroup = operationgroup_form.save(commit = False) - operations = operation_formset.save(commit = False) + operationgroup = operationgroup_form.save(commit=False) + operations = operation_formset.save(commit=False) # Retrieving COF grant cof_grant = Settings.SUBVENTION_COF() # Retrieving addcosts data addcost_amount = Settings.ADDCOST_AMOUNT() - addcost_for = Settings.ADDCOST_FOR() + addcost_for = Settings.ADDCOST_FOR() # Initializing vars - required_perms = set() # Required perms to perform all operations + required_perms = set() # Required perms to perform all operations cof_grant_divisor = 1 + cof_grant / 100 - to_addcost_for_balance = 0 # For balance of addcost_for - to_checkout_balance = 0 # For balance of selected checkout - to_articles_stocks = defaultdict(lambda:0) # For stocks articles + to_addcost_for_balance = 0 # For balance of addcost_for + to_checkout_balance = 0 # For balance of selected checkout + to_articles_stocks = defaultdict(lambda: 0) # For stocks articles is_addcost = (addcost_for and addcost_amount - and addcost_for != operationgroup.on_acc) + and addcost_for != operationgroup.on_acc) need_comment = operationgroup.on_acc.need_comment - # Filling data of each operations + operationgroup + calculating other stuffs + # Filling data of each operations + # + operationgroup + calculating other stuffs for operation in operations: if operation.type == Operation.PURCHASE: operation.amount = - operation.article.price * operation.article_nb if is_addcost & operation.article.category.has_addcost: - operation.addcost_for = addcost_for - operation.addcost_amount = addcost_amount * operation.article_nb - operation.amount -= operation.addcost_amount - to_addcost_for_balance += operation.addcost_amount + operation.addcost_for = addcost_for + operation.addcost_amount = addcost_amount \ + * operation.article_nb + operation.amount -= operation.addcost_amount + to_addcost_for_balance += operation.addcost_amount if operationgroup.on_acc.is_cash: operation.is_checkout = True to_checkout_balance += -operation.amount @@ -1012,12 +1019,14 @@ def kpsul_perform_operations(request): operation.is_checkout = False if operationgroup.on_acc.is_cof: if is_addcost & operation.article.category.has_addcost: - operation.addcost_amount = operation.addcost_amount / cof_grant_divisor + operation.addcost_amount = operation.addcost_amount \ + / cof_grant_divisor operation.amount = operation.amount / cof_grant_divisor to_articles_stocks[operation.article] -= operation.article_nb else: if operationgroup.on_acc.is_cash: - data['errors']['account'] = 'Charge et retrait impossible sur LIQ' + data['errors']['account'] = ("Charge et retrait" + " impossible sur LIQ") to_checkout_balance += operation.amount operationgroup.amount += operation.amount if operation.type == Operation.DEPOSIT: @@ -1029,8 +1038,10 @@ def kpsul_perform_operations(request): if operationgroup.on_acc.is_cof: to_addcost_for_balance = to_addcost_for_balance / cof_grant_divisor - (perms, stop) = operationgroup.on_acc.perms_to_perform_operation( - amount = operationgroup.amount) + (perms, stop) = (operationgroup.on_acc + .perms_to_perform_operation( + amount=operationgroup.amount) + ) required_perms |= perms if need_comment: @@ -1059,7 +1070,7 @@ def kpsul_perform_operations(request): # saving account's balance and adding to Negative if not in if not operationgroup.on_acc.is_cash: Account.objects.filter(pk=operationgroup.on_acc.pk).update( - balance = F('balance') + operationgroup.amount) + balance=F('balance') + operationgroup.amount) operationgroup.on_acc.refresh_from_db() if operationgroup.on_acc.balance < 0: if hasattr(operationgroup.on_acc, 'negative'): @@ -1068,7 +1079,7 @@ def kpsul_perform_operations(request): operationgroup.on_acc.negative.save() else: negative = AccountNegative( - account = operationgroup.on_acc, start = timezone.now()) + account=operationgroup.on_acc, start = timezone.now()) negative.save() elif (hasattr(operationgroup.on_acc, 'negative') and not operationgroup.on_acc.negative.balance_offset): @@ -1077,12 +1088,12 @@ def kpsul_perform_operations(request): # Updating checkout's balance if to_checkout_balance: Checkout.objects.filter(pk=operationgroup.checkout.pk).update( - balance = F('balance') + to_checkout_balance) + balance=F('balance') + to_checkout_balance) # Saving addcost_for with new balance if there is one if is_addcost and to_addcost_for_balance: Account.objects.filter(pk=addcost_for.pk).update( - balance = F('balance') + to_addcost_for_balance) + balance=F('balance') + to_addcost_for_balance) # Saving operation group operationgroup.save() @@ -1097,7 +1108,7 @@ def kpsul_perform_operations(request): # Updating articles stock for article in to_articles_stocks: Article.objects.filter(pk=article.pk).update( - stock = F('stock') + to_articles_stocks[article]) + stock=F('stock') + to_articles_stocks[article]) # Websocket data websocket_data = {} @@ -1109,18 +1120,21 @@ def kpsul_perform_operations(request): 'at': operationgroup.at, 'is_cof': operationgroup.is_cof, 'comment': operationgroup.comment, - 'valid_by__trigramme': ( operationgroup.valid_by and - operationgroup.valid_by.trigramme or None), + 'valid_by__trigramme': (operationgroup.valid_by and + operationgroup.valid_by.trigramme or None), 'on_acc__trigramme': operationgroup.on_acc.trigramme, 'opes': [], }] for operation in operations: ope_data = { - 'id': operation.pk, 'type': operation.type, 'amount': operation.amount, + 'id': operation.pk, 'type': operation.type, + 'amount': operation.amount, 'addcost_amount': operation.addcost_amount, - 'addcost_for__trigramme': is_addcost and addcost_for.trigramme or None, + 'addcost_for__trigramme': is_addcost + and addcost_for.trigramme or None, 'is_checkout': operation.is_checkout, - 'article__name': operation.article and operation.article.name or None, + 'article__name': operation.article + and operation.article.name or None, 'article_nb': operation.article_nb, 'group_id': operationgroup.pk, 'canceled_by__trigramme': None, 'canceled_at': None, @@ -1134,7 +1148,7 @@ def kpsul_perform_operations(request): }] websocket_data['articles'] = [] # Need refresh from db cause we used update on querysets - articles_pk = [ article.pk for article in to_articles_stocks] + articles_pk = [article.pk for article in to_articles_stocks] articles = Article.objects.values('id', 'stock').filter(pk__in=articles_pk) for article in articles: websocket_data['articles'].append({ @@ -1144,6 +1158,7 @@ def kpsul_perform_operations(request): consumers.KPsul.group_send('kfet.kpsul', websocket_data) return JsonResponse(data) + @teamkfet_required def kpsul_cancel_operations(request): # Pour la réponse From 72615bf4007cab18199435cba7278ef65c900ac6 Mon Sep 17 00:00:00 2001 From: Qwann Date: Tue, 4 Apr 2017 16:57:17 +0200 Subject: [PATCH 5/8] small fixes --- kfet/templates/kfet/kpsul.html | 2 +- kfet/views.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index 7b907f80..8e1f44f3 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -833,7 +833,7 @@ $(document).ready(function() { if (settings['addcost_for'] && settings['addcost_amount'] && account_data['trigramme'] != settings['addcost_for'] - && article_data['5']) + && article_data[5]) amount_euro -= settings['addcost_amount'] * nb; var reduc_divisor = 1; if (account_data['is_cof']) diff --git a/kfet/views.py b/kfet/views.py index 7a2700d1..b684b90f 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -1019,8 +1019,7 @@ def kpsul_perform_operations(request): operation.is_checkout = False if operationgroup.on_acc.is_cof: if is_addcost & operation.article.category.has_addcost: - operation.addcost_amount = operation.addcost_amount \ - / cof_grant_divisor + operation.addcost_amount /= cof_grant_divisor operation.amount = operation.amount / cof_grant_divisor to_articles_stocks[operation.article] -= operation.article_nb else: From ba11aa49dbf52c5b4a2f1f6c70995d2d78483db6 Mon Sep 17 00:00:00 2001 From: Qwann Date: Tue, 4 Apr 2017 21:36:02 +0200 Subject: [PATCH 6/8] categories are updatable --- kfet/forms.py | 10 +++++ kfet/templates/kfet/category.html | 53 ++++++++++++++++++++++++ kfet/templates/kfet/category_update.html | 17 ++++++++ kfet/urls.py | 8 ++++ kfet/views.py | 38 +++++++++++++++-- 5 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 kfet/templates/kfet/category.html create mode 100644 kfet/templates/kfet/category_update.html diff --git a/kfet/forms.py b/kfet/forms.py index 2b59e1b3..53791456 100644 --- a/kfet/forms.py +++ b/kfet/forms.py @@ -229,6 +229,16 @@ class CheckoutStatementUpdateForm(forms.ModelForm): model = CheckoutStatement exclude = ['by', 'at', 'checkout', 'amount_error', 'amount_taken'] + +# ----- +# Category +# ----- + +class CategoryForm(forms.ModelForm): + class Meta: + model = ArticleCategory + fields = ['name', 'has_addcost'] + # ----- # Article forms # ----- diff --git a/kfet/templates/kfet/category.html b/kfet/templates/kfet/category.html new file mode 100644 index 00000000..4de44207 --- /dev/null +++ b/kfet/templates/kfet/category.html @@ -0,0 +1,53 @@ +{% extends 'kfet/base.html' %} + +{% block title %}Categories d'articles{% endblock %} +{% block content-header-title %}Categories d'articles{% endblock %} + +{% block content %} + +
+
+
+
+
{{ categories|length }}
+
catégorie{{ categories|length|pluralize }}
+
+
+
+
+ {% include 'kfet/base_messages.html' %} +
+
+

Liste des catégories

+
+ + + + + + + + + + + {% for category in categories %} + + + + + + + {% endfor %} + +
NomNombre d'articlesPeut-être majoré
+ + + + {{ category.name }}{{ category.articles.all|length }}{{ category.has_addcost | yesno:"Oui,Non"}}
+
+
+
+
+
+ +{% endblock %} diff --git a/kfet/templates/kfet/category_update.html b/kfet/templates/kfet/category_update.html new file mode 100644 index 00000000..fb04e12b --- /dev/null +++ b/kfet/templates/kfet/category_update.html @@ -0,0 +1,17 @@ +{% extends 'kfet/base.html' %} + +{% block title %}Édition de la catégorie {{ category.name }}{% endblock %} +{% block content-header-title %}Catégorie {{ category.name }} - Édition{% endblock %} + +{% block content %} + +
+ {% csrf_token %} + {{ form.as_p }} + {% if not perms.kfet.change_articlecategory %} + + {% endif %} + +
+ +{% endblock %} diff --git a/kfet/urls.py b/kfet/urls.py index 0a5c2128..aabbfc3c 100644 --- a/kfet/urls.py +++ b/kfet/urls.py @@ -134,6 +134,14 @@ urlpatterns = [ # Article urls # ----- + # Category - General + url('^categories/$', + teamkfet_required(views.CategoryList.as_view()), + name='kfet.category'), + # Category - Update + url('^categories/(?P\d+)/edit$', + teamkfet_required(views.CategoryUpdate.as_view()), + name='kfet.category.update'), # Article - General url('^articles/$', teamkfet_required(views.ArticleList.as_view()), diff --git a/kfet/views.py b/kfet/views.py index b684b90f..7cb37f28 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + from django.shortcuts import render, get_object_or_404, redirect from django.core.exceptions import PermissionDenied @@ -27,7 +27,7 @@ from kfet.models import ( Account, Checkout, Article, Settings, AccountNegative, CheckoutStatement, GenericTeamToken, Supplier, SupplierArticle, Inventory, InventoryArticle, Order, OrderArticle, Operation, OperationGroup, - TransferGroup, Transfer) + TransferGroup, Transfer, ArticleCategory) from kfet.forms import ( AccountTriForm, AccountBalanceForm, AccountNoTriForm, UserForm, CofForm, UserRestrictTeamForm, UserGroupForm, AccountForm, CofRestrictForm, @@ -37,7 +37,7 @@ from kfet.forms import ( KPsulOperationGroupForm, KPsulAccountForm, KPsulCheckoutForm, KPsulOperationFormSet, AddcostForm, FilterHistoryForm, SettingsForm, TransferFormSet, InventoryArticleForm, OrderArticleForm, - OrderArticleToInventoryForm + OrderArticleToInventoryForm, CategoryForm ) from collections import defaultdict from kfet import consumers @@ -720,6 +720,38 @@ class CheckoutStatementUpdate(SuccessMessageMixin, UpdateView): form.instance.amount_taken = getAmountTaken(form.instance) return super(CheckoutStatementUpdate, self).form_valid(form) +# ----- +# Category views +# ----- + + +# Category - General +class CategoryList(ListView): + queryset = (ArticleCategory.objects + .prefetch_related('articles') + .order_by('name')) + template_name = 'kfet/category.html' + context_object_name = 'categories' + + +# Category - Update +class CategoryUpdate(SuccessMessageMixin, UpdateView): + model = ArticleCategory + template_name = 'kfet/category_update.html' + form_class = CategoryForm + success_url = reverse_lazy('kfet.category') + success_message = "Informations mises à jour pour la catégorie : %(name)s" + + # Surcharge de la validation + def form_valid(self, form): + # Checking permission + if not self.request.user.has_perm('kfet.change_articlecategory'): + form.add_error(None, 'Permission refusée') + return self.form_invalid(form) + + # Updating + return super(CategoryUpdate, self).form_valid(form) + # ----- # Article views # ----- From 7350006990cd663c9ef370c11efcc72db6e0446f Mon Sep 17 00:00:00 2001 From: Qwann Date: Tue, 4 Apr 2017 21:48:17 +0200 Subject: [PATCH 7/8] PEP8 --- kfet/urls.py | 26 ++++++++++----------- kfet/views.py | 62 +++++++++++++++++++++++++-------------------------- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/kfet/urls.py b/kfet/urls.py index aabbfc3c..fd9bfe54 100644 --- a/kfet/urls.py +++ b/kfet/urls.py @@ -8,7 +8,7 @@ from kfet.decorators import teamkfet_required urlpatterns = [ url(r'^$', views.Home.as_view(), - name = 'kfet.home'), + name='kfet.home'), url(r'^login/genericteam$', views.login_genericteam, name='kfet.login.genericteam'), url(r'^history$', views.history, @@ -71,26 +71,26 @@ urlpatterns = [ # Account - Statistics url('^accounts/(?P.{3})/stat/last/$', views.AccountStatLastAll.as_view(), - name = 'kfet.account.stat.last'), + name='kfet.account.stat.last'), url('^accounts/(?P.{3})/stat/last/month/$', views.AccountStatLastMonth.as_view(), - name = 'kfet.account.stat.last.month'), + name='kfet.account.stat.last.month'), url('^accounts/(?P.{3})/stat/last/week/$', views.AccountStatLastWeek.as_view(), - name = 'kfet.account.stat.last.week'), + name='kfet.account.stat.last.week'), url('^accounts/(?P.{3})/stat/last/day/$', views.AccountStatLastDay.as_view(), - name = 'kfet.account.stat.last.day'), + name='kfet.account.stat.last.day'), url('^accounts/(?P.{3})/stat/balance/$', views.AccountStatBalanceAll.as_view(), - name = 'kfet.account.stat.balance'), + name='kfet.account.stat.balance'), url('^accounts/(?P.{3})/stat/balance/d/(?P\d*)/$', views.AccountStatBalance.as_view(), - name = 'kfet.account.stat.balance.days'), + name='kfet.account.stat.balance.days'), url('^accounts/(?P.{3})/stat/balance/anytime/$', views.AccountStatBalance.as_view(), - name = 'kfet.account.stat.balance.anytime'), + name='kfet.account.stat.balance.anytime'), # ----- # Checkout urls @@ -157,20 +157,20 @@ urlpatterns = [ # Article - Update url('^articles/(?P\d+)/edit$', teamkfet_required(views.ArticleUpdate.as_view()), - name = 'kfet.article.update'), + name='kfet.article.update'), # Article - Statistics url('^articles/(?P\d+)/stat/last/$', views.ArticleStatLastAll.as_view(), - name = 'kfet.article.stat.last'), + name='kfet.article.stat.last'), url('^articles/(?P\d+)/stat/last/month/$', views.ArticleStatLastMonth.as_view(), - name = 'kfet.article.stat.last.month'), + name='kfet.article.stat.last.month'), url('^articles/(?P\d+)/stat/last/week/$', views.ArticleStatLastWeek.as_view(), - name = 'kfet.article.stat.last.week'), + name='kfet.article.stat.last.week'), url('^articles/(?P\d+)/stat/last/day/$', views.ArticleStatLastDay.as_view(), - name = 'kfet.article.stat.last.day'), + name='kfet.article.stat.last.day'), # ----- # K-Psul urls diff --git a/kfet/views.py b/kfet/views.py index 7cb37f28..4f23a3ae 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -756,24 +756,24 @@ class CategoryUpdate(SuccessMessageMixin, UpdateView): # Article views # ----- -# Article - General +# Article - General class ArticleList(ListView): queryset = (Article.objects - .select_related('category') - .prefetch_related(Prefetch('inventories', - queryset = Inventory.objects.order_by('-at'), - to_attr = 'inventory')) - .order_by('category', '-is_sold', 'name')) + .select_related('category') + .prefetch_related(Prefetch('inventories', + queryset=Inventory.objects.order_by('-at'), + to_attr='inventory')) + .order_by('category', '-is_sold', 'name')) template_name = 'kfet/article.html' context_object_name = 'articles' -# Article - Create +# Article - Create class ArticleCreate(SuccessMessageMixin, CreateView): - model = Article - template_name = 'kfet/article_create.html' - form_class = ArticleForm + model = Article + template_name = 'kfet/article_create.html' + form_class = ArticleForm success_message = 'Nouvel item : %(category)s - %(name)s' # Surcharge de la validation @@ -788,7 +788,7 @@ class ArticleCreate(SuccessMessageMixin, CreateView): # Save des suppliers déjà existant for supplier in form.cleaned_data['suppliers']: SupplierArticle.objects.create( - article = article, supplier = supplier) + article=article, supplier=supplier) # Nouveau supplier supplier_new = form.cleaned_data['supplier_new'].strip() @@ -797,49 +797,49 @@ class ArticleCreate(SuccessMessageMixin, CreateView): name=supplier_new) if created: SupplierArticle.objects.create( - article = article, supplier = supplier) + article=article, supplier=supplier) # Inventaire avec stock initial inventory = Inventory() inventory.by = self.request.user.profile.account_kfet inventory.save() InventoryArticle.objects.create( - inventory = inventory, - article = article, - stock_old = article.stock, - stock_new = article.stock, + inventory=inventory, + article=article, + stock_old=article.stock, + stock_new=article.stock, ) # Creating return super(ArticleCreate, self).form_valid(form) -# Article - Read +# Article - Read class ArticleRead(DetailView): - model = Article + model = Article template_name = 'kfet/article_read.html' context_object_name = 'article' def get_context_data(self, **kwargs): context = super(ArticleRead, self).get_context_data(**kwargs) inventoryarts = (InventoryArticle.objects - .filter(article = self.object) - .select_related('inventory') - .order_by('-inventory__at')) + .filter(article=self.object) + .select_related('inventory') + .order_by('-inventory__at')) context['inventoryarts'] = inventoryarts supplierarts = (SupplierArticle.objects - .filter(article = self.object) - .select_related('supplier') - .order_by('-at')) + .filter(article=self.object) + .select_related('supplier') + .order_by('-at')) context['supplierarts'] = supplierarts return context -# Article - Update +# Article - Update class ArticleUpdate(SuccessMessageMixin, UpdateView): - model = Article - template_name = 'kfet/article_update.html' - form_class = ArticleRestrictForm + model = Article + template_name = 'kfet/article_update.html' + form_class = ArticleRestrictForm success_message = "Informations mises à jour pour l'article : %(name)s" # Surcharge de la validation @@ -855,13 +855,13 @@ class ArticleUpdate(SuccessMessageMixin, UpdateView): for supplier in form.cleaned_data['suppliers']: if supplier not in article.suppliers.all(): SupplierArticle.objects.create( - article = article, supplier = supplier) + article=article, supplier=supplier) # On vire les suppliers désélectionnés for supplier in article.suppliers.all(): if supplier not in form.cleaned_data['suppliers']: SupplierArticle.objects.filter( - article = article, supplier = supplier).delete() + article=article, supplier=supplier).delete() # Nouveau supplier supplier_new = form.cleaned_data['supplier_new'].strip() @@ -870,7 +870,7 @@ class ArticleUpdate(SuccessMessageMixin, UpdateView): name=supplier_new) if created: SupplierArticle.objects.create( - article = article, supplier = supplier) + article=article, supplier=supplier) # Updating return super(ArticleUpdate, self).form_valid(form) From 3ee9de93d9a458d0bab750774c46ec9b1878a2ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Wed, 5 Apr 2017 15:34:28 +0200 Subject: [PATCH 8/8] few improvements on article category - add verbose names to ArticleCategory fields - add button to view categories list from articles list - fix article_update template in form validation - improve interface for articlecategory_update - revert vanished urls (happened in merge with master...) --- kfet/migrations/0052_category_addcost.py | 7 ++++++- kfet/models.py | 8 ++++++-- kfet/templates/kfet/article.html | 3 +++ kfet/templates/kfet/article_update.html | 2 +- kfet/templates/kfet/category.html | 2 +- kfet/templates/kfet/category_update.html | 24 ++++++++++++++++-------- kfet/urls.py | 6 ++++++ 7 files changed, 39 insertions(+), 13 deletions(-) diff --git a/kfet/migrations/0052_category_addcost.py b/kfet/migrations/0052_category_addcost.py index 62dab063..83346a1a 100644 --- a/kfet/migrations/0052_category_addcost.py +++ b/kfet/migrations/0052_category_addcost.py @@ -14,6 +14,11 @@ class Migration(migrations.Migration): migrations.AddField( model_name='articlecategory', name='has_addcost', - field=models.BooleanField(default=True), + field=models.BooleanField(default=True, help_text="Si oui et qu'une majoration est active, celle-ci sera appliquée aux articles de cette catégorie.", verbose_name='majorée'), + ), + migrations.AlterField( + model_name='articlecategory', + name='name', + field=models.CharField(max_length=45, verbose_name='nom'), ), ] diff --git a/kfet/models.py b/kfet/models.py index bee14156..cb8c324b 100644 --- a/kfet/models.py +++ b/kfet/models.py @@ -341,8 +341,12 @@ class CheckoutStatement(models.Model): @python_2_unicode_compatible class ArticleCategory(models.Model): - name = models.CharField(max_length=45) - has_addcost = models.BooleanField(default=True) + name = models.CharField("nom", max_length=45) + has_addcost = models.BooleanField("majorée", default=True, + help_text="Si oui et qu'une majoration " + "est active, celle-ci sera " + "appliquée aux articles de " + "cette catégorie.") def __str__(self): return self.name diff --git a/kfet/templates/kfet/article.html b/kfet/templates/kfet/article.html index 17c831df..123f4cfa 100644 --- a/kfet/templates/kfet/article.html +++ b/kfet/templates/kfet/article.html @@ -16,6 +16,9 @@ Nouvel article + + Catégories + diff --git a/kfet/templates/kfet/article_update.html b/kfet/templates/kfet/article_update.html index 85a29f6b..a3bfbcc6 100644 --- a/kfet/templates/kfet/article_update.html +++ b/kfet/templates/kfet/article_update.html @@ -12,7 +12,7 @@
-
+ {% csrf_token %} {% include 'kfet/form_snippet.html' with form=form %} {% if not perms.kfet.change_article %} diff --git a/kfet/templates/kfet/category.html b/kfet/templates/kfet/category.html index 4de44207..5393bf59 100644 --- a/kfet/templates/kfet/category.html +++ b/kfet/templates/kfet/category.html @@ -26,7 +26,7 @@ Nom Nombre d'articles - Peut-être majoré + Peut être majorée diff --git a/kfet/templates/kfet/category_update.html b/kfet/templates/kfet/category_update.html index fb04e12b..1a26d001 100644 --- a/kfet/templates/kfet/category_update.html +++ b/kfet/templates/kfet/category_update.html @@ -5,13 +5,21 @@ {% block content %} - - {% csrf_token %} - {{ form.as_p }} - {% if not perms.kfet.change_articlecategory %} - - {% endif %} - -
+{% include "kfet/base_messages.html" %} + +
+
+
+
+ {% csrf_token %} + {% include 'kfet/form_snippet.html' with form=form %} + {% if not perms.kfet.edit_articlecategory %} + {% include 'kfet/form_authentication_snippet.html' %} + {% endif %} + {% include 'kfet/form_submit_snippet.html' with value="Enregistrer"%} + +
+
+
{% endblock %} diff --git a/kfet/urls.py b/kfet/urls.py index a4393f8d..bc1f3370 100644 --- a/kfet/urls.py +++ b/kfet/urls.py @@ -69,6 +69,12 @@ urlpatterns = [ name='kfet.account.negative'), # Account - Statistics + url(r'^accounts/(?P.{3})/stat/operations/list$', + views.AccountStatOperationList.as_view(), + name='kfet.account.stat.operation.list'), + url(r'^accounts/(?P.{3})/stat/operations$', + views.AccountStatOperation.as_view(), + name='kfet.account.stat.operation'), url(r'^accounts/(?P.{3})/stat/balance/list$', views.AccountStatBalanceList.as_view(),