2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-05-03 05:48:47 +00:00

Add ability for stock API to be filtered by installed status

This commit is contained in:
Oliver Walters 2020-09-28 20:07:25 +10:00
parent 8dd8e69c05
commit f253bf1843
7 changed files with 72 additions and 11 deletions

View File

@ -19,7 +19,7 @@
loadStockTable($("#stock-table"), { loadStockTable($("#stock-table"), {
params: { params: {
location_detail: true, location_detail: true,
part_details: true, part_detail: true,
build: {{ build.id }}, build: {{ build.id }},
}, },
groupByField: 'location', groupByField: 'location',

View File

@ -476,6 +476,26 @@ class StockList(generics.ListCreateAPIView):
if sales_order: if sales_order:
queryset = queryset.filter(sales_order=sales_order) queryset = queryset.filter(sales_order=sales_order)
# Filter stock items which are installed in another (specific) stock item
installed_in = params.get('installed_in', None)
if installed_in:
# Note: The "installed_in" field is called "belongs_to"
queryset = queryset.filter(belongs_to=installed_in)
# Filter stock items which are installed in another stock item
installed = params.get('installed', None)
if installed is not None:
installed = str2bool(installed)
if installed:
# Exclude items which are *not* installed in another item
queryset = queryset.exclude(belongs_to=None)
else:
# Exclude items which are instaled in another item
queryset = queryset.filter(belongs_to=None)
# Filter by customer # Filter by customer
customer = params.get('customer', None) customer = params.get('customer', None)

View File

@ -0,0 +1,31 @@
{% extends "stock/item_base.html" %}
{% load static %}
{% load i18n %}
{% block details %}
{% include "stock/tabs.html" with tab='installed' %}
<h4>{% trans "Installed Items" %}</h4>
<hr>
<table class='table table-striped table-condensed' id='installed-table'>
</table>
{% endblock %}
{% block js_ready %}
{{ block.super }}
loadStockTable($("#installed-table"), {
params: {
installed_in: {{ item.id }},
part_detail: true,
},
name: 'stock-item-installed',
url: "{% url 'api-stock-list' %}",
})
{% endblock %}

View File

@ -38,11 +38,11 @@
<a href="{% url 'stock-item-children' item.id %}">{% trans "Children" %}{% if item.child_count > 0 %}<span class='badge'>{{ item.child_count }}</span>{% endif %}</a> <a href="{% url 'stock-item-children' item.id %}">{% trans "Children" %}{% if item.child_count > 0 %}<span class='badge'>{{ item.child_count }}</span>{% endif %}</a>
</li> </li>
{% endif %} {% endif %}
{% if item.installedItemCount > 0 %} {% if item.part.assembly or item.installedItemCount > 0 %}
<li {% if tab == 'installed' %} class='active'{% endif %}> <li {% if tab == 'installed' %} class='active'{% endif %}>
<a href="#"> <a href="{% url 'stock-item-installed' item.id %}">
{% trans "Installed Parts" %} {% trans "Installed Parts" %}
<span class='badge'>{{ item.installedItemCount }}</span> {% if item.installedItemCount > 0 %}<span class='badge'>{{ item.installedItemCount }}</span>{% endif %}
</a> </a>
</li> </li>
{% endif %} {% endif %}

View File

@ -34,6 +34,7 @@ stock_item_detail_urls = [
url(r'^test/', views.StockItemDetail.as_view(template_name='stock/item_tests.html'), name='stock-item-test-results'), url(r'^test/', views.StockItemDetail.as_view(template_name='stock/item_tests.html'), name='stock-item-test-results'),
url(r'^children/', views.StockItemDetail.as_view(template_name='stock/item_childs.html'), name='stock-item-children'), url(r'^children/', views.StockItemDetail.as_view(template_name='stock/item_childs.html'), name='stock-item-children'),
url(r'^attachments/', views.StockItemDetail.as_view(template_name='stock/item_attachments.html'), name='stock-item-attachments'), url(r'^attachments/', views.StockItemDetail.as_view(template_name='stock/item_attachments.html'), name='stock-item-attachments'),
url(r'^installed/', views.StockItemDetail.as_view(template_name='stock/item_installed.html'), name='stock-item-installed'),
url(r'^notes/', views.StockItemNotes.as_view(), name='stock-item-notes'), url(r'^notes/', views.StockItemNotes.as_view(), name='stock-item-notes'),
url('^.*$', views.StockItemDetail.as_view(), name='stock-item-detail'), url('^.*$', views.StockItemDetail.as_view(), name='stock-item-detail'),

View File

@ -512,16 +512,20 @@ function loadStockTable(table, options) {
title: '{% trans "Location" %}', title: '{% trans "Location" %}',
sortable: true, sortable: true,
formatter: function(value, row, index, field) { formatter: function(value, row, index, field) {
if (value) { if (row.belongs_to) {
var text = "{% trans 'Installed in Stock Item ' %}" + row.belongs_to;
var url = `/stock/item/${row.belongs_to}/installed/`;
return renderLink(text, url);
} else if (row.customer) {
var text = "{% trans "Shipped to customer" %}";
return renderLink(text, `/company/${row.customer}/assigned-stock/`);
}
else if (value) {
return renderLink(value, `/stock/location/${row.location}/`); return renderLink(value, `/stock/location/${row.location}/`);
} }
else { else {
if (row.customer) { return '<i>{% trans "No stock location set" %}</i>';
var text = "{% trans "Shipped to customer" %}";
return renderLink(text, `/company/${row.customer}/assigned-stock/`);
} else {
return '<i>{% trans "No stock location set" %}</i>';
}
} }
} }
}, },

View File

@ -65,6 +65,11 @@ function getAvailableTableFilters(tableKey) {
title: '{% trans "In Stock" %}', title: '{% trans "In Stock" %}',
description: '{% trans "Show items which are in stock" %}', description: '{% trans "Show items which are in stock" %}',
}, },
installed: {
type: 'bool',
title: '{% trans "Installed" %}',
description: '{% trans "Show stock items which are installed in another item" %}',
},
sent_to_customer: { sent_to_customer: {
type: 'bool', type: 'bool',
title: '{% trans "Sent to customer" %}', title: '{% trans "Sent to customer" %}',