Reorganized stock location view

This commit is contained in:
Oliver Walters 2021-04-20 19:49:07 +10:00
parent f578f68001
commit 6986709fb8
8 changed files with 184 additions and 55 deletions

View File

@ -320,6 +320,11 @@ class StockLocationList(generics.ListCreateAPIView):
'description',
]
ordering_fields = [
'name',
'items',
]
class StockList(generics.ListCreateAPIView):
""" API endpoint for list view of Stock objects

View File

@ -244,6 +244,7 @@ class LocationSerializer(InvenTreeModelSerializer):
items = serializers.IntegerField(source='item_count', read_only=True)
class Meta:
model = StockLocation
fields = [

View File

@ -2,8 +2,15 @@
{% load static %}
{% load inventree_extras %}
{% load i18n %}
{% block menubar %}
{% include "stock/location_navbar.html" with tab="stock" %}
{% endblock %}
{% block content %}
<div class='panel panel-default panel-inventree'>
{% setting_object 'STOCK_OWNERSHIP_CONTROL' as owner_control %}
{% if owner_control.value == "True" %}
{% authorized_owners location.owner as owners %}
@ -120,36 +127,29 @@
</div>
</h3>
</div>
</div>
{% if location and location.children.all|length > 0 %}
{% include 'stock/location_list.html' with children=location.children.all collapse_id="locations" %}
{% elif locations|length > 0 %}
{% include 'stock/location_list.html' with children=locations collapse_id="locations" %}
{% endif %}
{% block location_content %}
<hr>
{% include "stock_table.html" %}
<div class='panel panel-default panel-inventree'>
<div class='panel-heading'>
<h4>{% trans "Stock Items" %}</h4>
</div>
{% include "stock_table.html" %}
</div>
{% endblock %}
{% block js_load %}
{{ block.super }}
</div>
{% endblock %}
{% block js_ready %}
{{ block.super }}
if (inventreeLoadInt("show-part-locs") == 1) {
$("#collapse-item-locations").collapse('show');
}
$("#collapse-item-locations").on('shown.bs.collapse', function() {
inventreeSave('show-part-locs', 1);
});
$("#collapse-item-locations").on('hidden.bs.collapse', function() {
inventreeDel('show-part-locs');
enableNavbar({
label: 'location',
toggleId: '#location-menu-toggle'
});
{% if location %}
@ -261,7 +261,7 @@
],
params: {
{% if location %}
location: {{ location.id }},
location: {{ location.pk }},
{% endif %}
part_detail: true,
location_detail: true,

View File

@ -1,24 +0,0 @@
{% extends "collapse.html" %}
{% load i18n %}
{% if roles.stock_location.view or roles.stock.view %}
{% block collapse_title %}
{% trans 'Sub-Locations' %}<span class='badge'>{{ children|length }}</span>
{% endblock %}
{% block collapse_content %}
<ul class="list-group">
{% for child in children %}
<li class="list-group-item"><a href="{% url 'stock-location-detail' child.id %}">{{ child.name }}</a> - <i>{{ child.description }}</i>
{% if child.item_count > 0 %}
<!-- span class='badge'>{{ child.item_count }} Item{% if child.item_count > 1 %}s{% endif %}</span> -->
<span class='badge'>
{% comment %}Translators: pluralize with counter{% endcomment %}
{% blocktrans count counter=child.item_count %}{{ counter }} Item{% plural %}{{ counter }} Items{% endblocktrans %}
</span>
{% endif %}
</li>
{% endfor %}
</ul>
{% endblock %}
{% endif %}

View File

@ -0,0 +1,33 @@
{% load i18n %}
<ul class='list-group'>
<li class='list-group-item'>
<a href='#' id='location-menu-toggle'>
<span class='menu-tab-icon fas fa-expand-arrows-alt'></span>
</a>
</li>
<li class='list-group-item {% if tab == "sublocations" %}active{% endif %}' title='{% trans "Sublocations" %}'>
{% if location %}
<a href='{% url "stock-location-sublocation" location.id %}'>
{% else %}
<a href='{% url "stock-sublocations" %}'>
{% endif %}
<span class='fas fa-sitemap'></span>
{% trans "Sublocations" %}
</a>
</li>
<li class='list-group-item {% if tab == "stock" %}active{% endif %}' title='{% trans "Stock Items" %}'>
{% if location %}
<a href='{% url "stock-location-detail" location.id %}'>
{% else %}
<a href='{% url "stock-index" %}'>
{% endif %}
<span class='fas fa-boxes'></span>
{% trans "Stock Items" %}
</a>
</li>
</ul>

View File

@ -0,0 +1,36 @@
{% extends "stock/location.html" %}
{% load static %}
{% load i18n %}
{% load inventree_extras %}
{% block menubar %}
{% include "stock/location_navbar.html" with tab="sublocations" %}
{% endblock %}
{% block location_content %}
<div class='panel panel-default panel-inventree'>
<div class='panel-heading'>
<h4>{% trans "Sublocations" %}</h4>
</div>
<table class='table table-striped table-condensed' id='sublocation-table'></table>
</div>
{% endblock %}
{% block js_ready %}
{{ block.super }}
loadStockLocationTable($('#sublocation-table'), {
params: {
{% if location %}
parent: {{ location.pk }},
{% else %}
parent: 'null',
{% endif %}
}
});
{% endblock %}

View File

@ -6,14 +6,21 @@ from django.conf.urls import url, include
from . import views
# URL list for web interface
stock_location_detail_urls = [
url(r'^edit/?', views.StockLocationEdit.as_view(), name='stock-location-edit'),
url(r'^delete/?', views.StockLocationDelete.as_view(), name='stock-location-delete'),
url(r'^qr_code/?', views.StockLocationQRCode.as_view(), name='stock-location-qr'),
location_urls = [
url(r'^new/', views.StockLocationCreate.as_view(), name='stock-location-create'),
url(r'^(?P<pk>\d+)/', include([
url(r'^edit/?', views.StockLocationEdit.as_view(), name='stock-location-edit'),
url(r'^delete/?', views.StockLocationDelete.as_view(), name='stock-location-delete'),
url(r'^qr_code/?', views.StockLocationQRCode.as_view(), name='stock-location-qr'),
url(r'sublocation/', views.StockLocationDetail.as_view(template_name='stock/sublocation.html'), name='stock-location-sublocation'),
# Anything else
url('^.*$', views.StockLocationDetail.as_view(), name='stock-location-detail'),
])),
# Anything else
url('^.*$', views.StockLocationDetail.as_view(), name='stock-location-detail'),
]
stock_item_detail_urls = [
@ -49,9 +56,7 @@ stock_tracking_urls = [
stock_urls = [
# Stock location
url(r'^location/(?P<pk>\d+)/', include(stock_location_detail_urls)),
url(r'^location/new/', views.StockLocationCreate.as_view(), name='stock-location-create'),
url(r'^location/', include(location_urls)),
url(r'^item/new/?', views.StockItemCreate.as_view(), name='stock-item-create'),
@ -81,5 +86,7 @@ stock_urls = [
# Individual stock items
url(r'^item/(?P<pk>\d+)/', include(stock_item_detail_urls)),
url(r'^sublocations/', views.StockIndex.as_view(template_name='stock/sublocation.html'), name='stock-sublocations'),
url(r'^.*$', views.StockIndex.as_view(), name='stock-index'),
]

View File

@ -897,6 +897,77 @@ function loadStockTable(table, options) {
});
}
function loadStockLocationTable(table, options) {
/* Display a table of stock locations */
var params = options.params || {};
var filterListElement = options.filterList || '#filter-list-location';
var filters = {};
var filterKey = options.filterKey || options.name || 'location';
if (!options.disableFilters) {
filters = loadTableFilters(filterKey);
}
var original = {};
for (var key in params) {
original[key] = params[key];
}
setupFilterList(filterKey, table, filterListElement);
for (var key in params) {
filters[key] = params[key];
}
table.inventreeTable({
method: 'get',
url: options.url || '{% url "api-location-list" %}',
queryParams: filters,
sidePagination: 'server',
name: 'location',
original: original,
showColumns: true,
columns: [
{
checkbox: true,
title: '{% trans "Select" %}',
searchable: false,
switchable: false,
},
{
field: 'name',
title: '{% trans "Name" %}',
switchable: true,
sortable: true,
formatter: function(value, row) {
return renderLink(
value,
`/stock/location/${row.pk}/`
);
},
},
{
field: 'description',
title: '{% trans "Description" %}',
switchable: true,
sortable: false,
},
{
field: 'items',
title: '{% trans "Stock Items" %}',
switchable: true,
sortable: false,
sortName: 'item_count',
}
]
});
}
function loadStockTrackingTable(table, options) {
var cols = [