general modifications

This commit is contained in:
guillaume-renaud 2016-11-14 00:38:33 +01:00
parent 587ad96326
commit 5cb75ec3eb
7 changed files with 82 additions and 17 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:main', stock_id=c.stock.id) }}">Stock</a> - <a href="{{ url('stock:items_list', stock_id=c.stock.id)}}?stock={{c.stock.id}}">Stock</a> -
{% else %} {% else %}
<a href="{{ url('stock:new', counter_id=c.id) }}">{% trans %}Create new stock{% endtrans%}</a> - <a href="{{url('stock:new', counter_id=c.id)}}?counter={{c.id}}">{% trans %}Create new stock{% endtrans%}</a> -
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if user.is_owner(c) %} {% if user.is_owner(c) %}

View File

@ -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),
),
]

View File

@ -2,11 +2,12 @@ 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 counter.models import Counter, ProductType
from counter.models import Counter
class Stock(models.Model): 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) name = models.CharField(_('name'), max_length=64)
counter = models.OneToOneField(Counter, verbose_name=_('counter'), related_name='stock') counter = models.OneToOneField(Counter, verbose_name=_('counter'), related_name='stock')
@ -17,12 +18,17 @@ class Stock(models.Model):
return reverse('stock:list') return reverse('stock:list')
class StockItem(models.Model): 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) 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) 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") stock_owner = models.ForeignKey(Stock, related_name="stock_owner")
def __str__(self): def __str__(self):
return "%s (%s)" % (self.name, self.stock_owner) return "%s (%s)" % (self.name, self.stock_owner)

View File

@ -0,0 +1,15 @@
{% extends "core/base.jinja" %}
{% block title %}
{% trans s=stock %}{{stock}}{% endtrans %}
{% endblock %}
{% block content %}
{% if current_tab == "stocks" %}
<p><a href="{{ url('stock:new_item', stock_id=stock.id)}}?stock={{stock.id}}">{% trans %}New item{% endtrans %}</a></p>
{% endif %}
<h3>{% trans s=stock %}{{stock}}{% endtrans %}</h3>
{% 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:main', stock_id=s.id) }}">{{s}}</a> <a href="{{ url('stock:items_list', stock_id=s.id)}}?stock={{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

@ -3,9 +3,12 @@ from django.conf.urls import include, url
from stock.views import * from stock.views import *
urlpatterns = [ urlpatterns = [
url(r'^(?P<stock_id>[0-9]+)$', StockMain.as_view(), name='main'), #Stock urls
url(r'^new/counter/(?P<counter_id>[0-9]+)$', StockCreateView.as_view(), name='new'), url(r'^new/counter/(?P<counter_id>[0-9]+)$', StockCreateView.as_view(), name='new'),
url(r'^edit/(?P<stock_id>[0-9]+)$', StockEditView.as_view(), name='edit'), url(r'^edit/(?P<stock_id>[0-9]+)$', StockEditView.as_view(), name='edit'),
url(r'^list$', StockListView.as_view(), name='list'), url(r'^list$', StockListView.as_view(), name='list'),
url(r'^(?P<stock_id>[0-9]+)/newItem$', StockItemCreateView.as_view(), name='new_item'),
# StockItem urls
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'),
] ]

View File

@ -6,8 +6,6 @@ from django import forms
from django.forms.models import modelform_factory from django.forms.models import modelform_factory
from django.core.urlresolvers import reverse_lazy, reverse from django.core.urlresolvers import reverse_lazy, reverse
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin, TabedViewMixin from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin, TabedViewMixin
from counter.views import CounterAdminTabsMixin from counter.views import CounterAdminTabsMixin
from counter.models import Counter from counter.models import Counter
@ -19,11 +17,17 @@ class StockMain(CounterAdminTabsMixin, CanCreateMixin, DetailView):
""" """
The stock view for the counter owner The stock view for the counter owner
""" """
model = Stock model = StockItem
template_name = 'stock/stock_main.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):
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): class StockListView(CounterAdminTabsMixin, CanViewMixin, ListView):
""" """
A list view for the admins A list view for the admins
@ -70,13 +74,19 @@ class StockCreateView(CounterAdminTabsMixin, CanCreateMixin, CreateView):
current_tab = "stocks" current_tab = "stocks"
success_url = reverse_lazy('stock:list') 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): class StockItemCreateView(CounterAdminTabsMixin, CanCreateMixin, CreateView):
""" """
A create view for a new StockItem A create view for a new StockItem
""" """
model = 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' template_name = 'core/create.jinja'
pk_url_kwarg = "stock_id" pk_url_kwarg = "stock_id"
current_tab = "stocks" current_tab = "stocks"