mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add ability for stock API to be filtered by installed status
This commit is contained in:
parent
8dd8e69c05
commit
f253bf1843
@ -19,7 +19,7 @@
|
||||
loadStockTable($("#stock-table"), {
|
||||
params: {
|
||||
location_detail: true,
|
||||
part_details: true,
|
||||
part_detail: true,
|
||||
build: {{ build.id }},
|
||||
},
|
||||
groupByField: 'location',
|
||||
|
@ -476,6 +476,26 @@ class StockList(generics.ListCreateAPIView):
|
||||
if 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
|
||||
customer = params.get('customer', None)
|
||||
|
||||
|
31
InvenTree/stock/templates/stock/item_installed.html
Normal file
31
InvenTree/stock/templates/stock/item_installed.html
Normal 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 %}
|
@ -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>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if item.installedItemCount > 0 %}
|
||||
{% if item.part.assembly or item.installedItemCount > 0 %}
|
||||
<li {% if tab == 'installed' %} class='active'{% endif %}>
|
||||
<a href="#">
|
||||
<a href="{% url 'stock-item-installed' item.id %}">
|
||||
{% trans "Installed Parts" %}
|
||||
<span class='badge'>{{ item.installedItemCount }}</span>
|
||||
{% if item.installedItemCount > 0 %}<span class='badge'>{{ item.installedItemCount }}</span>{% endif %}
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
@ -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'^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'^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('^.*$', views.StockItemDetail.as_view(), name='stock-item-detail'),
|
||||
|
@ -512,16 +512,20 @@ function loadStockTable(table, options) {
|
||||
title: '{% trans "Location" %}',
|
||||
sortable: true,
|
||||
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}/`);
|
||||
}
|
||||
else {
|
||||
if (row.customer) {
|
||||
var text = "{% trans "Shipped to customer" %}";
|
||||
return renderLink(text, `/company/${row.customer}/assigned-stock/`);
|
||||
} else {
|
||||
return '<i>{% trans "No stock location set" %}</i>';
|
||||
}
|
||||
return '<i>{% trans "No stock location set" %}</i>';
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -65,6 +65,11 @@ function getAvailableTableFilters(tableKey) {
|
||||
title: '{% trans "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: {
|
||||
type: 'bool',
|
||||
title: '{% trans "Sent to customer" %}',
|
||||
|
Loading…
Reference in New Issue
Block a user