mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
StockLocation labels are now printable
This commit is contained in:
parent
af47b211fd
commit
d91700fd39
@ -182,29 +182,24 @@ class StockItemLabelPrint(generics.RetrieveAPIView, StockItemLabelMixin):
|
|||||||
e = sys.exc_info()[1]
|
e = sys.exc_info()[1]
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'error': _('Error during label printing'),
|
'error': _('Error during label rendering'),
|
||||||
'message': str(e),
|
'message': str(e),
|
||||||
}
|
}
|
||||||
|
|
||||||
return Response(data, status=400)
|
return Response(data, status=400)
|
||||||
|
|
||||||
return InvenTree.helpers.DownloadFile(pdf.getbuffer(), 'stock_item_labels.pdf', content_type='application/pdf')
|
return InvenTree.helpers.DownloadFile(
|
||||||
|
pdf.getbuffer(),
|
||||||
|
'stock_item_label.pdf',
|
||||||
|
content_type='application/pdf'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class StockLocationLabelList(LabelListView):
|
class StockLocationLabelMixin:
|
||||||
"""
|
"""
|
||||||
API endpoint for viewiing list of StockLocationLabel objects.
|
Mixin for extracting stock locations from query params
|
||||||
|
|
||||||
Filterable by:
|
|
||||||
|
|
||||||
- enabled: Filter by enabled / disabled status
|
|
||||||
- location: Filter by a single stock location
|
|
||||||
- locations: Filter by list of stock locations
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
queryset = StockLocationLabel.objects.all()
|
|
||||||
serializer_class = StockLocationLabelSerializer
|
|
||||||
|
|
||||||
def get_locations(self):
|
def get_locations(self):
|
||||||
"""
|
"""
|
||||||
Return a list of requested stock locations
|
Return a list of requested stock locations
|
||||||
@ -215,7 +210,7 @@ class StockLocationLabelList(LabelListView):
|
|||||||
params = self.request.query_params
|
params = self.request.query_params
|
||||||
|
|
||||||
if 'locations[]' in params:
|
if 'locations[]' in params:
|
||||||
locations = params.getlist('locations', [])
|
locations = params.getlist('locations[]', [])
|
||||||
elif 'location' in params:
|
elif 'location' in params:
|
||||||
locations = [params.get('location', None)]
|
locations = [params.get('location', None)]
|
||||||
|
|
||||||
@ -235,6 +230,22 @@ class StockLocationLabelList(LabelListView):
|
|||||||
|
|
||||||
return valid_locations
|
return valid_locations
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class StockLocationLabelList(LabelListView, StockLocationLabelMixin):
|
||||||
|
"""
|
||||||
|
API endpoint for viewiing list of StockLocationLabel objects.
|
||||||
|
|
||||||
|
Filterable by:
|
||||||
|
|
||||||
|
- enabled: Filter by enabled / disabled status
|
||||||
|
- location: Filter by a single stock location
|
||||||
|
- locations: Filter by list of stock locations
|
||||||
|
"""
|
||||||
|
|
||||||
|
queryset = StockLocationLabel.objects.all()
|
||||||
|
serializer_class = StockLocationLabelSerializer
|
||||||
|
|
||||||
def filter_queryset(self, queryset):
|
def filter_queryset(self, queryset):
|
||||||
"""
|
"""
|
||||||
Filter the StockLocationLabel queryset
|
Filter the StockLocationLabel queryset
|
||||||
@ -294,6 +305,49 @@ class StockLocationLabelDetail(generics.RetrieveUpdateDestroyAPIView):
|
|||||||
serializer_class = StockLocationLabelSerializer
|
serializer_class = StockLocationLabelSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class StockLocationLabelPrint(generics.RetrieveAPIView, StockLocationLabelMixin):
|
||||||
|
"""
|
||||||
|
API endpoint for printing a StockLocationLabel object
|
||||||
|
"""
|
||||||
|
|
||||||
|
queryset = StockLocationLabel.objects.all()
|
||||||
|
seiralizers_class = StockLocationLabelSerializer
|
||||||
|
|
||||||
|
def get(self, request, *args, **kwargs):
|
||||||
|
|
||||||
|
locations = self.get_locations()
|
||||||
|
|
||||||
|
if len(locations) == 0:
|
||||||
|
# No valid locations provided - return an error message
|
||||||
|
|
||||||
|
return Response(
|
||||||
|
{
|
||||||
|
'error': _('Must provide valid StockLocation(s)'),
|
||||||
|
},
|
||||||
|
status=400,
|
||||||
|
)
|
||||||
|
|
||||||
|
label = self.get_object()
|
||||||
|
|
||||||
|
try:
|
||||||
|
pdf = label.render(locations)
|
||||||
|
except:
|
||||||
|
e = sys.exc_info()[1]
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'error': _('Error during label rendering'),
|
||||||
|
'message': str(e),
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response(data, status=400)
|
||||||
|
|
||||||
|
return InvenTree.helpers.DownloadFile(
|
||||||
|
pdf.getbuffer(),
|
||||||
|
'stock_location_label.pdf',
|
||||||
|
content_type='application/pdf'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
label_api_urls = [
|
label_api_urls = [
|
||||||
|
|
||||||
# Stock item labels
|
# Stock item labels
|
||||||
@ -312,6 +366,7 @@ label_api_urls = [
|
|||||||
url(r'location/', include([
|
url(r'location/', include([
|
||||||
# Detail views
|
# Detail views
|
||||||
url(r'^(?P<pk>\d+)/', include([
|
url(r'^(?P<pk>\d+)/', include([
|
||||||
|
url(r'print/?', StockLocationLabelPrint.as_view(), name='api-stocklocation-label-print'),
|
||||||
url(r'^.*$', StockLocationLabelDetail.as_view(), name='api-stocklocation-label-detail'),
|
url(r'^.*$', StockLocationLabelDetail.as_view(), name='api-stocklocation-label-detail'),
|
||||||
])),
|
])),
|
||||||
|
|
||||||
|
@ -89,7 +89,13 @@ function printStockLocationLabels(locations, options={}) {
|
|||||||
locations,
|
locations,
|
||||||
{
|
{
|
||||||
success: function(pk) {
|
success: function(pk) {
|
||||||
// TODO - Print the label!
|
var href = `/api/label/location/${pk}/print/?`;
|
||||||
|
|
||||||
|
locations.forEach(function(location) {
|
||||||
|
href += `locations[]=${location}&`;
|
||||||
|
});
|
||||||
|
|
||||||
|
window.location.href = href;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user