Stock admin gestion, items list views, create and edit items

This commit is contained in:
guillaume-renaud 2016-11-16 17:17:17 +01:00
parent 5cb75ec3eb
commit 6c54b246ca
8 changed files with 95 additions and 2890 deletions

View File

@ -32,9 +32,9 @@
<a href="{{ url('counter:admin', counter_id=c.id) }}">{% trans %}Edit{% endtrans %}</a> - <a href="{{ url('counter:admin', counter_id=c.id) }}">{% trans %}Edit{% endtrans %}</a> -
<a href="{{ url('counter:stats', counter_id=c.id) }}">{% trans %}Stats{% endtrans %}</a> - <a href="{{ url('counter:stats', counter_id=c.id) }}">{% trans %}Stats{% endtrans %}</a> -
{%if c.stock %} {%if c.stock %}
<a href="{{ url('stock:items_list', stock_id=c.stock.id)}}?stock={{c.stock.id}}">Stock</a> - <a href="{{ url('stock:items_list', stock_id=c.stock.id)}}">Stock</a> -
{% else %} {% else %}
<a href="{{url('stock:new', counter_id=c.id)}}?counter={{c.id}}">{% trans %}Create new stock{% endtrans%}</a> - <a href="{{url('stock:new', counter_id=c.id)}}">{% trans %}Create new stock{% endtrans%}</a> -
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if user.is_owner(c) %} {% if user.is_owner(c) %}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('stock', '0002_auto_20161113_2325'),
]
operations = [
migrations.AlterField(
model_name='stockitem',
name='effective_quantity',
field=models.IntegerField(default=0, verbose_name='effective quantity', help_text='number of box'),
),
migrations.AlterField(
model_name='stockitem',
name='stock_owner',
field=models.ForeignKey(related_name='items', to='stock.Stock'),
),
migrations.AlterField(
model_name='stockitem',
name='type',
field=models.ForeignKey(related_name='stock_items', verbose_name='type', null=True, to='counter.ProductType', blank=True, on_delete=django.db.models.deletion.SET_NULL),
),
migrations.AlterField(
model_name='stockitem',
name='unit_quantity',
field=models.IntegerField(default=0, verbose_name='unit quantity', help_text='number of element in one box'),
),
]

View File

@ -22,13 +22,15 @@ 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) name = models.CharField(_('name'), max_length=64)
unit_quantity = models.IntegerField(_('unit quantity'), default=0, help_text='number of beer in one crate (equal one for barrels)') unit_quantity = models.IntegerField(_('unit quantity'), default=0, help_text='number of element in one box')
effective_quantity = models.IntegerField(_('effective quantity'), default=0, help_text='total number of bottle/barrel') effective_quantity = models.IntegerField(_('effective quantity'), default=0, help_text='number of box')
type = models.ForeignKey(ProductType, related_name="stockItem_type", verbose_name=_("type"), null=True, blank=True, type = models.ForeignKey(ProductType, related_name="stock_items", verbose_name=_("type"), null=True, blank=True,
on_delete=models.SET_NULL) on_delete=models.SET_NULL)
stock_owner = models.ForeignKey(Stock, related_name="stock_owner") stock_owner = models.ForeignKey(Stock, related_name="items")
def __str__(self): def __str__(self):
return "%s (%s)" % (self.name, self.stock_owner) return "%s (%s)" % (self.name, self.effective_quantity)
def get_absolute_url(self):
return reverse('stock:items_list', kwargs={'stock_id':self.stock_owner.id})

View File

@ -1,15 +1,30 @@
{% extends "core/base.jinja" %} {% extends "core/base.jinja" %}
{% block title %} {% block title %}
{% trans s=stock %}{{stock}}{% endtrans %} {{ stock }}
{% endblock %} {% endblock %}
{% block content %} {% block content %}
{% if current_tab == "stocks" %} {% if current_tab == "stocks" %}
<p><a href="{{ url('stock:new_item', stock_id=stock.id)}}?stock={{stock.id}}">{% trans %}New item{% endtrans %}</a></p> <p><a href="{{ url('stock:new_item', stock_id=stock.id)}}">{% trans %}New item{% endtrans %}</a></p>
{% endif %}
{% if stock %}
<h3>{{ stock }}</h3>
{% for t in ProductType.objects.order_by('name') %}
<h4>{{ t }}</h4>
<ul>
{% for i in stock.items.filter(type=t).order_by('name') %}
<li><a href="{{ url('stock:edit_item', item_id=i.id)}}">{{ i }}</a></li>
{% endfor %}
</ul>
{% endfor %}
<h4>{% trans %}Others{% endtrans %}</h4>
<ul>
{% for i in stock.items.filter(type=None).order_by('name') %}
<li><a href="{{ url('stock:edit_item', item_id=i.id)}}">{{ i }}</a></li>
{% endfor %}
</ul>
{% else %}
{% trans %}There is no items in this stock.{% endtrans %}
{% endif %} {% endif %}
<h3>{% trans s=stock %}{{stock}}{% endtrans %}</h3>
{% endblock %} {% endblock %}

