validation of organization bank accounts
This commit is contained in:
@@ -5,7 +5,8 @@ from django.db.models import Q
|
||||
from rest_framework import serializers
|
||||
|
||||
from apps.authentication.exceptions import UserExistException, OrganizationNationalUniqueIDException, \
|
||||
OrganizationTypeRepeatableException, BankAccountExistException
|
||||
OrganizationTypeRepeatableException, BankAccountExistException, BankAccountNumberAccountException, \
|
||||
BankAccountCardException, BankAccountShebaException
|
||||
from apps.authentication.models import (
|
||||
User,
|
||||
City,
|
||||
@@ -56,9 +57,21 @@ class BankAccountSerializer(serializers.ModelSerializer):
|
||||
card = attrs['card']
|
||||
sheba = attrs['sheba']
|
||||
|
||||
if self.Meta.model.objects.filter(Q(account=account) | Q(card=card) | Q(sheba=sheba)).exists():
|
||||
raise BankAccountExistException()
|
||||
if not self.instance:
|
||||
if self.Meta.model.objects.filter(Q(account=account) | Q(card=card) | Q(sheba=sheba)).exists():
|
||||
raise BankAccountExistException()
|
||||
elif self.instance:
|
||||
if self.instance.account != account:
|
||||
if self.Meta.model.objects.filter(Q(account=account)).exists():
|
||||
raise BankAccountNumberAccountException()
|
||||
|
||||
elif self.instance.card != card:
|
||||
if self.Meta.model.objects.filter(Q(card=card)).exists():
|
||||
raise BankAccountCardException()
|
||||
|
||||
elif self.instance.sheba != sheba:
|
||||
if self.Meta.model.objects.filter(Q(sheba=sheba)).exists():
|
||||
raise BankAccountShebaException()
|
||||
return attrs
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
|
||||
@@ -17,6 +17,24 @@ class BankAccountExistException(APIException):
|
||||
default_code = "اطلاعات بانکی وارد شده از قبل ثبت شده است" # noqa
|
||||
|
||||
|
||||
class BankAccountCardException(APIException):
|
||||
status_code = status.HTTP_403_FORBIDDEN
|
||||
default_detail = "شماره کارت از قبل ثبت شده است" # noqa
|
||||
default_code = "شماره کارت از قبل ثبت شده است" # noqa
|
||||
|
||||
|
||||
class BankAccountShebaException(APIException):
|
||||
status_code = status.HTTP_403_FORBIDDEN
|
||||
default_detail = "شماره شبا از قبل ثبت شده است" # noqa
|
||||
default_code = "شماره شبا از قبل ثبت شده است" # noqa
|
||||
|
||||
|
||||
class BankAccountNumberAccountException(APIException):
|
||||
status_code = status.HTTP_403_FORBIDDEN
|
||||
default_detail = "شماره حساب از قبل ثبت شده است" # noqa
|
||||
default_code = "شماره حساب از قبل ثبت شده است" # noqa
|
||||
|
||||
|
||||
class OrganizationBankAccountException(APIException):
|
||||
""" if organization does not have bank account """
|
||||
|
||||
|
||||
Reference in New Issue
Block a user