fix - update bug in organization by org_type_field

This commit is contained in:
2025-10-29 16:39:13 +03:30
parent 7afa0d8940
commit 3b78560bb9
2 changed files with 45 additions and 17 deletions

View File

@@ -247,25 +247,49 @@ class OrganizationSerializer(serializers.ModelSerializer):
# check organization type field
# if is repeatable of type, organization will not be recreating
org_type = attrs['type']
if not org_type.is_repeatable:
if org_type.org_type_field == 'PR' and self.Meta.model.objects.filter(
type=org_type,
province=attrs['province']
).exists():
raise OrganizationTypeRepeatableException()
if not self.instance:
if not org_type.is_repeatable:
if org_type.org_type_field == 'PR' and self.Meta.model.objects.filter(
type=org_type,
province=attrs['province']
).exists():
raise OrganizationTypeRepeatableException()
if org_type.org_type_field == 'CI' and self.Meta.model.objects.filter(
type=org_type,
city=attrs['city']
).exists():
raise OrganizationTypeRepeatableException()
if org_type.org_type_field == 'CI' and self.Meta.model.objects.filter(
type=org_type,
city=attrs['city']
).exists():
raise OrganizationTypeRepeatableException()
if org_type.org_type_field == 'CO' and self.Meta.model.objects.filter(
type=org_type,
province=attrs['province'],
city=attrs['city']
).exists():
raise OrganizationTypeRepeatableException()
if org_type.org_type_field == 'CO' and self.Meta.model.objects.filter(
type=org_type,
province=attrs['province'],
).exists():
raise OrganizationTypeRepeatableException()
# check organization type field when updating
elif self.instance:
if not org_type.is_repeatable:
if org_type.org_type_field == 'PR' and self.instance.province != attrs[
'province'] and self.Meta.model.objects.filter(
type=org_type,
province=attrs['province'],
).exists():
raise OrganizationTypeRepeatableException()
if org_type.org_type_field == 'CI' and self.instance.city != attrs[
'city'] and self.Meta.model.objects.filter(
type=org_type,
city=attrs['city'],
).exists():
raise OrganizationTypeRepeatableException()
if org_type.org_type_field == 'CO' and self.instance.province != attrs[
'province'] and self.Meta.model.objects.filter(
type=org_type,
province=attrs['province'],
).exists():
raise OrganizationTypeRepeatableException()
return attrs

View File

@@ -576,3 +576,7 @@ AssertionError: .validate() should return the validated data
[2025-10-29 10:32:38,147] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
[2025-10-29 10:38:36,906] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\api.py changed, reloading.
[2025-10-29 10:38:40,119] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
[2025-10-29 10:40:02,244] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/organization-type/?org_type_field=CI HTTP/1.1" 200 675
[2025-10-29 10:40:10,133] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/organization-type/?org_type_field=PR HTTP/1.1" 200 400
[2025-10-29 10:40:16,966] INFO django.server | IP: - | Path: - | "GET /auth/api/v1/organization-type/?org_type_field=CO HTTP/1.1" 200 276
[2025-10-29 16:36:54,591] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\serializers\serializer.py changed, reloading.