fix - update bug in organization by org_type_field
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user