diff --git a/stock/templates/stock/stock_item_list.jinja b/stock/templates/stock/stock_item_list.jinja index cac5fb30..ef1a3a4d 100644 --- a/stock/templates/stock/stock_item_list.jinja +++ b/stock/templates/stock/stock_item_list.jinja @@ -7,6 +7,7 @@ {% block content %} {% if current_tab == "stocks" %}

{% trans %}New item{% endtrans %}

+
{% trans %}Shopping list{% endtrans %}
{% endif %} {% if stock %}

{{ stock }}

diff --git a/stock/templates/stock/stock_list.jinja b/stock/templates/stock/stock_list.jinja index b0450984..829ad6c5 100644 --- a/stock/templates/stock/stock_list.jinja +++ b/stock/templates/stock/stock_list.jinja @@ -11,7 +11,7 @@ {% for s in stock_list.order_by('name') %}
  • {% if user.can_edit(s) %} - {{s}} + {{s}} - Edit {% endif %}
  • diff --git a/stock/templates/stock/stock_shopping_list.jinja b/stock/templates/stock/stock_shopping_list.jinja new file mode 100644 index 00000000..96b48085 --- /dev/null +++ b/stock/templates/stock/stock_shopping_list.jinja @@ -0,0 +1,10 @@ +{% extends "core/base.jinja" %} + +{% block title %} +Shopping list for {{ stock }} +{% endblock %} + +{% block content %} +

    Shopping list for {{ stock }}

    + +{% endblock %} \ No newline at end of file diff --git a/stock/urls.py b/stock/urls.py index 436f7a4d..d7512b24 100644 --- a/stock/urls.py +++ b/stock/urls.py @@ -12,5 +12,5 @@ urlpatterns = [ url(r'^(?P[0-9]+)$', StockItemList.as_view(), name='items_list'), url(r'^(?P[0-9]+)/stockItem/newItem$', StockItemCreateView.as_view(), name='new_item'), url(r'^stockItem/(?P[0-9]+)/edit$', StockItemEditView.as_view(), name='edit_item'), - + url(r'^(?P[0-9]+)/shopping$', StockShoppingListView.as_view(), name='shopping_list'), ] diff --git a/stock/views.py b/stock/views.py index e38e21db..0f8af903 100644 --- a/stock/views.py +++ b/stock/views.py @@ -13,7 +13,7 @@ from stock.models import Stock, StockItem -class StockMain(CounterAdminTabsMixin, CanCreateMixin, DetailView): +class StockItemList(CounterAdminTabsMixin, CanCreateMixin, ListView): """ The stockitems list view for the counter owner """ @@ -22,12 +22,6 @@ class StockMain(CounterAdminTabsMixin, CanCreateMixin, DetailView): pk_url_kwarg = "stock_id" current_tab = "stocks" - #def get_context_data(self, **kwargs): - # context = super(StockItemList, self).get_context_data(**kwargs) - # if 'stock' in self.request.GET.keys(): - # context['stock'] = Stock.objects.filter(id=self.request.GET['stock']).first() - # return context - class StockListView(CounterAdminTabsMixin, CanViewMixin, ListView): """ A list view for the admins @@ -94,8 +88,7 @@ class StockCreateView(CounterAdminTabsMixin, CanCreateMixin, CreateView): class StockItemCreateView(CounterAdminTabsMixin, CanCreateMixin, CreateView): """ A create view for a new StockItem - """ - + """ model = StockItem form_class = modelform_factory(StockItem, fields=['name', 'unit_quantity', 'effective_quantity', 'type', 'stock_owner']) template_name = 'core/create.jinja' @@ -109,6 +102,20 @@ class StockItemCreateView(CounterAdminTabsMixin, CanCreateMixin, CreateView): return ret def get_success_url(self): - return reverse_lazy('stock:items_list', kwargs={'stock_id':self.object.stock_owner.id}) + '?stock=' + str(self.object.stock_owner.id) + return reverse_lazy('stock:items_list', kwargs={'stock_id':self.object.stock_owner.id}) - + +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