import - validation on rancher organization link serializer
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.0 on 2025-12-22 11:59
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('authentication', '0049_alter_bankaccountinformation_account_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='organization',
|
||||
name='service_area',
|
||||
field=models.ManyToManyField(related_name='service_area', to='authentication.city'),
|
||||
),
|
||||
]
|
||||
@@ -74,13 +74,32 @@ class RancherOrganizationLinkSerializer(serializers.ModelSerializer):
|
||||
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 not self.instance:
|
||||
if self.Meta.model.objects.filter(rancher=rancher, organization=organization).exists():
|
||||
raise HerdException(message="دامدار برای تعاونی مد نظر از قبل وجود دارد", status_code=403) # noqa
|
||||
|
||||
elif self.Meta.model.objects.filter(
|
||||
rancher=rancher,
|
||||
organization__parent_organization=organization.parent_organization
|
||||
).exists():
|
||||
raise HerdException(
|
||||
message="دامدار نمیتواند زیر مجموعه دو تعاونی با اتحادیه یکسان باشند", # noqa
|
||||
status_code=403
|
||||
)
|
||||
|
||||
if self.instance:
|
||||
if rancher.city not in organization.service_area:
|
||||
if rancher.city not in organization.service_area.all():
|
||||
raise HerdException(message="دامدار در محدوده فعالیت تعاونی قرار ندارد", status_code=403) # noqa
|
||||
|
||||
elif self.instance.organization == organization:
|
||||
raise HerdException(message="دامدار برای تعاونی مد نظر از قبل وجود دارد", status_code=403) # noqa
|
||||
|
||||
elif self.instance.organization.parent_organization == organization.parent_organization:
|
||||
raise HerdException(
|
||||
message="دامدار نمیتواند زیر مجموعه دو تعاونی با اتحادیه یکسان باشند", # noqa
|
||||
status_code=403
|
||||
)
|
||||
|
||||
return attrs
|
||||
|
||||
def to_representation(self, instance):
|
||||
|
||||
Reference in New Issue
Block a user