Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Sith
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
59
Issues
59
List
Boards
Labels
Service Desk
Milestones
Merge Requests
9
Merge Requests
9
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
AE
Sith
Commits
6c54b246
Commit
6c54b246
authored
Nov 16, 2016
by
Lo-J
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stock admin gestion, items list views, create and edit items
parent
5cb75ec3
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
95 additions
and
2890 deletions
+95
-2890
counter/templates/counter/counter_list.jinja
counter/templates/counter/counter_list.jinja
+2
-2
locale/fr/LC_MESSAGES/django.po
locale/fr/LC_MESSAGES/django.po
+0
-2862
stock/migrations/0003_auto_20161116_1338.py
stock/migrations/0003_auto_20161116_1338.py
+35
-0
stock/models.py
stock/models.py
+7
-5
stock/templates/stock/stock_item_list.jinja
stock/templates/stock/stock_item_list.jinja
+21
-6
stock/templates/stock/stock_list.jinja
stock/templates/stock/stock_list.jinja
+1
-1
stock/urls.py
stock/urls.py
+2
-0
stock/views.py
stock/views.py
+27
-14
No files found.
counter/templates/counter/counter_list.jinja
View file @
6c54b246
...
...
@@ -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: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
%}
<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
%}
{%
if
user.is_owner
(
c
)
%}
...
...
locale/fr/LC_MESSAGES/django.po
deleted
100644 → 0
View file @
5cb75ec3
This diff is collapsed.
Click to expand it.
stock/migrations/0003_auto_20161116_1338.py
0 → 100644
View file @
6c54b246
# -*- 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'
),
),
]
stock/models.py
View file @
6c54b246
...
...
@@ -22,13 +22,15 @@ class StockItem(models.Model):
The StockItem class, element of the stock
"""
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)
'
)
effective_quantity
=
models
.
IntegerField
(
_
(
'effective quantity'
),
default
=
0
,
help_text
=
'
total number of bottle/barrel
'
)
type
=
models
.
ForeignKey
(
ProductType
,
related_name
=
"stock
Item_type
"
,
verbose_name
=
_
(
"type"
),
null
=
True
,
blank
=
True
,
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
=
'
number of box
'
)
type
=
models
.
ForeignKey
(
ProductType
,
related_name
=
"stock
_items
"
,
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
=
"
items
"
)
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
})
\ No newline at end of file
stock/templates/stock/stock_item_list.jinja
View file @
6c54b246
{%
extends
"core/base.jinja"
%}
{%
block
title
%}
{
%
trans
s
=
stock
%}{{
stock
}}{%
endtrans
%
}
{
{
stock
}
}
{%
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>
<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
%}
<h3>
{%
trans
s
=
stock
%}{{
stock
}}{%
endtrans
%}
</h3>
{%
endblock
%}
\ No newline at end of file
stock/templates/stock/stock_list.jinja
View file @
6c54b246
...
...
@@ -11,7 +11,7 @@
{%
for
s
in
stock_list.order_by
(
'name'
)
%}
<li>
{%
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>
{%
endif
%}
</li>
...
...
stock/urls.py
View file @
6c54b246
...
...
@@ -11,4 +11,6 @@ urlpatterns = [
# 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'
),
url
(
r
'^stockItem/(?P<item_id>[0-9]+)/edit$'
,
StockItemEditView
.
as_view
(),
name
=
'edit_item'
),
]
stock/views.py
View file @
6c54b246
...
...
@@ -15,18 +15,18 @@ from stock.models import Stock, StockItem
class
StockMain
(
CounterAdminTabsMixin
,
CanCreateMixin
,
DetailView
):
"""
The stock view for the counter owner
The stock
items list
view for the counter owner
"""
model
=
Stock
Item
model
=
Stock
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
#
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
):
"""
...
...
@@ -39,7 +39,7 @@ class StockListView(CounterAdminTabsMixin, CanViewMixin, ListView):
class
StockEditForm
(
forms
.
ModelForm
):
"""
docstring for StockEditForm"forms.ModelForm
A form to change stock's characteristics
"""
class
Meta
:
model
=
Stock
...
...
@@ -54,7 +54,7 @@ class StockEditForm(forms.ModelForm):
class
StockEditView
(
CounterAdminTabsMixin
,
CanEditPropMixin
,
UpdateView
):
"""
A edit view for the stock
A
n
edit view for the stock
"""
model
=
Stock
form_class
=
StockEditForm
...
...
@@ -63,6 +63,17 @@ class StockEditView(CounterAdminTabsMixin, CanEditPropMixin, UpdateView):
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
):
"""
A create view for a new Stock
...
...
@@ -76,8 +87,8 @@ class StockCreateView(CounterAdminTabsMixin, CanCreateMixin, CreateView):
def
get_initial
(
self
):
ret
=
super
(
StockCreateView
,
self
).
get_initial
()
if
'counter
'
in
self
.
request
.
GET
.
keys
():
ret
[
'counter'
]
=
self
.
request
.
GET
[
'counter
'
]
if
'counter
_id'
in
self
.
kwargs
.
keys
():
ret
[
'counter'
]
=
self
.
kwargs
[
'counter_id
'
]
return
ret
class
StockItemCreateView
(
CounterAdminTabsMixin
,
CanCreateMixin
,
CreateView
):
...
...
@@ -93,9 +104,11 @@ class StockItemCreateView(CounterAdminTabsMixin, CanCreateMixin, CreateView):
def
get_initial
(
self
):
ret
=
super
(
StockItemCreateView
,
self
).
get_initial
()
if
'stock
'
in
self
.
request
.
GET
.
keys
():
ret
[
'stock_owner'
]
=
self
.
request
.
GET
[
'stock
'
]
if
'stock
_id'
in
self
.
kwargs
.
keys
():
ret
[
'stock_owner'
]
=
self
.
kwargs
[
'stock_id
'
]
return
ret
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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment