mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Use existing serializers to encode information for barcode response
This commit is contained in:
parent
d19e287cb5
commit
10ee8bc666
@ -71,7 +71,7 @@ class ActionPluginView(APIView):
|
|||||||
|
|
||||||
# If we got to here, no matching action was found
|
# If we got to here, no matching action was found
|
||||||
return Response({
|
return Response({
|
||||||
'error': _("No matching action found for"),
|
'error': _("No matching action found"),
|
||||||
"action": action,
|
"action": action,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -136,4 +136,7 @@ class BarcodePluginView(APIView):
|
|||||||
# Include the original barcode data
|
# Include the original barcode data
|
||||||
response['barcode_data'] = barcode_data
|
response['barcode_data'] = barcode_data
|
||||||
|
|
||||||
|
print("Response:")
|
||||||
|
print(response)
|
||||||
|
|
||||||
return Response(response)
|
return Response(response)
|
||||||
|
@ -96,6 +96,8 @@ class PartSerializer(InvenTreeModelSerializer):
|
|||||||
queryset = queryset.prefetch_related('builds')
|
queryset = queryset.prefetch_related('builds')
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
# TODO - Include a 'category_detail' field which serializers the category object
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Part
|
model = Part
|
||||||
partial = True
|
partial = True
|
||||||
|
@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
|
from rest_framework.renderers import JSONRenderer
|
||||||
|
|
||||||
|
from stock.serializers import StockItemSerializer, LocationSerializer
|
||||||
|
from part.serializers import PartSerializer
|
||||||
|
|
||||||
import plugins.plugin as plugin
|
import plugins.plugin as plugin
|
||||||
|
|
||||||
|
|
||||||
@ -46,18 +51,31 @@ class BarcodePlugin(plugin.InvenTreePlugin):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def render_part(self, part):
|
def render_part(self, part):
|
||||||
return {
|
"""
|
||||||
'id': part.id,
|
Render a Part object to JSON
|
||||||
'name': part.full_name,
|
Use the existing serializer to do this.
|
||||||
}
|
"""
|
||||||
|
|
||||||
|
serializer = PartSerializer(part)
|
||||||
|
|
||||||
|
return serializer.data
|
||||||
|
|
||||||
def render_stock_location(self, loc):
|
def render_stock_location(self, loc):
|
||||||
return {
|
"""
|
||||||
"id": loc.id
|
Render a StockLocation object to JSON
|
||||||
}
|
Use the existing serializer to do this.
|
||||||
|
"""
|
||||||
|
|
||||||
|
serializer = LocationSerializer(loc)
|
||||||
|
|
||||||
|
return serializer.data
|
||||||
|
|
||||||
def render_stock_item(self, item):
|
def render_stock_item(self, item):
|
||||||
|
"""
|
||||||
|
Render a StockItem object to JSON.
|
||||||
|
Use the existing serializer to do this
|
||||||
|
"""
|
||||||
|
|
||||||
return {
|
serializer = StockItemSerializer(item, part_detail=True, location_detail=True, supplier_detail=True)
|
||||||
"id": item.id,
|
|
||||||
}
|
return serializer.data
|
||||||
|
Loading…
Reference in New Issue
Block a user