2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-15 11:35:41 +00:00

Added edit views for stock

- StockItem
- StockLocation
This commit is contained in:
Oliver
2018-04-15 23:27:56 +10:00
parent 3c844fc77f
commit 55b533d3ef
18 changed files with 168 additions and 22 deletions

View File

@ -20,6 +20,9 @@ class StockLocation(InvenTreeTree):
Stock locations can be heirarchical as required
"""
def get_absolute_url(self):
return '/stock/location/{id}/'.format(id=self.id)
@property
def items(self):
stock_list = self.stockitem_set.all()
@ -34,7 +37,16 @@ def before_delete_stock_location(sender, instance, using, **kwargs):
item.location = instance.parent
item.save()
# Update each child category
for child in instance.children.all():
child.parent = instance.parent
child.save()
class StockItem(models.Model):
def get_absolute_url(self):
return '/stock/item/{id}/'.format(id=self.id)
part = models.ForeignKey(Part, on_delete=models.CASCADE, related_name='locations')
supplier_part = models.ForeignKey(SupplierPart, blank=True, null=True, on_delete=models.SET_NULL)

View File

@ -4,10 +4,12 @@
{% include "stock/loc_link.html" with location=item.location %}
<h3>Stock entry details</h3>
<table class="table table-striped">
<tr>
<td>Part</td>
<td><a href="{% url 'part-detail' item.part.id %}">{{ item.part.name }}</td>
<td><a href="{% url 'part-stock' item.part.id %}">{{ item.part.name }}</td>
</tr>
<tr>
<td>Location</td>
@ -45,4 +47,13 @@
{% endif %}
</table>
<div class='container-fluid'>
<a href="{% url 'stock-item-edit' item.id %}">
<button class='btn btn-info'>Edit Stock Item</button>
</a>
<a href="{% url 'stock-item-delete' item.id %}">
<button class='btn btn-danger'>Delete Stock Item</button>
</a>
</div>
{% endblock %}

View File

@ -0,0 +1,5 @@
{% extends "create_edit_obj.html" %}
{% block obj_title %}
Create a new stock item
{% endblock %}

View File

@ -0,0 +1,9 @@
{% extends "delete_obj.html" %}
{% block del_title %}
Are you sure you want to delete this stock item?
{% endblock %}
{% block del_body %}
This will remove <b>{{ item.quantity }}</b> units of <b>'{{ item.part.name }}'</b> from stock.
{% endblock %}

View File

@ -0,0 +1,5 @@
{% extends "create_edit_obj.html" %}
{% block obj_title %}
Edit stock item for part '{{ item.part.name }}'
{% endblock %}

View File

@ -14,4 +14,22 @@
{% include "stock/stock_table.html" with items=location.items %}
<div class='container-fluid'>
<a href="{% url 'stock-location-create' %}?location={{ location.id }}">
<button class='btn btn-success'>New Stock Location</button>
</a>
<a href="{% url 'stock-item-create' %}?location={{ location.id }}">
<button class='btn btn-success'>New Stock Item</button>
</a>
<a href="{% url 'stock-location-edit' location.id %}">
<button class="btn btn-info">Edit Location</button>
</a>
<a href="{% url 'stock-location-delete' location.id %}">
<button class="btn btn-danger">Delete Location</button>
</a>
</div>
{% endblock %}

View File

@ -0,0 +1,5 @@
{% extends "create_edit_obj.html" %}
{% block obj_title %}
Create a new stock location
{% endblock %}

View File

@ -0,0 +1,41 @@
{% extends 'delete_obj.html' %}
{% block del_title %}
Are you sure you want to delete stock location '{{ location.name }}'?
{% endblock %}
{% block del_body %}
{% if location.children.all|length > 0 %}
<p>This location contains {{ location.children.all|length }} child locations.<br>
If this location is deleted, these child locations will be moved to
{% if location.parent %}
the '{{ location.parent.name }}' location.
{% else %}
the top level 'Stock' category.
{% endif %}
</p>
<ul class='list-group'>
{% for loc in location.children.all %}
<li class='list-group-item'><b>{{ loc.name }}</b> - <i>{{ loc.description}}</i></li>
{% endfor %}
</ul>
{% endif %}
{% if location.items.all|length > 0 %}
<p>This location contains {{ location.items.all|length }} stock items.<br>
{% if location.parent %}
If this location is deleted, these items will be moved to the '{{ location.parent.name }}' location.
{% else %}
If this location is deleted, these items will be deleted!
{% endif %}
</p>
<ul class='list-group'>
{% for item in location.items.all %}
<li class='list-group-item'><b>{{ item.part.name }}</b> - <i>{{ item.part.description }}</i><span class='badge'>{{ item.quantity }}</span></li>
{% endfor %}
</ul>
{% endif %}
{% endblock %}

View File

@ -0,0 +1,5 @@
{% extends "create_edit_obj.html" %}
{% block obj_title %}
Edit stock location '{{ location.name }}'
{% endblock %}

View File

@ -8,7 +8,7 @@
</tr>
{% for item in items.all %}
<tr>
<td><a href="{% url 'part-detail' item.part.id %}">{{ item.part.name }}</a></td>
<td><a href="{% url 'part-stock' item.part.id %}">{{ item.part.name }}</a></td>
<td>{{ item.quantity }}</td>
<td>{{ item.status }}</td>
<td>{{ item.stocktake_date }}</td>

View File

@ -52,10 +52,10 @@ stock_urls = [
url(r'^location/new/', views.StockLocationCreate.as_view(), name='stock-location-create'),
url(r'^item/new/?', views.StockItemCreate.as_view(), name='stock-item-create'),
# Individual stock items
url(r'^item/(?P<pk>\d+)/', include(stock_item_detail_urls)),
url(r'^item/new/', views.StockItemCreate.as_view(), name='stock-item-create'),
url(r'^.*$', views.StockIndex.as_view(), name='stock-index'),
]

View File

@ -5,7 +5,7 @@ from django.urls import reverse
from django.views.generic import DetailView, ListView
from django.views.generic.edit import UpdateView, DeleteView, CreateView
from part.models import Part
from .models import StockItem, StockLocation
from .forms import EditStockLocationForm
@ -46,35 +46,60 @@ class StockItemDetail(DetailView):
class StockLocationEdit(UpdateView):
model = StockLocation
form_class = EditStockLocationForm
template_name = '/stock/location-edit.html'
template_name = 'stock/location_edit.html'
context_object_name = 'location'
class StockItemEdit(UpdateView):
model = StockItem
form_class = EditStockItemForm
template_name = '/stock/item-edit.html'
template_name = 'stock/item_edit.html'
context_object_name = 'item'
class StockLocationCreate(CreateView):
model = StockLocation
form_class = EditStockLocationForm
template_name = '/stock/location-create.html'
template_name = 'stock/location_create.html'
context_object_name = 'location'
def get_initial(self):
initials = super(StockLocationCreate, self).get_initial().copy()
loc_id = self.request.GET.get('location', None)
if loc_id:
initials['parent'] = get_object_or_404(StockLocation, pk=loc_id)
return initials
class StockItemCreate(CreateView):
model = StockItem
form_class = EditStockItemForm
template_name = '/stock/item-create.html'
template_name = 'stock/item_create.html'
context_object_name = 'item'
def get_initial(self):
initials = super(StockItemCreate, self).get_initial().copy()
part_id = self.request.GET.get('part', None)
loc_id = self.request.GET.get('location', None)
if part_id:
initials['part'] = get_object_or_404(Part, pk=part_id)
if loc_id:
initials['location'] = get_object_or_404(StockLocation, pk=loc_id)
return initials
class StockLocationDelete(DeleteView):
model = StockLocation
success_url = '/stock/'
template_name = '/stock/location-delete.html'
success_url = '/stock'
template_name = 'stock/location_delete.html'
context_object_name = 'location'
def post(self, request, *args, **kwargs):
if 'confirm' in request.POST:
@ -84,9 +109,10 @@ class StockLocationDelete(DeleteView):
class StockItemDelete(DeleteView):
model = StockLocation
model = StockItem
success_url = '/stock/'
template_name = '/stock/item-delete.html'
template_name = 'stock/item_delete.html'
context_object_name = 'item'
def post(self, request, *args, **kwargs):
if 'confirm' in request.POST: