diff --git a/InvenTree/InvenTree/api.py b/InvenTree/InvenTree/api.py index 02975c3088..d68ecd67ad 100644 --- a/InvenTree/InvenTree/api.py +++ b/InvenTree/InvenTree/api.py @@ -71,7 +71,7 @@ class ActionPluginView(APIView): # If we got to here, no matching action was found return Response({ - 'error': _("No matching action found for"), + 'error': _("No matching action found"), "action": action, }) @@ -136,4 +136,7 @@ class BarcodePluginView(APIView): # Include the original barcode data response['barcode_data'] = barcode_data + print("Response:") + print(response) + return Response(response) diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py index d5270cabb2..788613e104 100644 --- a/InvenTree/part/serializers.py +++ b/InvenTree/part/serializers.py @@ -96,6 +96,8 @@ class PartSerializer(InvenTreeModelSerializer): queryset = queryset.prefetch_related('builds') return queryset + # TODO - Include a 'category_detail' field which serializers the category object + class Meta: model = Part partial = True diff --git a/InvenTree/plugins/barcode/barcode.py b/InvenTree/plugins/barcode/barcode.py index 6710c0f78e..f8bd82f744 100644 --- a/InvenTree/plugins/barcode/barcode.py +++ b/InvenTree/plugins/barcode/barcode.py @@ -2,6 +2,11 @@ import hashlib +from rest_framework.renderers import JSONRenderer + +from stock.serializers import StockItemSerializer, LocationSerializer +from part.serializers import PartSerializer + import plugins.plugin as plugin @@ -46,18 +51,31 @@ class BarcodePlugin(plugin.InvenTreePlugin): return None def render_part(self, part): - return { - 'id': part.id, - 'name': part.full_name, - } + """ + Render a Part object to JSON + Use the existing serializer to do this. + """ + + serializer = PartSerializer(part) + + return serializer.data 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): + """ + Render a StockItem object to JSON. + Use the existing serializer to do this + """ - return { - "id": item.id, - } + serializer = StockItemSerializer(item, part_detail=True, location_detail=True, supplier_detail=True) + + return serializer.data