add distribution delete exception
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
from rest_framework.exceptions import APIException
|
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
|
from rest_framework.exceptions import APIException
|
||||||
|
|
||||||
|
|
||||||
class QuotaWeightException(APIException):
|
class QuotaWeightException(APIException):
|
||||||
@@ -18,6 +18,14 @@ class DistributionWeightException(APIException):
|
|||||||
default_code = 'error'
|
default_code = 'error'
|
||||||
|
|
||||||
|
|
||||||
|
class DistributionDeletedException(APIException):
|
||||||
|
""" if distribution is deleted """
|
||||||
|
|
||||||
|
status_code = status.HTTP_400_BAD_REQUEST
|
||||||
|
default_detail = "امکان حذف این توزیع وجود ندارد. ورود به انبار یا توزیعی برای آن ثبت شده است" # noqa
|
||||||
|
default_code = 'error'
|
||||||
|
|
||||||
|
|
||||||
class QuotaClosedException(APIException):
|
class QuotaClosedException(APIException):
|
||||||
""" if quota is closed, operations can not be done """
|
""" if quota is closed, operations can not be done """
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from rest_framework.response import Response
|
|||||||
from apps.core.mixins.search_mixin import DynamicSearchMixin
|
from apps.core.mixins.search_mixin import DynamicSearchMixin
|
||||||
from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin
|
from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin
|
||||||
from apps.core.pagination import CustomPageNumberPagination
|
from apps.core.pagination import CustomPageNumberPagination
|
||||||
|
from apps.product import exceptions
|
||||||
from apps.product import models as product_models
|
from apps.product import models as product_models
|
||||||
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 common.helpers import get_organization_by_user
|
from common.helpers import get_organization_by_user
|
||||||
@@ -159,10 +160,7 @@ class QuotaDistributionViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSe
|
|||||||
if quota_distribution.inventory_entry.exists() or self.queryset.filter(
|
if quota_distribution.inventory_entry.exists() or self.queryset.filter(
|
||||||
parent_distribution=quota_distribution.id
|
parent_distribution=quota_distribution.id
|
||||||
):
|
):
|
||||||
raise APIException(
|
raise exceptions.DistributionDeletedException()
|
||||||
"امکان حذف این توزیع وجود ندارد. ورود به انبار یا توزیعی برای آن ثبت شده است", # noqa
|
|
||||||
status.HTTP_400_BAD_REQUEST
|
|
||||||
)
|
|
||||||
try:
|
try:
|
||||||
trash(self.queryset, pk)
|
trash(self.queryset, pk)
|
||||||
return Response(status=status.HTTP_200_OK)
|
return Response(status=status.HTTP_200_OK)
|
||||||
|
|||||||
Reference in New Issue
Block a user