mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-07 15:58:49 +00:00
Detail in StockItem API now optional
This commit is contained in:
parent
9052ccc181
commit
5664fc5472
@ -17,6 +17,8 @@
|
|||||||
url: "{% url 'api-stock-list' %}",
|
url: "{% url 'api-stock-list' %}",
|
||||||
params: {
|
params: {
|
||||||
supplier: {{ company.id }},
|
supplier: {{ company.id }},
|
||||||
|
part_detail: true,
|
||||||
|
location_detail: true,
|
||||||
},
|
},
|
||||||
buttons: [
|
buttons: [
|
||||||
'#stock-options',
|
'#stock-options',
|
||||||
|
@ -37,6 +37,8 @@
|
|||||||
loadStockTable($("#stock-table"), {
|
loadStockTable($("#stock-table"), {
|
||||||
params: {
|
params: {
|
||||||
part: {{ part.id }},
|
part: {{ part.id }},
|
||||||
|
location_detail: true,
|
||||||
|
part_detail: true,
|
||||||
},
|
},
|
||||||
buttons: [
|
buttons: [
|
||||||
'#stock-options',
|
'#stock-options',
|
||||||
|
@ -392,25 +392,25 @@ function loadStockTable(table, options) {
|
|||||||
visible: false,
|
visible: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'part.full_name',
|
field: 'part_detail',
|
||||||
title: 'Part',
|
title: 'Part',
|
||||||
sortable: true,
|
sortable: true,
|
||||||
formatter: function(value, row, index, field) {
|
formatter: function(value, row, index, field) {
|
||||||
return imageHoverIcon(row.part.image_url) + renderLink(value, row.part.url + 'stock/');
|
return imageHoverIcon(value.image_url) + renderLink(value.full_name, value.url + 'stock/');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'part.description',
|
field: 'part_detail.description',
|
||||||
title: 'Description',
|
title: 'Description',
|
||||||
sortable: true,
|
sortable: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'location',
|
field: 'location_detail',
|
||||||
title: 'Location',
|
title: 'Location',
|
||||||
sortable: true,
|
sortable: true,
|
||||||
formatter: function(value, row, index, field) {
|
formatter: function(value, row, index, field) {
|
||||||
if (row.location) {
|
if (value) {
|
||||||
return renderLink(row.location.pathstring, row.location.url);
|
return renderLink(value.pathstring, value.url);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return '<i>No stock location set</i>';
|
return '<i>No stock location set</i>';
|
||||||
|
@ -18,6 +18,7 @@ from .serializers import LocationSerializer
|
|||||||
from .serializers import StockTrackingSerializer
|
from .serializers import StockTrackingSerializer
|
||||||
|
|
||||||
from InvenTree.views import TreeSerializer
|
from InvenTree.views import TreeSerializer
|
||||||
|
from InvenTree.helpers import str2bool
|
||||||
|
|
||||||
from rest_framework.serializers import ValidationError
|
from rest_framework.serializers import ValidationError
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
@ -245,6 +246,17 @@ class StockList(generics.ListCreateAPIView):
|
|||||||
- supplier: Filter by supplier
|
- supplier: Filter by supplier
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def get_serializer(self, *args, **kwargs):
|
||||||
|
|
||||||
|
part_detail = str2bool(self.request.GET.get('part_detail', None))
|
||||||
|
location_detail = str2bool(self.request.GET.get('location_detail', None))
|
||||||
|
|
||||||
|
kwargs['part_detail'] = part_detail
|
||||||
|
kwargs['location_detail'] = location_detail
|
||||||
|
|
||||||
|
kwargs['context'] = self.get_serializer_context()
|
||||||
|
return self.serializer_class(*args, **kwargs)
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
"""
|
"""
|
||||||
If the query includes a particular location,
|
If the query includes a particular location,
|
||||||
|
@ -55,11 +55,11 @@ class StockItemSerializer(serializers.ModelSerializer):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
||||||
|
|
||||||
part = PartBriefSerializer(many=False, read_only=True)
|
|
||||||
location = LocationBriefSerializer(many=False, read_only=True)
|
|
||||||
status_text = serializers.CharField(source='get_status_display', read_only=True)
|
status_text = serializers.CharField(source='get_status_display', read_only=True)
|
||||||
|
|
||||||
|
part_detail = PartBriefSerializer(source='part', many=False, read_only=True)
|
||||||
|
location_detail = LocationBriefSerializer(source='location', many=False, read_only=True)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def setup_eager_loading(queryset):
|
def setup_eager_loading(queryset):
|
||||||
queryset = queryset.prefetch_related('part')
|
queryset = queryset.prefetch_related('part')
|
||||||
@ -69,14 +69,29 @@ class StockItemSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
|
||||||
|
part_detail = kwargs.pop('part_detail', False)
|
||||||
|
location_detail = kwargs.pop('location_detail', False)
|
||||||
|
|
||||||
|
super(StockItemSerializer, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
if part_detail is not True:
|
||||||
|
self.fields.pop('part_detail')
|
||||||
|
|
||||||
|
if location_detail is not True:
|
||||||
|
self.fields.pop('location_detail')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = StockItem
|
model = StockItem
|
||||||
fields = [
|
fields = [
|
||||||
'pk',
|
'pk',
|
||||||
'url',
|
'url',
|
||||||
'part',
|
'part',
|
||||||
|
'part_detail',
|
||||||
'supplier_part',
|
'supplier_part',
|
||||||
'location',
|
'location',
|
||||||
|
'location_detail',
|
||||||
'in_stock',
|
'in_stock',
|
||||||
'quantity',
|
'quantity',
|
||||||
'serial',
|
'serial',
|
||||||
|
@ -141,6 +141,8 @@
|
|||||||
{% if location %}
|
{% if location %}
|
||||||
location: {{ location.id }},
|
location: {{ location.id }},
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
part_detail: true,
|
||||||
|
location_detail: true,
|
||||||
},
|
},
|
||||||
url: "{% url 'api-stock-list' %}",
|
url: "{% url 'api-stock-list' %}",
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user