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