mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 19:46:46 +00:00
Merge pull request #2370 from SchrodingersGat/api-forms
Serial number placeholders
This commit is contained in:
commit
82d5952ddd
@ -42,7 +42,7 @@ from build.models import Build
|
|||||||
|
|
||||||
from . import serializers as part_serializers
|
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.api import AttachmentMixin
|
||||||
|
|
||||||
from InvenTree.status_codes import BuildStatus
|
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):
|
class PartDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||||
""" API endpoint for detail view of a single Part object """
|
""" 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+)/?', 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'),
|
url(r'^.*$', PartList.as_view(), name='api-part-list'),
|
||||||
]
|
]
|
||||||
|
@ -433,6 +433,7 @@
|
|||||||
$("#stock-serialize").click(function() {
|
$("#stock-serialize").click(function() {
|
||||||
|
|
||||||
serializeStockItem({{ item.pk }}, {
|
serializeStockItem({{ item.pk }}, {
|
||||||
|
part: {{ item.part.pk }},
|
||||||
reload: true,
|
reload: true,
|
||||||
data: {
|
data: {
|
||||||
quantity: {{ item.quantity }},
|
quantity: {{ item.quantity }},
|
||||||
|
@ -54,6 +54,7 @@ function inventreeGet(url, filters={}, options={}) {
|
|||||||
data: filters,
|
data: filters,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
|
async: (options.async == false) ? false : true,
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
if (options.success) {
|
if (options.success) {
|
||||||
options.success(response);
|
options.success(response);
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
disableFormInput,
|
disableFormInput,
|
||||||
enableFormInput,
|
enableFormInput,
|
||||||
hideFormInput,
|
hideFormInput,
|
||||||
|
setFormInputPlaceholder,
|
||||||
setFormGroupVisibility,
|
setFormGroupVisibility,
|
||||||
showFormInput,
|
showFormInput,
|
||||||
*/
|
*/
|
||||||
@ -1276,6 +1277,11 @@ function initializeGroups(fields, options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the placeholder value for a field
|
||||||
|
function setFormInputPlaceholder(name, placeholder, options) {
|
||||||
|
$(options.modal).find(`#id_${name}`).attr('placeholder', placeholder);
|
||||||
|
}
|
||||||
|
|
||||||
// Clear a form input
|
// Clear a form input
|
||||||
function clearFormInput(name, options) {
|
function clearFormInput(name, options) {
|
||||||
updateFieldValue(name, null, {}, options);
|
updateFieldValue(name, null, {}, options);
|
||||||
|
@ -80,6 +80,20 @@ function serializeStockItem(pk, options={}) {
|
|||||||
notes: {},
|
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);
|
constructForm(url, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,10 +158,26 @@ function stockItemFields(options={}) {
|
|||||||
// If a "trackable" part is selected, enable serial number field
|
// If a "trackable" part is selected, enable serial number field
|
||||||
if (data.trackable) {
|
if (data.trackable) {
|
||||||
enableFormInput('serial_numbers', opts);
|
enableFormInput('serial_numbers', opts);
|
||||||
// showFormInput('serial_numbers', opts);
|
|
||||||
|
// Request part serial number information from the server
|
||||||
|
inventreeGet(`/api/part/${data.pk}/serial-numbers/`, {}, {
|
||||||
|
success: function(data) {
|
||||||
|
var placeholder = '';
|
||||||
|
if (data.next) {
|
||||||
|
placeholder = `{% trans "Next available serial number" %}: ${data.next}`;
|
||||||
|
} else if (data.latest) {
|
||||||
|
placeholder = `{% trans "Latest serial number" %}: ${data.latest}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
setFormInputPlaceholder('serial_numbers', placeholder, opts);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
clearFormInput('serial_numbers', opts);
|
clearFormInput('serial_numbers', opts);
|
||||||
disableFormInput('serial_numbers', opts);
|
disableFormInput('serial_numbers', opts);
|
||||||
|
|
||||||
|
setFormInputPlaceholder('serial_numbers', '{% trans "This part cannot be serialized" %}', opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable / disable fields based on purchaseable status
|
// Enable / disable fields based on purchaseable status
|
||||||
|
Loading…
x
Reference in New Issue
Block a user