2016-11-11 15:55:52 +00:00
|
|
|
from django.shortcuts import render, get_object_or_404
|
2016-11-08 17:14:41 +00:00
|
|
|
from django.views.generic import ListView, DetailView, RedirectView, TemplateView
|
|
|
|
from django.views.generic.edit import UpdateView, CreateView, DeleteView, ProcessFormView, FormMixin
|
2016-11-09 16:49:19 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
from django import forms
|
|
|
|
from django.forms.models import modelform_factory
|
|
|
|
from django.core.urlresolvers import reverse_lazy, reverse
|
2016-10-26 15:20:42 +00:00
|
|
|
|
2016-11-09 16:49:19 +00:00
|
|
|
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin, TabedViewMixin
|
|
|
|
from counter.views import CounterAdminTabsMixin
|
|
|
|
from counter.models import Counter
|
|
|
|
from stock.models import Stock, StockItem
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-11-24 09:40:42 +00:00
|
|
|
class StockItemList(CounterAdminTabsMixin, CanCreateMixin, ListView):
|
2016-11-08 17:14:41 +00:00
|
|
|
"""
|
2016-11-16 16:17:17 +00:00
|
|
|
The stockitems list view for the counter owner
|
2016-11-08 17:14:41 +00:00
|
|
|
"""
|
2016-11-16 16:17:17 +00:00
|
|
|
model = Stock
|
2016-11-13 23:38:33 +00:00
|
|
|
template_name = 'stock/stock_item_list.jinja'
|
2016-11-08 17:14:41 +00:00
|
|
|
pk_url_kwarg = "stock_id"
|
2016-11-09 16:49:19 +00:00
|
|
|
current_tab = "stocks"
|
|
|
|
|
|
|
|
class StockListView(CounterAdminTabsMixin, CanViewMixin, ListView):
|
|
|
|
"""
|
|
|
|
A list view for the admins
|
|
|
|
"""
|
|
|
|
model = Stock
|
|
|
|
template_name = 'stock/stock_list.jinja'
|
|
|
|
current_tab = "stocks"
|
|
|
|
|
|
|
|
|
|
|
|
class StockEditForm(forms.ModelForm):
|
|
|
|
"""
|
2016-11-16 16:17:17 +00:00
|
|
|
A form to change stock's characteristics
|
2016-11-09 16:49:19 +00:00
|
|
|
"""
|
|
|
|
class Meta:
|
|
|
|
model = Stock
|
2016-11-11 15:55:52 +00:00
|
|
|
fields = ['name', 'counter']
|
2016-11-09 16:49:19 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(StockEditForm, self).__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
return super(StockEditForm, self).save(*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
class StockEditView(CounterAdminTabsMixin, CanEditPropMixin, UpdateView):
|
|
|
|
"""
|
2016-11-16 16:17:17 +00:00
|
|
|
An edit view for the stock
|
2016-11-09 16:49:19 +00:00
|
|
|
"""
|
|
|
|
model = Stock
|
|
|
|
form_class = StockEditForm
|
|
|
|
pk_url_kwarg = "stock_id"
|
|
|
|
template_name = 'core/edit.jinja'
|
|
|
|
current_tab = "stocks"
|
2016-11-08 17:14:41 +00:00
|
|
|
|
2016-11-09 16:49:19 +00:00
|
|
|
|
2016-11-16 16:17:17 +00:00
|
|
|
class StockItemEditView(CounterAdminTabsMixin, CanEditPropMixin, UpdateView):
|
|
|
|
"""
|
|
|
|
An edit view for a stock item
|
|
|
|
"""
|
|
|
|
model = StockItem
|
|
|
|
form_class = modelform_factory(StockItem, fields=['name', 'unit_quantity', 'effective_quantity', 'type', 'stock_owner'])
|
|
|
|
pk_url_kwarg = "item_id"
|
|
|
|
template_name = 'core/edit.jinja'
|
|
|
|
current_tab = "stocks"
|
|
|
|
|
|
|
|
|
2016-11-09 16:49:19 +00:00
|
|
|
class StockCreateView(CounterAdminTabsMixin, CanCreateMixin, CreateView):
|
2016-11-08 17:14:41 +00:00
|
|
|
"""
|
2016-11-09 16:49:19 +00:00
|
|
|
A create view for a new Stock
|
2016-11-08 17:14:41 +00:00
|
|
|
"""
|
2016-11-09 16:49:19 +00:00
|
|
|
model = Stock
|
|
|
|
form_class = modelform_factory(Stock, fields=['name', 'counter'])
|
|
|
|
template_name = 'core/create.jinja'
|
|
|
|
pk_url_kwarg = "counter_id"
|
|
|
|
current_tab = "stocks"
|
|
|
|
success_url = reverse_lazy('stock:list')
|
|
|
|
|
2016-11-13 23:38:33 +00:00
|
|
|
def get_initial(self):
|
|
|
|
ret = super(StockCreateView, self).get_initial()
|
2016-11-16 16:17:17 +00:00
|
|
|
if 'counter_id' in self.kwargs.keys():
|
|
|
|
ret['counter'] = self.kwargs['counter_id']
|
2016-11-13 23:38:33 +00:00
|
|
|
return ret
|
|
|
|
|
2016-11-09 16:49:19 +00:00
|
|
|
class StockItemCreateView(CounterAdminTabsMixin, CanCreateMixin, CreateView):
|
2016-11-08 17:14:41 +00:00
|
|
|
"""
|
2016-11-09 16:49:19 +00:00
|
|
|
A create view for a new StockItem
|
2016-11-24 09:40:42 +00:00
|
|
|
"""
|
2016-11-09 16:49:19 +00:00
|
|
|
model = StockItem
|
2016-11-13 23:38:33 +00:00
|
|
|
form_class = modelform_factory(StockItem, fields=['name', 'unit_quantity', 'effective_quantity', 'type', 'stock_owner'])
|
2016-11-09 16:49:19 +00:00
|
|
|
template_name = 'core/create.jinja'
|
|
|
|
pk_url_kwarg = "stock_id"
|
|
|
|
current_tab = "stocks"
|
2016-11-11 15:55:52 +00:00
|
|
|
|
|
|
|
def get_initial(self):
|
|
|
|
ret = super(StockItemCreateView, self).get_initial()
|
2016-11-16 16:17:17 +00:00
|
|
|
if 'stock_id' in self.kwargs.keys():
|
|
|
|
ret['stock_owner'] = self.kwargs['stock_id']
|
2016-11-11 15:55:52 +00:00
|
|
|
return ret
|
|
|
|
|
2016-11-09 16:49:19 +00:00
|
|
|
def get_success_url(self):
|
2016-11-24 09:40:42 +00:00
|
|
|
return reverse_lazy('stock:items_list', kwargs={'stock_id':self.object.stock_owner.id})
|
2016-11-16 16:17:17 +00:00
|
|
|
|
2016-11-24 09:40:42 +00:00
|
|
|
|
|
|
|
class StockShoppingListView(CounterAdminTabsMixin, CanViewMixin, ListView):
|
|
|
|
"""
|
|
|
|
A list view for the people to know the item to buy
|
|
|
|
"""
|
|
|
|
model = Stock
|
|
|
|
template_name = "stock/stock_shopping_list.jinja"
|
|
|
|
pk_url_kwarg = "stock_id"
|
|
|
|
current_tab = "stocks"
|
|
|
|
|
|
|
|
def get_context_data(self):
|
|
|
|
ret = super(StockShoppingListView, self).get_context_data()
|
|
|
|
if 'stock_id' in self.kwargs.keys():
|
|
|
|
ret['stock'] = Stock.objects.filter(id=self.kwargs['stock_id']).first();
|
|
|
|
return ret
|