mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Adds a simple endpoint for accessing serial number information for a Part instance
- This is not included by default in the "part detail" endpoint as it must be calculated!
This commit is contained in:
parent
8eb5e79070
commit
ef7a9b5152
@ -42,7 +42,7 @@ from build.models import Build
|
||||
|
||||
from . import serializers as part_serializers
|
||||
|
||||
from InvenTree.helpers import str2bool, isNull
|
||||
from InvenTree.helpers import str2bool, isNull, increment
|
||||
from InvenTree.api import AttachmentMixin
|
||||
|
||||
from InvenTree.status_codes import BuildStatus
|
||||
@ -410,6 +410,33 @@ class PartThumbsUpdate(generics.RetrieveUpdateAPIView):
|
||||
]
|
||||
|
||||
|
||||
class PartSerialNumberDetail(generics.RetrieveAPIView):
|
||||
"""
|
||||
API endpoint for returning extra serial number information about a particular part
|
||||
"""
|
||||
|
||||
queryset = Part.objects.all()
|
||||
|
||||
def retrieve(self, request, *args, **kwargs):
|
||||
|
||||
part = self.get_object()
|
||||
|
||||
# Calculate the "latest" serial number
|
||||
latest = part.getLatestSerialNumber()
|
||||
|
||||
data = {
|
||||
'latest': latest,
|
||||
}
|
||||
|
||||
if latest is not None:
|
||||
next = increment(latest)
|
||||
|
||||
if next != increment:
|
||||
data['next'] = next
|
||||
|
||||
return Response(data)
|
||||
|
||||
|
||||
class PartDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
""" API endpoint for detail view of a single Part object """
|
||||
|
||||
@ -1532,7 +1559,14 @@ part_api_urls = [
|
||||
url(r'^(?P<pk>\d+)/?', PartThumbsUpdate.as_view(), name='api-part-thumbs-update'),
|
||||
])),
|
||||
|
||||
url(r'^(?P<pk>\d+)/', PartDetail.as_view(), name='api-part-detail'),
|
||||
url(r'^(?P<pk>\d+)/', include([
|
||||
|
||||
# Endpoint for extra serial number information
|
||||
url(r'^serial-numbers/', PartSerialNumberDetail.as_view(), name='api-part-serial-number-detail'),
|
||||
|
||||
# Part detail endpoint
|
||||
url(r'^.*$', PartDetail.as_view(), name='api-part-detail'),
|
||||
])),
|
||||
|
||||
url(r'^.*$', PartList.as_view(), name='api-part-list'),
|
||||
]
|
||||
|
@ -433,6 +433,7 @@
|
||||
$("#stock-serialize").click(function() {
|
||||
|
||||
serializeStockItem({{ item.pk }}, {
|
||||
part: {{ item.part.pk }},
|
||||
reload: true,
|
||||
data: {
|
||||
quantity: {{ item.quantity }},
|
||||
|
@ -54,6 +54,7 @@ function inventreeGet(url, filters={}, options={}) {
|
||||
data: filters,
|
||||
dataType: 'json',
|
||||
contentType: 'application/json',
|
||||
async: (options.async == false) ? false : true,
|
||||
success: function(response) {
|
||||
if (options.success) {
|
||||
options.success(response);
|
||||
|
@ -80,6 +80,20 @@ function serializeStockItem(pk, options={}) {
|
||||
notes: {},
|
||||
};
|
||||
|
||||
if (options.part) {
|
||||
// Work out the next available serial number
|
||||
inventreeGet(`/api/part/${options.part}/serial-numbers/`, {}, {
|
||||
success: function(data) {
|
||||
if (data.next) {
|
||||
options.fields.serial_numbers.placeholder = `{% trans "Next available serial number" %}: ${data.next}`;
|
||||
} else if (data.latest) {
|
||||
options.fields.serial_numbers.placeholder = `{% trans "Latest serial number" %}: ${data.latest}`;
|
||||
}
|
||||
},
|
||||
async: false,
|
||||
});
|
||||
}
|
||||
|
||||
constructForm(url, options);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user