2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 12:35:46 +00:00

Use existing serializers to encode information for barcode response

This commit is contained in:
Oliver Walters
2020-04-15 23:41:16 +10:00
parent d19e287cb5
commit 10ee8bc666
3 changed files with 34 additions and 11 deletions

View File

@ -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