2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 04:25:42 +00:00

Implemented bidirectional traversal for PART and STOCK apps

- Added list view for StockItems
This commit is contained in:
Oliver
2018-04-14 15:13:16 +10:00
parent e30a089c76
commit 89ee09b01f
15 changed files with 157 additions and 38 deletions

View File

@ -0,0 +1,38 @@
{% extends "base.html" %}
{% block content %}
{% include "stock/loc_link.html" with location=location %}
{% if children|length > 0 %}
<table>
<tr><th>Sublocations</th></tr>
{% for child in children %}
<tr>
<td><a href="/stock/list/?location={{ child.id }}">{{ child.name }}</a></td>
</tr>
{% endfor %}
</table>
{% endif %}
{% if items|length > 0 %}
<table>
<tr>
<th>Part</th>
<th>Stock</th>
<th>Stocktake</th>
<th>Notes</th>
</tr>
{% for item in items %}
<tr>
<td><a href="{% url 'part-detail' item.part.id %}">{{ item.part.name }}</a></td>
<td>{{ item.quantity }}</td>
<td>{{ item.stocktake_date }}</td>
<td>{{ item.notes }}</td>
</tr>
{% endfor %}
</table>
{% else %}
There are no parts in this location.
{% endif %}
{% endblock %}

View File

@ -0,0 +1,9 @@
<div class="container">
<a href="/stock/list/">Stock</a> >
{% if location %}
{% for path_item in location.parentpath %}
<a href="/stock/list/?location={{ path_item.id }}">{{ path_item.name }}</a> >
{% endfor %}
<a href="/stock/list/?location={{ location.id }}">{{ location.name }}</a>
{% endif %}
</div>

View File

@ -1,4 +1,5 @@
from django.conf.urls import url, include
from django.views.generic.base import RedirectView
from . import views
from . import api
@ -11,7 +12,7 @@ stock_endpoints = [
url(r'^add-stock/?$', api.AddStockEndpoint.as_view(), name='stockitem-add-stock'),
]
stock_urls = [
stock_api_urls = [
# Detail for a single stock item
url(r'^(?P<pk>[0-9]+)/', include(stock_endpoints)),
@ -20,10 +21,25 @@ stock_urls = [
url(r'^$', api.StockList.as_view()),
]
stock_loc_urls = [
stock_api_loc_urls = [
url(r'^(?P<pk>[0-9]+)/?$', api.LocationDetail.as_view(), name='stocklocation-detail'),
url(r'^\?.*/?$', api.LocationList.as_view()),
url(r'^$', api.LocationList.as_view())
]
# URL list for web interface
stock_detail_urls = [
url('', views.detail, name='stock-detail'),
]
stock_urls = [
# Individual stock items
url(r'^(?P<pk>\d+)/', include(stock_detail_urls)),
url('list', views.index, name='stock=index'),
# Redirect any other patterns
url(r'^.*$', RedirectView.as_view(url='list', permanent=False), name='stock-index'),
]

View File

@ -0,0 +1,43 @@
from django.http import HttpResponse
from django.template import loader
from django.shortcuts import get_object_or_404, render
from .models import StockItem, StockLocation
def index(request):
template = loader.get_template('stock/index.html')
items = StockItem.objects.all()
location = None
if 'location' in request.GET:
loc_id = request.GET['location']
location = get_object_or_404(StockLocation, pk=loc_id)
items = items.filter(location = loc_id)
children = StockLocation.objects.filter(parent = loc_id)
else:
# No stock items can exist without a location
items = None
location = None
children = StockLocation.objects.filter(parent__isnull=True)
context = {
'items' : items,
'location' : location,
'children' : children,
}
return HttpResponse(template.render(context, request))
def detail(request, pk):
item = get_object_or_404(Stock, pk=pk)
return render(request, 'stock/detail.html', {'item' : item})