import - quota dashboard & some changes in product quota stat
This commit is contained in:
@@ -15,6 +15,7 @@ from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin
|
||||
from apps.core.pagination import CustomPageNumberPagination
|
||||
from apps.product import models as product_models
|
||||
from apps.product.exceptions import QuotaExpiredTimeException
|
||||
from apps.product.services.quota_dashboard_service import QuotaDashboardService
|
||||
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.viewsets import product_api
|
||||
@@ -35,7 +36,8 @@ def delete(queryset, pk):
|
||||
obj.delete()
|
||||
|
||||
|
||||
class QuotaViewSet(BaseViewSet, SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearchMixin): # noqa
|
||||
class QuotaViewSet(BaseViewSet, SoftDeleteMixin, QuotaDashboardService, viewsets.ModelViewSet,
|
||||
DynamicSearchMixin, ): # noqa
|
||||
""" apis for product quota """
|
||||
|
||||
queryset = product_models.Quota.objects.all()
|
||||
@@ -49,6 +51,8 @@ class QuotaViewSet(BaseViewSet, SoftDeleteMixin, viewsets.ModelViewSet, DynamicS
|
||||
"sale_type",
|
||||
"sale_unit__unit",
|
||||
"group",
|
||||
"created_by",
|
||||
"modified_by"
|
||||
]
|
||||
|
||||
@transaction.atomic
|
||||
@@ -351,6 +355,33 @@ class QuotaViewSet(BaseViewSet, SoftDeleteMixin, viewsets.ModelViewSet, DynamicS
|
||||
quota.save()
|
||||
return Response(status=status.HTTP_200_OK)
|
||||
|
||||
@action(
|
||||
methods=['get'],
|
||||
detail=False,
|
||||
url_path='quotas_dashboard',
|
||||
url_name='quotas_dashboard',
|
||||
name='quotas_dashboard'
|
||||
)
|
||||
def quotas_dashboard(self, request):
|
||||
"""
|
||||
dashboard of all quotas & their information
|
||||
"""
|
||||
|
||||
query_param = self.request.query_params # noqa
|
||||
|
||||
start_date = query_param.get('start') if 'start' in query_param.keys() else None
|
||||
end_date = query_param.get('end') if 'end' in query_param.keys() else None
|
||||
|
||||
quota_dashboard = self.get_dashboard(
|
||||
self,
|
||||
org=get_organization_by_user(request.user),
|
||||
start_date=start_date,
|
||||
end_date=end_date,
|
||||
search_fields=self.search_fields,
|
||||
)
|
||||
|
||||
return Response(quota_dashboard)
|
||||
|
||||
@action(
|
||||
methods=['get'],
|
||||
detail=False,
|
||||
|
||||
Reference in New Issue
Block a user