Commit 5cb75ec3 authored by Lo-J's avatar Lo-J

general modifications

parent 587ad963
......@@ -32,9 +32,9 @@
<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> -
{%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 %}
<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 %}
{% if user.is_owner(c) %}
......
# -*- 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),
),
]
......@@ -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)
{% 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 %}
\ No newline at end of file
......@@ -11,7 +11,7 @@
{% for s in stock_list.order_by('name') %}
<li>
{% 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>
{% endif %}
</li>
......
......@@ -3,9 +3,12 @@ from django.conf.urls import include, url
from stock.views import *
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'^edit/(?P<stock_id>[0-9]+)$', StockEditView.as_view(), name='edit'),
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'),
]
......@@ -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"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment