activate quota - distribution list
This commit is contained in:
@@ -386,7 +386,7 @@ class Quota(BaseModel):
|
|||||||
return self.quota_weight - distributed_weight
|
return self.quota_weight - distributed_weight
|
||||||
|
|
||||||
def is_in_valid_time(self):
|
def is_in_valid_time(self):
|
||||||
""" check if quota allowed time for distribute, sale, etc is expired"""
|
""" check if quota allowed time for distribute, sale, etc is expired """
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
persian_date = jdatetime.datetime.fromgregorian(datetime=now)
|
persian_date = jdatetime.datetime.fromgregorian(datetime=now)
|
||||||
|
|
||||||
|
|||||||
@@ -270,9 +270,26 @@ class QuotaViewSet(viewsets.ModelViewSet): # noqa
|
|||||||
|
|
||||||
@action(
|
@action(
|
||||||
methods=['patch'],
|
methods=['patch'],
|
||||||
|
detail=True,
|
||||||
|
url_path='activate',
|
||||||
|
url_name='activate',
|
||||||
|
name='activate'
|
||||||
)
|
)
|
||||||
def activate(self, request):
|
def activate(self, request):
|
||||||
pass
|
""" to activate quota """
|
||||||
|
|
||||||
|
quota = self.get_object()
|
||||||
|
|
||||||
|
# check quota expired time
|
||||||
|
if not quota.is_in_valid_time():
|
||||||
|
raise QuotaExpiredTimeException()
|
||||||
|
|
||||||
|
if not quota.is_closed:
|
||||||
|
raise APIException("این سهمیه از قبل فعال است", status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
quota.is_closed = False
|
||||||
|
quota.save()
|
||||||
|
return Response(status=status.HTTP_200_OK)
|
||||||
|
|
||||||
@action(
|
@action(
|
||||||
methods=['get'],
|
methods=['get'],
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
from django.db.models import Q
|
||||||
|
|
||||||
from apps.product.web.api.v1.serializers import quota_distribution_serializers as distribution_serializers
|
from apps.product.web.api.v1.serializers import quota_distribution_serializers as distribution_serializers
|
||||||
from rest_framework.exceptions import APIException
|
from rest_framework.exceptions import APIException
|
||||||
from apps.product import models as product_models
|
from apps.product import models as product_models
|
||||||
@@ -66,6 +68,18 @@ class QuotaDistributionViewSet(viewsets.ModelViewSet):
|
|||||||
|
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
|
# @action(
|
||||||
|
# methods=['get'],
|
||||||
|
# url_name='my_distributions',
|
||||||
|
# url_path='my_distributions',
|
||||||
|
# name='my_distributions'
|
||||||
|
# )
|
||||||
|
# def my_distributions(self, request):
|
||||||
|
#
|
||||||
|
# distributions = self.queryset.filter(
|
||||||
|
# Q(assigned_organization='')
|
||||||
|
# )
|
||||||
|
|
||||||
@action(
|
@action(
|
||||||
methods=['put'],
|
methods=['put'],
|
||||||
detail=True,
|
detail=True,
|
||||||
|
|||||||
Reference in New Issue
Block a user