list of organizations by province - some changes in quota an models of that
This commit is contained in:
@@ -251,6 +251,30 @@ class IncentivePlanViewSet(viewsets.ModelViewSet): # noqa
|
||||
queryset = product_models.IncentivePlan.objects.all()
|
||||
serializer_class = product_serializers.IncentivePlanSerializer
|
||||
|
||||
@transaction.atomic
|
||||
def create(self, request, *args, **kwargs):
|
||||
""" custom incentive plan create object """
|
||||
# set incentive plans with user relations like organization
|
||||
user_relation = product_models.UserRelations.objects.filter(user=request.user).first()
|
||||
request.data['registering_organization'] = user_relation.id
|
||||
|
||||
serializer = self.serializer_class(data=request.data)
|
||||
if serializer.is_valid(raise_exception=True):
|
||||
serializer.save()
|
||||
|
||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||
return Response(serializer.errors, status=status.HTTP_403_FORBIDDEN)
|
||||
|
||||
@transaction.atomic
|
||||
def list(self, request, *args, **kwargs):
|
||||
""" get incentive plans by user relations like organization """
|
||||
|
||||
user_relations = product_models.UserRelations.objects.filter(user=request.user).first()
|
||||
incentive_plans = user_relations.incentive_plans.all()
|
||||
|
||||
serializer = self.serializer_class(incentive_plans, many=True)
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
|
||||
@action(
|
||||
methods=['put'],
|
||||
detail=True,
|
||||
@@ -283,12 +307,16 @@ class IncentivePlanViewSet(viewsets.ModelViewSet): # noqa
|
||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
|
||||
class QuotaViewSet(viewsets.ModelViewSet):
|
||||
class QuotaViewSet(viewsets.ModelViewSet): # noqa
|
||||
""" apis for product quota """
|
||||
|
||||
queryset = product_models.Quota.objects.all()
|
||||
serializer_class = product_serializers.QuotaSerializer
|
||||
|
||||
@transaction.atomic
|
||||
def create(self, request, *args, **kwargs):
|
||||
pass
|
||||
|
||||
@action(
|
||||
methods=['put'],
|
||||
detail=True,
|
||||
|
||||
Reference in New Issue
Block a user