inventory entry search & filter - distibution data in inventory rntry

This commit is contained in:
2025-07-29 10:59:04 +03:30
parent 8a229891d4
commit cf5541700b
4 changed files with 66 additions and 2 deletions

View File

@@ -1,6 +1,8 @@
from apps.warehouse.web.api.v1 import serializers as warehouse_serializers
from apps.warehouse.services.search import InventoryEntrySearch
from apps.warehouse import models as warehouse_models
from common.helpers import get_organization_by_user
from rest_framework.exceptions import APIException
from common.generics import base64_to_image_file
from common.liara_tools import upload_to_liara
from rest_framework.decorators import action
@@ -39,6 +41,24 @@ class InventoryEntryViewSet(viewsets.ModelViewSet):
inventory.save()
return Response(status=status.HTTP_200_OK)
@transaction.atomic
def list(self, request, *args, **kwargs):
""" search & filter by date range or return all objects """
query_params = self.request.query_params
query = query_params.get('query')
start_date = query_params.get('start')
end_date = query_params.get('end')
search = InventoryEntrySearch(
query,
start_date,
end_date
)
serializer = self.serializer_class(search.search(), many=True)
return Response(serializer.data, status=status.HTTP_200_OK)
@transaction.atomic
def create(self, request, *args, **kwargs):
""" custom create of inventory entry """

View File

@@ -48,9 +48,13 @@ class InventoryEntrySerializer(serializers.ModelSerializer):
def to_representation(self, instance):
representation = super().to_representation(instance)
representation['document'] = instance.document
if instance.document:
representation['document'] = instance.document
if instance.distribution:
representation['distribution'] = instance.distribution.distribution_id
representation['distribution'] = {
'distribution': instance.distribution.distribution_id,
'id': instance.distribution.id
}
return representation