diff --git a/apps/pos_device/middlewares.py b/apps/pos_device/middlewares.py index 63f6105..414a352 100644 --- a/apps/pos_device/middlewares.py +++ b/apps/pos_device/middlewares.py @@ -28,3 +28,4 @@ class POSDeviceMiddleware: """ validate request headers from pos device """ data = {key: request.headers.get(key) for key in self.REQUIRED_HEADERS} + diff --git a/apps/product/web/api/v1/viewsets/quota_api.py b/apps/product/web/api/v1/viewsets/quota_api.py index 5b0ebf9..4f5cc46 100644 --- a/apps/product/web/api/v1/viewsets/quota_api.py +++ b/apps/product/web/api/v1/viewsets/quota_api.py @@ -1,4 +1,5 @@ from apps.product.web.api.v1.serializers import product_serializers as product_serializers +from apps.product.web.api.v1.serializers import quota_distribution_serializers from apps.product.web.api.v1.serializers import quota_serializers from apps.product.exceptions import QuotaExpiredTimeException from apps.core.pagination import CustomPageNumberPagination @@ -341,38 +342,28 @@ class QuotaViewSet(viewsets.ModelViewSet): # noqa @action( methods=['get'], - detail=False, - url_name='list_for_assigner', - url_path='list_for_assigner', - name='list_for_assigner' + detail=True, + url_path='distributions_by_quota', + url_name='distributions_by_quota', + name='distributions_by_quota' ) - def quotas_list_for_assigner(self, request): - """ list of quotas for creator """ + def get_distributions_by_quota(self, request, pk=None): + """ list of distributions by quota """ - assigner = product_models.UserRelations.objects.filter(user=request.user).first() - serializers = self.serializer_class( - self.queryset.filter(registerer_organization=assigner.organization), - many=True - ).data - return Response(serializers.data, status=status.HTTP_200_OK) + try: + quota = self.get_object() - @action( - methods=['get'], - detail=False, - url_name='list_for_assigned', - url_path='list_for_assigned', - name='list_for_assigned' - ) - def quotas_list_for_assigned(self, request): - """ list of quotas for assigned organizations """ - - assigned = product_models.UserRelations.objects.filter(user=request.user).first() - serializer = self.serializer_class( - self.queryset.filter(assigned_organizations=assigned.organization), - many=True - ) - - return Response(serializer.data, status=status.HTTP_200_OK) + # paginate queryset + page = self.paginate_queryset( + quota.distributions_assigned.all().order_by('-modify_date') + ) + if page is not None: + serializer = quota_distribution_serializers.QuotaDistributionSerializer( + page, many=True + ) + return self.get_paginated_response(serializer.data) + except Exception as e: + raise APIException("none object", code=403) @action( methods=['get'],