distributions list by quota
This commit is contained in:
@@ -28,3 +28,4 @@ class POSDeviceMiddleware:
|
||||
""" validate request headers from pos device """
|
||||
|
||||
data = {key: request.headers.get(key) for key in self.REQUIRED_HEADERS}
|
||||
|
||||
|
||||
@@ -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'
|
||||
# paginate queryset
|
||||
page = self.paginate_queryset(
|
||||
quota.distributions_assigned.all().order_by('-modify_date')
|
||||
)
|
||||
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
|
||||
if page is not None:
|
||||
serializer = quota_distribution_serializers.QuotaDistributionSerializer(
|
||||
page, many=True
|
||||
)
|
||||
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
return self.get_paginated_response(serializer.data)
|
||||
except Exception as e:
|
||||
raise APIException("none object", code=403)
|
||||
|
||||
@action(
|
||||
methods=['get'],
|
||||
|
||||
Reference in New Issue
Block a user