change: change inventory list serialzier
This commit is contained in:
@@ -4,8 +4,24 @@ from core.apps.wherehouse.models.inventory import Inventory
|
|||||||
|
|
||||||
|
|
||||||
class InventoryListSerializer(serializers.ModelSerializer):
|
class InventoryListSerializer(serializers.ModelSerializer):
|
||||||
|
product = serializers.SerializerMethodField(method_name='get_product')
|
||||||
|
unity = serializers.SerializerMethodField(method_name='get_unity')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Inventory
|
model = Inventory
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'quantity', 'product', 'price', 'unity'
|
'id', 'quantity', 'product', 'price', 'unity'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def get_product(self, obj):
|
||||||
|
return {
|
||||||
|
'id': obj.product.id,
|
||||||
|
'name': obj.product.name,
|
||||||
|
'type': obj.product.type
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_unity(self, obj):
|
||||||
|
return {
|
||||||
|
'id': obj.unity.id,
|
||||||
|
'value': obj.unity.value,
|
||||||
|
}
|
||||||
@@ -17,7 +17,7 @@ class InventoryListApiView(generics.GenericAPIView):
|
|||||||
def get(self, request):
|
def get(self, request):
|
||||||
wherehouse_ids = request.query_params.getlist('wherehouse_id')
|
wherehouse_ids = request.query_params.getlist('wherehouse_id')
|
||||||
if wherehouse_ids:
|
if wherehouse_ids:
|
||||||
inventories = Inventory.objects.filter(wherehouse__in=wherehouse_ids)
|
inventories = Inventory.objects.filter(wherehouse__in=wherehouse_ids).select_related('product', 'unity')
|
||||||
else:
|
else:
|
||||||
inventories = Inventory.objects.all()
|
inventories = Inventory.objects.all()
|
||||||
page = self.paginate_queryset(inventories)
|
page = self.paginate_queryset(inventories)
|
||||||
|
|||||||
Reference in New Issue
Block a user