This commit is contained in:
Qwann 2017-04-04 21:48:17 +02:00
parent ba11aa49db
commit 7350006990
2 changed files with 44 additions and 44 deletions

View file

@ -8,7 +8,7 @@ from kfet.decorators import teamkfet_required
urlpatterns = [ urlpatterns = [
url(r'^$', views.Home.as_view(), url(r'^$', views.Home.as_view(),
name = 'kfet.home'), name='kfet.home'),
url(r'^login/genericteam$', views.login_genericteam, url(r'^login/genericteam$', views.login_genericteam,
name='kfet.login.genericteam'), name='kfet.login.genericteam'),
url(r'^history$', views.history, url(r'^history$', views.history,
@ -71,26 +71,26 @@ urlpatterns = [
# Account - Statistics # Account - Statistics
url('^accounts/(?P<trigramme>.{3})/stat/last/$', url('^accounts/(?P<trigramme>.{3})/stat/last/$',
views.AccountStatLastAll.as_view(), views.AccountStatLastAll.as_view(),
name = 'kfet.account.stat.last'), name='kfet.account.stat.last'),
url('^accounts/(?P<trigramme>.{3})/stat/last/month/$', url('^accounts/(?P<trigramme>.{3})/stat/last/month/$',
views.AccountStatLastMonth.as_view(), views.AccountStatLastMonth.as_view(),
name = 'kfet.account.stat.last.month'), name='kfet.account.stat.last.month'),
url('^accounts/(?P<trigramme>.{3})/stat/last/week/$', url('^accounts/(?P<trigramme>.{3})/stat/last/week/$',
views.AccountStatLastWeek.as_view(), views.AccountStatLastWeek.as_view(),
name = 'kfet.account.stat.last.week'), name='kfet.account.stat.last.week'),
url('^accounts/(?P<trigramme>.{3})/stat/last/day/$', url('^accounts/(?P<trigramme>.{3})/stat/last/day/$',
views.AccountStatLastDay.as_view(), views.AccountStatLastDay.as_view(),
name = 'kfet.account.stat.last.day'), name='kfet.account.stat.last.day'),
url('^accounts/(?P<trigramme>.{3})/stat/balance/$', url('^accounts/(?P<trigramme>.{3})/stat/balance/$',
views.AccountStatBalanceAll.as_view(), views.AccountStatBalanceAll.as_view(),
name = 'kfet.account.stat.balance'), name='kfet.account.stat.balance'),
url('^accounts/(?P<trigramme>.{3})/stat/balance/d/(?P<nb_date>\d*)/$', url('^accounts/(?P<trigramme>.{3})/stat/balance/d/(?P<nb_date>\d*)/$',
views.AccountStatBalance.as_view(), views.AccountStatBalance.as_view(),
name = 'kfet.account.stat.balance.days'), name='kfet.account.stat.balance.days'),
url('^accounts/(?P<trigramme>.{3})/stat/balance/anytime/$', url('^accounts/(?P<trigramme>.{3})/stat/balance/anytime/$',
views.AccountStatBalance.as_view(), views.AccountStatBalance.as_view(),
name = 'kfet.account.stat.balance.anytime'), name='kfet.account.stat.balance.anytime'),
# ----- # -----
# Checkout urls # Checkout urls
@ -157,20 +157,20 @@ urlpatterns = [
# Article - Update # Article - Update
url('^articles/(?P<pk>\d+)/edit$', url('^articles/(?P<pk>\d+)/edit$',
teamkfet_required(views.ArticleUpdate.as_view()), teamkfet_required(views.ArticleUpdate.as_view()),
name = 'kfet.article.update'), name='kfet.article.update'),
# Article - Statistics # Article - Statistics
url('^articles/(?P<pk>\d+)/stat/last/$', url('^articles/(?P<pk>\d+)/stat/last/$',
views.ArticleStatLastAll.as_view(), views.ArticleStatLastAll.as_view(),
name = 'kfet.article.stat.last'), name='kfet.article.stat.last'),
url('^articles/(?P<pk>\d+)/stat/last/month/$', url('^articles/(?P<pk>\d+)/stat/last/month/$',
views.ArticleStatLastMonth.as_view(), views.ArticleStatLastMonth.as_view(),
name = 'kfet.article.stat.last.month'), name='kfet.article.stat.last.month'),
url('^articles/(?P<pk>\d+)/stat/last/week/$', url('^articles/(?P<pk>\d+)/stat/last/week/$',
views.ArticleStatLastWeek.as_view(), views.ArticleStatLastWeek.as_view(),
name = 'kfet.article.stat.last.week'), name='kfet.article.stat.last.week'),
url('^articles/(?P<pk>\d+)/stat/last/day/$', url('^articles/(?P<pk>\d+)/stat/last/day/$',
views.ArticleStatLastDay.as_view(), views.ArticleStatLastDay.as_view(),
name = 'kfet.article.stat.last.day'), name='kfet.article.stat.last.day'),
# ----- # -----
# K-Psul urls # K-Psul urls

View file

@ -756,24 +756,24 @@ class CategoryUpdate(SuccessMessageMixin, UpdateView):
# Article views # Article views
# ----- # -----
# Article - General
# Article - General
class ArticleList(ListView): class ArticleList(ListView):
queryset = (Article.objects queryset = (Article.objects
.select_related('category') .select_related('category')
.prefetch_related(Prefetch('inventories', .prefetch_related(Prefetch('inventories',
queryset = Inventory.objects.order_by('-at'), queryset=Inventory.objects.order_by('-at'),
to_attr = 'inventory')) to_attr='inventory'))
.order_by('category', '-is_sold', 'name')) .order_by('category', '-is_sold', 'name'))
template_name = 'kfet/article.html' template_name = 'kfet/article.html'
context_object_name = 'articles' context_object_name = 'articles'
# Article - Create
# Article - Create
class ArticleCreate(SuccessMessageMixin, CreateView): class ArticleCreate(SuccessMessageMixin, CreateView):
model = Article model = Article
template_name = 'kfet/article_create.html' template_name = 'kfet/article_create.html'
form_class = ArticleForm form_class = ArticleForm
success_message = 'Nouvel item : %(category)s - %(name)s' success_message = 'Nouvel item : %(category)s - %(name)s'
# Surcharge de la validation # Surcharge de la validation
@ -788,7 +788,7 @@ class ArticleCreate(SuccessMessageMixin, CreateView):
# Save des suppliers déjà existant # Save des suppliers déjà existant
for supplier in form.cleaned_data['suppliers']: for supplier in form.cleaned_data['suppliers']:
SupplierArticle.objects.create( SupplierArticle.objects.create(
article = article, supplier = supplier) article=article, supplier=supplier)
# Nouveau supplier # Nouveau supplier
supplier_new = form.cleaned_data['supplier_new'].strip() supplier_new = form.cleaned_data['supplier_new'].strip()
@ -797,49 +797,49 @@ class ArticleCreate(SuccessMessageMixin, CreateView):
name=supplier_new) name=supplier_new)
if created: if created:
SupplierArticle.objects.create( SupplierArticle.objects.create(
article = article, supplier = supplier) article=article, supplier=supplier)
# Inventaire avec stock initial # Inventaire avec stock initial
inventory = Inventory() inventory = Inventory()
inventory.by = self.request.user.profile.account_kfet inventory.by = self.request.user.profile.account_kfet
inventory.save() inventory.save()
InventoryArticle.objects.create( InventoryArticle.objects.create(
inventory = inventory, inventory=inventory,
article = article, article=article,
stock_old = article.stock, stock_old=article.stock,
stock_new = article.stock, stock_new=article.stock,
) )
# Creating # Creating
return super(ArticleCreate, self).form_valid(form) return super(ArticleCreate, self).form_valid(form)
# Article - Read
# Article - Read
class ArticleRead(DetailView): class ArticleRead(DetailView):
model = Article model = Article
template_name = 'kfet/article_read.html' template_name = 'kfet/article_read.html'
context_object_name = 'article' context_object_name = 'article'
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(ArticleRead, self).get_context_data(**kwargs) context = super(ArticleRead, self).get_context_data(**kwargs)
inventoryarts = (InventoryArticle.objects inventoryarts = (InventoryArticle.objects
.filter(article = self.object) .filter(article=self.object)
.select_related('inventory') .select_related('inventory')
.order_by('-inventory__at')) .order_by('-inventory__at'))
context['inventoryarts'] = inventoryarts context['inventoryarts'] = inventoryarts
supplierarts = (SupplierArticle.objects supplierarts = (SupplierArticle.objects
.filter(article = self.object) .filter(article=self.object)
.select_related('supplier') .select_related('supplier')
.order_by('-at')) .order_by('-at'))
context['supplierarts'] = supplierarts context['supplierarts'] = supplierarts
return context return context
# Article - Update
# Article - Update
class ArticleUpdate(SuccessMessageMixin, UpdateView): class ArticleUpdate(SuccessMessageMixin, UpdateView):
model = Article model = Article
template_name = 'kfet/article_update.html' template_name = 'kfet/article_update.html'
form_class = ArticleRestrictForm form_class = ArticleRestrictForm
success_message = "Informations mises à jour pour l'article : %(name)s" success_message = "Informations mises à jour pour l'article : %(name)s"
# Surcharge de la validation # Surcharge de la validation
@ -855,13 +855,13 @@ class ArticleUpdate(SuccessMessageMixin, UpdateView):
for supplier in form.cleaned_data['suppliers']: for supplier in form.cleaned_data['suppliers']:
if supplier not in article.suppliers.all(): if supplier not in article.suppliers.all():
SupplierArticle.objects.create( SupplierArticle.objects.create(
article = article, supplier = supplier) article=article, supplier=supplier)
# On vire les suppliers désélectionnés # On vire les suppliers désélectionnés
for supplier in article.suppliers.all(): for supplier in article.suppliers.all():
if supplier not in form.cleaned_data['suppliers']: if supplier not in form.cleaned_data['suppliers']:
SupplierArticle.objects.filter( SupplierArticle.objects.filter(
article = article, supplier = supplier).delete() article=article, supplier=supplier).delete()
# Nouveau supplier # Nouveau supplier
supplier_new = form.cleaned_data['supplier_new'].strip() supplier_new = form.cleaned_data['supplier_new'].strip()
@ -870,7 +870,7 @@ class ArticleUpdate(SuccessMessageMixin, UpdateView):
name=supplier_new) name=supplier_new)
if created: if created:
SupplierArticle.objects.create( SupplierArticle.objects.create(
article = article, supplier = supplier) article=article, supplier=supplier)
# Updating # Updating
return super(ArticleUpdate, self).form_valid(form) return super(ArticleUpdate, self).form_valid(form)