fix distribution destroy bug
This commit is contained in:
@@ -1,17 +1,16 @@
|
|||||||
from apps.notification.models import Notification
|
|
||||||
from apps.product.web.api.v1.serializers import quota_distribution_serializers as distribution_serializers
|
|
||||||
from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin
|
|
||||||
from apps.core.mixins.search_mixin import DynamicSearchMixin
|
|
||||||
from apps.core.pagination import CustomPageNumberPagination
|
|
||||||
from rest_framework.exceptions import APIException
|
|
||||||
from apps.product import models as product_models
|
|
||||||
from rest_framework.response import Response
|
|
||||||
from rest_framework.decorators import action
|
|
||||||
from rest_framework import viewsets, filters
|
|
||||||
from rest_framework import status
|
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
from rest_framework import status
|
||||||
|
from rest_framework import viewsets, filters
|
||||||
|
from rest_framework.decorators import action
|
||||||
|
from rest_framework.exceptions import APIException
|
||||||
|
from rest_framework.response import Response
|
||||||
|
|
||||||
|
from apps.core.mixins.search_mixin import DynamicSearchMixin
|
||||||
|
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.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
|
||||||
|
|
||||||
|
|
||||||
@@ -157,13 +156,13 @@ class QuotaDistributionViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSe
|
|||||||
quota_distribution = self.get_object()
|
quota_distribution = self.get_object()
|
||||||
|
|
||||||
# check if distribution has inventory entry
|
# check if distribution has inventory entry
|
||||||
if quota_distribution.inventory_entry.exists():
|
if quota_distribution.inventory_entry.exists() and quota_distribution.parent_distribution is not None:
|
||||||
raise APIException(
|
raise APIException(
|
||||||
"امکان حذف این توزیع وجود ندارد. ورود به انبار برای آن ثبت شده است", # noqa
|
"امکان حذف این توزیع وجود ندارد. ورود به انبار یا توزیعی برای آن ثبت شده است", # noqa
|
||||||
status.HTTP_400_BAD_REQUEST
|
status.HTTP_400_BAD_REQUEST
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
delete(self.queryset, pk)
|
trash(self.queryset, pk)
|
||||||
return Response(status=status.HTTP_200_OK)
|
return Response(status=status.HTTP_200_OK)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
return Response(e, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|||||||
Reference in New Issue
Block a user