Finish back up app Stock

This commit is contained in:
guillaume-renaud 2017-01-05 00:52:27 +01:00
parent fa97929da8
commit 62200827c2
2 changed files with 17 additions and 6 deletions

View File

@ -1,6 +1,8 @@
from django.db import models from django.db import models
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.conf import settings
from counter.models import Counter, ProductType from counter.models import Counter, ProductType
@ -17,6 +19,9 @@ class Stock(models.Model):
def get_absolute_url(self): def get_absolute_url(self):
return reverse('stock:list') return reverse('stock:list')
def can_be_viewed_by(self, user):
return user.is_in_group(settings.SITH_GROUP_COUNTER_ADMIN_ID)
class StockItem(models.Model): class StockItem(models.Model):
""" """
The StockItem class, element of the stock The StockItem class, element of the stock
@ -34,6 +39,9 @@ class StockItem(models.Model):
def get_absolute_url(self): def get_absolute_url(self):
return reverse('stock:items_list', kwargs={'stock_id':self.stock_owner.id}) return reverse('stock:items_list', kwargs={'stock_id':self.stock_owner.id})
def can_be_viewed_by(self, user):
return user.is_in_group(settings.SITH_GROUP_COUNTER_ADMIN_ID)
class ShoppingList(models.Model): class ShoppingList(models.Model):
""" """
The ShoppingList class, used to make an history of the shopping lists The ShoppingList class, used to make an history of the shopping lists
@ -49,3 +57,6 @@ class ShoppingList(models.Model):
def get_absolute_url(self): def get_absolute_url(self):
return reverse('stock:shoppinglist_list') return reverse('stock:shoppinglist_list')
def can_be_viewed_by(self, user):
return user.is_in_group(settings.SITH_GROUP_COUNTER_ADMIN_ID)

View File

@ -22,8 +22,11 @@ class StockItemList(CounterAdminTabsMixin, CanCreateMixin, ListView):
pk_url_kwarg = "stock_id" pk_url_kwarg = "stock_id"
current_tab = "stocks" current_tab = "stocks"
def can_be_viewed_by(self, user): def get_context_data(self):
return user.is_in_group(settings.SITH_GROUP_COUNTER_ADMIN_ID) ret = super(StockItemList, self).get_context_data()
if 'stock_id' in self.kwargs.keys():
ret['stock'] = Stock.objects.filter(id=self.kwargs['stock_id']).first();
return ret
class StockListView(CounterAdminTabsMixin, CanViewMixin, ListView): class StockListView(CounterAdminTabsMixin, CanViewMixin, ListView):
""" """
@ -35,7 +38,7 @@ class StockListView(CounterAdminTabsMixin, CanViewMixin, ListView):
def can_be_viewed_by(self, user): def can_be_viewed_by(self, user):
return user.is_in_group(settings.SITH_GROUP_COUNTER_ADMIN_ID) return user.is_in_group(settings.SITH_GROUP_COUNTER_ADMIN_ID)
class StockEditForm(forms.ModelForm): class StockEditForm(forms.ModelForm):
""" """
@ -66,9 +69,6 @@ class StockEditView(CounterAdminTabsMixin, CanEditPropMixin, UpdateView):
if 'stock' in self.request.GET.keys(): if 'stock' in self.request.GET.keys():
context['stock'] = Stock.objects.filter(id=self.request.GET['stock']).first() context['stock'] = Stock.objects.filter(id=self.request.GET['stock']).first()
return context return context
def can_be_viewed_by(self, user):
return user.is_in_group(settings.SITH_GROUP_COUNTER_ADMIN_ID)
class StockItemEditView(CounterAdminTabsMixin, CanEditPropMixin, UpdateView): class StockItemEditView(CounterAdminTabsMixin, CanEditPropMixin, UpdateView):