From 5cb75ec3ebf661d0677d5fe1cc3c97eb59d8bc34 Mon Sep 17 00:00:00 2001 From: guillaume-renaud Date: Mon, 14 Nov 2016 00:38:33 +0100 Subject: [PATCH] general modifications --- counter/templates/counter/counter_list.jinja | 4 +-- stock/migrations/0002_auto_20161113_2325.py | 31 ++++++++++++++++++++ stock/models.py | 18 ++++++++---- stock/templates/stock/stock_item_list.jinja | 15 ++++++++++ stock/templates/stock/stock_list.jinja | 2 +- stock/urls.py | 7 +++-- stock/views.py | 22 ++++++++++---- 7 files changed, 82 insertions(+), 17 deletions(-) create mode 100644 stock/migrations/0002_auto_20161113_2325.py create mode 100644 stock/templates/stock/stock_item_list.jinja diff --git a/counter/templates/counter/counter_list.jinja b/counter/templates/counter/counter_list.jinja index 0dc72d1f..5ecdf358 100644 --- a/counter/templates/counter/counter_list.jinja +++ b/counter/templates/counter/counter_list.jinja @@ -32,9 +32,9 @@ {% trans %}Edit{% endtrans %} - {% trans %}Stats{% endtrans %} - {%if c.stock %} - Stock - + Stock - {% else %} - {% trans %}Create new stock{% endtrans%} - + {% trans %}Create new stock{% endtrans%} - {% endif %} {% endif %} {% if user.is_owner(c) %} diff --git a/stock/migrations/0002_auto_20161113_2325.py b/stock/migrations/0002_auto_20161113_2325.py new file mode 100644 index 00000000..8f36b593 --- /dev/null +++ b/stock/migrations/0002_auto_20161113_2325.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('counter', '0011_auto_20161004_2039'), + ('stock', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='stockitem', + name='type', + field=models.ForeignKey(to='counter.ProductType', blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, verbose_name='type', related_name='stockItem_type'), + ), + migrations.AlterField( + model_name='stockitem', + name='effective_quantity', + field=models.IntegerField(help_text='total number of bottle/barrel', verbose_name='effective quantity', default=0), + ), + migrations.AlterField( + model_name='stockitem', + name='unit_quantity', + field=models.IntegerField(help_text='number of beer in one crate (equal one for barrels)', verbose_name='unit quantity', default=0), + ), + ] diff --git a/stock/models.py b/stock/models.py index 50336f72..4b2cccfd 100644 --- a/stock/models.py +++ b/stock/models.py @@ -2,11 +2,12 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ from django.core.urlresolvers import reverse - -from counter.models import Counter +from counter.models import Counter, ProductType class Stock(models.Model): - """ The Stock class, this one is used to know how many products are left for a specific counter """ + """ + The Stock class, this one is used to know how many products are left for a specific counter + """ name = models.CharField(_('name'), max_length=64) counter = models.OneToOneField(Counter, verbose_name=_('counter'), related_name='stock') @@ -17,12 +18,17 @@ class Stock(models.Model): return reverse('stock:list') class StockItem(models.Model): - """ The StockItem class, element of the stock """ + """ + The StockItem class, element of the stock + """ name = models.CharField(_('name'), max_length=64) - unit_quantity = models.IntegerField(_('unit quantity'), default=0) - effective_quantity = models.IntegerField(_('effective quantity'), default=0) + unit_quantity = models.IntegerField(_('unit quantity'), default=0, help_text='number of beer in one crate (equal one for barrels)') + effective_quantity = models.IntegerField(_('effective quantity'), default=0, help_text='total number of bottle/barrel') + type = models.ForeignKey(ProductType, related_name="stockItem_type", verbose_name=_("type"), null=True, blank=True, + on_delete=models.SET_NULL) stock_owner = models.ForeignKey(Stock, related_name="stock_owner") + def __str__(self): return "%s (%s)" % (self.name, self.stock_owner) diff --git a/stock/templates/stock/stock_item_list.jinja b/stock/templates/stock/stock_item_list.jinja new file mode 100644 index 00000000..77ccab36 --- /dev/null +++ b/stock/templates/stock/stock_item_list.jinja @@ -0,0 +1,15 @@ +{% extends "core/base.jinja" %} + +{% block title %} +{% trans s=stock %}{{stock}}{% endtrans %} +{% endblock %} + +{% block content %} +{% if current_tab == "stocks" %} +

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

+{% endif %} +

{% trans s=stock %}{{stock}}{% endtrans %}

+ + + +{% endblock %} \ No newline at end of file diff --git a/stock/templates/stock/stock_list.jinja b/stock/templates/stock/stock_list.jinja index 0b3b6122..5e3ed145 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/urls.py b/stock/urls.py index e824f657..f5c8e868 100644 --- a/stock/urls.py +++ b/stock/urls.py @@ -3,9 +3,12 @@ from django.conf.urls import include, url from stock.views import * urlpatterns = [ - url(r'^(?P[0-9]+)$', StockMain.as_view(), name='main'), +#Stock urls url(r'^new/counter/(?P[0-9]+)$', StockCreateView.as_view(), name='new'), url(r'^edit/(?P[0-9]+)$', StockEditView.as_view(), name='edit'), url(r'^list$', StockListView.as_view(), name='list'), - url(r'^(?P[0-9]+)/newItem$', StockItemCreateView.as_view(), name='new_item'), + +# StockItem urls + url(r'^(?P[0-9]+)$', StockItemList.as_view(), name='items_list'), + url(r'^(?P[0-9]+)/stockItem/newItem$', StockItemCreateView.as_view(), name='new_item'), ] diff --git a/stock/views.py b/stock/views.py index 6a3c8a86..2d259dcf 100644 --- a/stock/views.py +++ b/stock/views.py @@ -6,8 +6,6 @@ from django import forms from django.forms.models import modelform_factory from django.core.urlresolvers import reverse_lazy, reverse - - from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin, TabedViewMixin from counter.views import CounterAdminTabsMixin from counter.models import Counter @@ -19,11 +17,17 @@ class StockMain(CounterAdminTabsMixin, CanCreateMixin, DetailView): """ The stock view for the counter owner """ - model = Stock - template_name = 'stock/stock_main.jinja' + model = StockItem + template_name = 'stock/stock_item_list.jinja' 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 @@ -70,13 +74,19 @@ class StockCreateView(CounterAdminTabsMixin, CanCreateMixin, CreateView): current_tab = "stocks" success_url = reverse_lazy('stock:list') - + def get_initial(self): + ret = super(StockCreateView, self).get_initial() + if 'counter' in self.request.GET.keys(): + ret['counter'] = self.request.GET['counter'] + return ret + 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', 'stock_owner']) + form_class = modelform_factory(StockItem, fields=['name', 'unit_quantity', 'effective_quantity', 'type', 'stock_owner']) template_name = 'core/create.jinja' pk_url_kwarg = "stock_id" current_tab = "stocks"