dynamic mixin search for all apis
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from apps.warehouse.web.api.v1 import serializers as warehouse_serializers
|
||||
from apps.warehouse.services.search.inventory_search import InventoryEntrySearch
|
||||
from apps.core.mixins.search_mixin import DynamicSearchMixin
|
||||
from apps.warehouse import models as warehouse_models
|
||||
from common.helpers import get_organization_by_user
|
||||
from common.generics import base64_to_image_file
|
||||
@@ -12,11 +12,19 @@ from rest_framework import status
|
||||
import typing
|
||||
|
||||
|
||||
class InventoryEntryViewSet(viewsets.ModelViewSet):
|
||||
class InventoryEntryViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
|
||||
queryset = warehouse_models.InventoryEntry.objects.all()
|
||||
serializer_class = warehouse_serializers.InventoryEntrySerializer
|
||||
filter_backends = [filters.SearchFilter]
|
||||
search_fields = ['']
|
||||
search_fields = [
|
||||
"distribution__distribution_id",
|
||||
"organization__name",
|
||||
"weight",
|
||||
"balance",
|
||||
"lading_number",
|
||||
"is_confirmed",
|
||||
]
|
||||
date_field = "create_date"
|
||||
|
||||
def upload_confirmation_document(self, request, inventory: int) -> typing.Any:
|
||||
""" upload document for inventory entry confirmation """
|
||||
@@ -40,24 +48,6 @@ 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('search')
|
||||
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 """
|
||||
@@ -101,7 +91,8 @@ class InventoryEntryViewSet(viewsets.ModelViewSet):
|
||||
def my_inventory_entries(self, request):
|
||||
""" list of my inventory entries """
|
||||
|
||||
entries = self.queryset.filter(organization=get_organization_by_user(request.user))
|
||||
queryset = self.filter_queryset(self.queryset) # return by search param or all objects
|
||||
entries = queryset.filter(organization=get_organization_by_user(request.user))
|
||||
|
||||
# paginate & response
|
||||
page = self.paginate_queryset(entries)
|
||||
|
||||
Reference in New Issue
Block a user