fix - if rancher duplicated in check with national code in pos

This commit is contained in:
2025-11-11 13:45:23 +03:30
parent a66b29e609
commit 816bbeeb4d
2 changed files with 19 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
from rest_framework.exceptions import APIException
from rest_framework import status
from rest_framework.exceptions import APIException
class UniqueRancherApiException(APIException):
@@ -7,6 +7,11 @@ class UniqueRancherApiException(APIException):
default_detail = "دامدار با این کد ملی از قبل در سیستم وجود دارد" # noqa
class DuplicateRancherException(APIException):
status_code = status.HTTP_403_FORBIDDEN
default_detail = "دامدار با این شماره تماس از قبل در سیستم وجود دارد" # noqa
class HerdCapacityException(APIException):
status_code = status.HTTP_403_FORBIDDEN
default_detail = "مقدار حجم سبک و سنگین وارد شده از ظرفیت گله بیشتر میباشد" # noqa

View File

@@ -1,15 +1,17 @@
from apps.herd.pos.api.v1.serializers import HerdSerializer, RancherSerializer
from apps.livestock.web.api.v1.serializers import LiveStockSerializer
from apps.core.mixins.search_mixin import DynamicSearchMixin
from django.db import transaction
from rest_framework import status
from rest_framework import viewsets
from rest_framework.decorators import action
from rest_framework.exceptions import APIException
from rest_framework.permissions import AllowAny
from rest_framework.response import Response
from rest_framework.decorators import action
from common.tools import CustomOperations
from rest_framework import viewsets
from apps.core.mixins.search_mixin import DynamicSearchMixin
from apps.herd.exception import DuplicateRancherException
from apps.herd.models import Herd, Rancher
from django.db import transaction
from rest_framework import status
from apps.herd.pos.api.v1.serializers import HerdSerializer, RancherSerializer
from apps.livestock.web.api.v1.serializers import LiveStockSerializer
from common.tools import CustomOperations
class HerdViewSet(viewsets.ModelViewSet):
@@ -139,6 +141,9 @@ class RancherViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
rancher = self.queryset.filter(national_code=request.data['national_code'])
if len(rancher) > 1:
raise DuplicateRancherException()
if rancher.exists():
serializer = self.serializer_class(rancher.first())
return Response(serializer.data, status=status.HTTP_200_OK)