diff --git a/apps/product/web/api/v1/viewsets/product_api.py b/apps/product/web/api/v1/viewsets/product_api.py index 5dcb091..f74cc75 100644 --- a/apps/product/web/api/v1/viewsets/product_api.py +++ b/apps/product/web/api/v1/viewsets/product_api.py @@ -307,7 +307,7 @@ class IncentivePlanViewSet(viewsets.ModelViewSet): # noqa def active_plans(self, request): """ return active incentive plans """ - today = datetime.datetime.now().date() + today = datetime.now().date() user_relations = product_models.UserRelations.objects.filter(user=request.user).first() incentive_plans = user_relations.incentive_plans.filter( Q(is_time_unlimited=False) | @@ -637,6 +637,44 @@ class QuotaViewSet(viewsets.ModelViewSet): # noqa except APIException as e: raise APIException(detail="data error", code=400) + @action( + methods=['get'], + detail=False, + url_path='quotas_info_by_org', + url_name='quotas_info_by_org', + name='quotas_info_by_org' + ) + def quotas_information_by_organization(self, request): + """ get quotas information of an organization """ + + quotas = self.queryset.filter( + Q(assigned_organizations=get_organization_by_user(request.user)) | + Q(registerer_organization=get_organization_by_user(request.user)) + ) + + serializer = self.serializer_class(quotas, many=True).data + return Response(serializer, status=status.HTTP_200_OK) + + @action( + methods=['get'], + detail=False, + url_path='closed_quotas', + url_name='closed_quotas', + name='closed_quotas' + ) + def closed_quotas(self, request): + """ get list of close quotas for organization """ + + quotas = quotas = self.queryset.filter( + (Q(assigned_organizations=get_organization_by_user(request.user)) | + Q(registerer_organization=get_organization_by_user(request.user))) & + Q(is_closed=True) + ) + + serialize = self.serializer_class(quotas, many=True).data + + return Response(serialize, status=status.HTTP_200_OK) + @action( methods=['put'], detail=True,