import - service area in organization & validate in org rancher link
This commit is contained in:
@@ -5,7 +5,7 @@ from apps.authentication.api.v1.serializers.serializer import (
|
||||
ProvinceSerializer,
|
||||
CitySerializer
|
||||
)
|
||||
from apps.herd.exception import HerdCapacityException
|
||||
from apps.herd.exception import HerdCapacityException, HerdException
|
||||
from apps.herd.models import Herd, Rancher, RancherOrganizationLink
|
||||
|
||||
|
||||
@@ -70,6 +70,19 @@ class RancherOrganizationLinkSerializer(serializers.ModelSerializer):
|
||||
model = RancherOrganizationLink
|
||||
fields = '__all__'
|
||||
|
||||
def validate(self, attrs):
|
||||
rancher = attrs['rancher']
|
||||
organization = attrs['organization']
|
||||
|
||||
if self.Meta.model.objects.filter(rancher=rancher, organization=organization).exists():
|
||||
raise HerdException(message="دامدار برای تعاونی مد نظر از قبل وجود دارد", status_code=403) # noqa
|
||||
|
||||
if self.instance:
|
||||
if rancher.city not in organization.service_area:
|
||||
raise HerdException(message="دامدار در محدوده فعالیت تعاونی قرار ندارد", status_code=403) # noqa
|
||||
|
||||
return attrs
|
||||
|
||||
def to_representation(self, instance):
|
||||
representation = super().to_representation(instance)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user