distributions list by quota

This commit is contained in:
2025-07-27 08:20:52 +03:30
parent b425caf22f
commit ab55027184
2 changed files with 21 additions and 29 deletions

View File

@@ -28,3 +28,4 @@ class POSDeviceMiddleware:
""" validate request headers from pos device """ """ validate request headers from pos device """
data = {key: request.headers.get(key) for key in self.REQUIRED_HEADERS} data = {key: request.headers.get(key) for key in self.REQUIRED_HEADERS}

View File

@@ -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 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.web.api.v1.serializers import quota_serializers
from apps.product.exceptions import QuotaExpiredTimeException from apps.product.exceptions import QuotaExpiredTimeException
from apps.core.pagination import CustomPageNumberPagination from apps.core.pagination import CustomPageNumberPagination
@@ -341,38 +342,28 @@ class QuotaViewSet(viewsets.ModelViewSet): # noqa
@action( @action(
methods=['get'], methods=['get'],
detail=False, detail=True,
url_name='list_for_assigner', url_path='distributions_by_quota',
url_path='list_for_assigner', url_name='distributions_by_quota',
name='list_for_assigner' name='distributions_by_quota'
) )
def quotas_list_for_assigner(self, request): def get_distributions_by_quota(self, request, pk=None):
""" list of quotas for creator """ """ list of distributions by quota """
assigner = product_models.UserRelations.objects.filter(user=request.user).first() try:
serializers = self.serializer_class( quota = self.get_object()
self.queryset.filter(registerer_organization=assigner.organization),
many=True
).data
return Response(serializers.data, status=status.HTTP_200_OK)
@action( # paginate queryset
methods=['get'], page = self.paginate_queryset(
detail=False, quota.distributions_assigned.all().order_by('-modify_date')
url_name='list_for_assigned', )
url_path='list_for_assigned', if page is not None:
name='list_for_assigned' serializer = quota_distribution_serializers.QuotaDistributionSerializer(
) page, many=True
def quotas_list_for_assigned(self, request): )
""" list of quotas for assigned organizations """ return self.get_paginated_response(serializer.data)
except Exception as e:
assigned = product_models.UserRelations.objects.filter(user=request.user).first() raise APIException("none object", code=403)
serializer = self.serializer_class(
self.queryset.filter(assigned_organizations=assigned.organization),
many=True
)
return Response(serializer.data, status=status.HTTP_200_OK)
@action( @action(
methods=['get'], methods=['get'],