fix - if rancher duplicated in check with national code in pos
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 UniqueRancherApiException(APIException):
|
class UniqueRancherApiException(APIException):
|
||||||
@@ -7,6 +7,11 @@ class UniqueRancherApiException(APIException):
|
|||||||
default_detail = "دامدار با این کد ملی از قبل در سیستم وجود دارد" # noqa
|
default_detail = "دامدار با این کد ملی از قبل در سیستم وجود دارد" # noqa
|
||||||
|
|
||||||
|
|
||||||
|
class DuplicateRancherException(APIException):
|
||||||
|
status_code = status.HTTP_403_FORBIDDEN
|
||||||
|
default_detail = "دامدار با این شماره تماس از قبل در سیستم وجود دارد" # noqa
|
||||||
|
|
||||||
|
|
||||||
class HerdCapacityException(APIException):
|
class HerdCapacityException(APIException):
|
||||||
status_code = status.HTTP_403_FORBIDDEN
|
status_code = status.HTTP_403_FORBIDDEN
|
||||||
default_detail = "مقدار حجم سبک و سنگین وارد شده از ظرفیت گله بیشتر میباشد" # noqa
|
default_detail = "مقدار حجم سبک و سنگین وارد شده از ظرفیت گله بیشتر میباشد" # noqa
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
from apps.herd.pos.api.v1.serializers import HerdSerializer, RancherSerializer
|
from django.db import transaction
|
||||||
from apps.livestock.web.api.v1.serializers import LiveStockSerializer
|
from rest_framework import status
|
||||||
from apps.core.mixins.search_mixin import DynamicSearchMixin
|
from rest_framework import viewsets
|
||||||
|
from rest_framework.decorators import action
|
||||||
from rest_framework.exceptions import APIException
|
from rest_framework.exceptions import APIException
|
||||||
from rest_framework.permissions import AllowAny
|
from rest_framework.permissions import AllowAny
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.decorators import action
|
|
||||||
from common.tools import CustomOperations
|
from apps.core.mixins.search_mixin import DynamicSearchMixin
|
||||||
from rest_framework import viewsets
|
from apps.herd.exception import DuplicateRancherException
|
||||||
from apps.herd.models import Herd, Rancher
|
from apps.herd.models import Herd, Rancher
|
||||||
from django.db import transaction
|
from apps.herd.pos.api.v1.serializers import HerdSerializer, RancherSerializer
|
||||||
from rest_framework import status
|
from apps.livestock.web.api.v1.serializers import LiveStockSerializer
|
||||||
|
from common.tools import CustomOperations
|
||||||
|
|
||||||
|
|
||||||
class HerdViewSet(viewsets.ModelViewSet):
|
class HerdViewSet(viewsets.ModelViewSet):
|
||||||
@@ -139,6 +141,9 @@ class RancherViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
|
|||||||
|
|
||||||
rancher = self.queryset.filter(national_code=request.data['national_code'])
|
rancher = self.queryset.filter(national_code=request.data['national_code'])
|
||||||
|
|
||||||
|
if len(rancher) > 1:
|
||||||
|
raise DuplicateRancherException()
|
||||||
|
|
||||||
if rancher.exists():
|
if rancher.exists():
|
||||||
serializer = self.serializer_class(rancher.first())
|
serializer = self.serializer_class(rancher.first())
|
||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||||
|
|||||||
Reference in New Issue
Block a user