View File

@ -11,7 +11,7 @@
{% for s in stock_list.order_by('name') %} {% for s in stock_list.order_by('name') %}
<li> <li>
{% if user.can_edit(s) %} {% if user.can_edit(s) %}
<a href="{{ url('stock:items_list', stock_id=s.id)}}?stock={{s.id}}">{{s}}</a> <a href="{{ url('stock:items_list', stock_id=s.id)}}">{{s}}</a>
- <a href="{{ url('stock:edit', stock_id=s.id) }}">Edit</a> - <a href="{{ url('stock:edit', stock_id=s.id) }}">Edit</a>
{% endif %} {% endif %}
</li> </li>

View File

@ -11,4 +11,6 @@ urlpatterns = [
# StockItem urls # StockItem urls
url(r'^(?P<stock_id>[0-9]+)$', StockItemList.as_view(), name='items_list'), url(r'^(?P<stock_id>[0-9]+)$', StockItemList.as_view(), name='items_list'),
url(r'^(?P<stock_id>[0-9]+)/stockItem/newItem$', StockItemCreateView.as_view(), name='new_item'), url(r'^(?P<stock_id>[0-9]+)/stockItem/newItem$', StockItemCreateView.as_view(), name='new_item'),
url(r'^stockItem/(?P<item_id>[0-9]+)/edit$', StockItemEditView.as_view(), name='edit_item'),
] ]

View File

@ -15,18 +15,18 @@ from stock.models import Stock, StockItem
class StockMain(CounterAdminTabsMixin, CanCreateMixin, DetailView): class StockMain(CounterAdminTabsMixin, CanCreateMixin, DetailView):
""" """
The stock view for the counter owner The stockitems list view for the counter owner
""" """
model = StockItem model = Stock
template_name = 'stock/stock_item_list.jinja' template_name = 'stock/stock_item_list.jinja'
pk_url_kwarg = "stock_id" pk_url_kwarg = "stock_id"
current_tab = "stocks" current_tab = "stocks"
def get_context_data(self, **kwargs): #def get_context_data(self, **kwargs):
context = super(StockItemList, self).get_context_data(**kwargs) # context = super(StockItemList, self).get_context_data(**kwargs)
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
class StockListView(CounterAdminTabsMixin, CanViewMixin, ListView): class StockListView(CounterAdminTabsMixin, CanViewMixin, ListView):
""" """
@ -39,7 +39,7 @@ class StockListView(CounterAdminTabsMixin, CanViewMixin, ListView):
class StockEditForm(forms.ModelForm): class StockEditForm(forms.ModelForm):
""" """
docstring for StockEditForm"forms.ModelForm A form to change stock's characteristics
""" """
class Meta: class Meta:
model = Stock model = Stock
@ -54,7 +54,7 @@ class StockEditForm(forms.ModelForm):
class StockEditView(CounterAdminTabsMixin, CanEditPropMixin, UpdateView): class StockEditView(CounterAdminTabsMixin, CanEditPropMixin, UpdateView):
""" """
A edit view for the stock An edit view for the stock
""" """
model = Stock model = Stock
form_class = StockEditForm form_class = StockEditForm
@ -63,6 +63,17 @@ class StockEditView(CounterAdminTabsMixin, CanEditPropMixin, UpdateView):
current_tab = "stocks" current_tab = "stocks"
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"
class StockCreateView(CounterAdminTabsMixin, CanCreateMixin, CreateView): class StockCreateView(CounterAdminTabsMixin, CanCreateMixin, CreateView):
""" """
A create view for a new Stock A create view for a new Stock
@ -76,8 +87,8 @@ class StockCreateView(CounterAdminTabsMixin, CanCreateMixin, CreateView):
def get_initial(self): def get_initial(self):
ret = super(StockCreateView, self).get_initial() ret = super(StockCreateView, self).get_initial()
if 'counter' in self.request.GET.keys(): if 'counter_id' in self.kwargs.keys():
ret['counter'] = self.request.GET['counter'] ret['counter'] = self.kwargs['counter_id']
return ret return ret
class StockItemCreateView(CounterAdminTabsMixin, CanCreateMixin, CreateView): class StockItemCreateView(CounterAdminTabsMixin, CanCreateMixin, CreateView):
@ -93,9 +104,11 @@ class StockItemCreateView(CounterAdminTabsMixin, CanCreateMixin, CreateView):
def get_initial(self): def get_initial(self):
ret = super(StockItemCreateView, self).get_initial() ret = super(StockItemCreateView, self).get_initial()
if 'stock' in self.request.GET.keys(): if 'stock_id' in self.kwargs.keys():
ret['stock_owner'] = self.request.GET['stock'] ret['stock_owner'] = self.kwargs['stock_id']
return ret return ret
def get_success_url(self): def get_success_url(self):
return reverse_lazy('stock:main', kwargs={'stock_id': self.object.stock_owner.id}) return reverse_lazy('stock:items_list', kwargs={'stock_id':self.object.stock_owner.id}) + '?stock=' + str(self.object.stock_owner.id)