import - sync_livestock/herd_rancher_sync/purchase_policy & service_area in organization
This commit is contained in:
@@ -11,6 +11,7 @@ from apps.herd.exception import DuplicateRancherException
|
||||
from apps.herd.models import Herd, Rancher
|
||||
from apps.herd.pos.api.v1.serializers import HerdSerializer, RancherSerializer
|
||||
from apps.livestock.web.api.v1.serializers import LiveStockSerializer
|
||||
from apps.pos_device.mixins.pos_device_mixin import POSDeviceMixin
|
||||
from common.tools import CustomOperations
|
||||
|
||||
|
||||
@@ -111,7 +112,7 @@ class HerdViewSet(viewsets.ModelViewSet):
|
||||
return self.get_paginated_response(serializer.data)
|
||||
|
||||
|
||||
class RancherViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
|
||||
class RancherViewSet(viewsets.ModelViewSet, DynamicSearchMixin, POSDeviceMixin):
|
||||
queryset = Rancher.objects.all() # noqa
|
||||
serializer_class = RancherSerializer
|
||||
permission_classes = [AllowAny]
|
||||
@@ -140,11 +141,17 @@ class RancherViewSet(viewsets.ModelViewSet, DynamicSearchMixin):
|
||||
""" check national code & existence of rancher """
|
||||
|
||||
rancher = self.queryset.filter(national_code=request.data['national_code'])
|
||||
org = self.get_device_organization()
|
||||
|
||||
if len(rancher) > 1:
|
||||
raise DuplicateRancherException()
|
||||
|
||||
if rancher.exists():
|
||||
|
||||
# if not RancherOrganizationLink.objects.filter(organization=org, rancher=rancher).exists():
|
||||
# if org.purchase_policy == 'INTERNAL_ONLY':
|
||||
# raise RancherOrganizationLinkException()
|
||||
|
||||
serializer = self.serializer_class(rancher.first())
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user