bank account existance exception
This commit is contained in:
@@ -5,7 +5,7 @@ from django.db.models import Q
|
||||
from rest_framework import serializers
|
||||
|
||||
from apps.authentication.exceptions import UserExistException, OrganizationNationalUniqueIDException, \
|
||||
OrganizationTypeRepeatableException
|
||||
OrganizationTypeRepeatableException, BankAccountExistException
|
||||
from apps.authentication.models import (
|
||||
User,
|
||||
City,
|
||||
@@ -51,6 +51,14 @@ class BankAccountSerializer(serializers.ModelSerializer):
|
||||
model = BankAccountInformation
|
||||
fields = '__all__'
|
||||
|
||||
def validate(self, attrs):
|
||||
account = attrs['account']
|
||||
card = attrs['card']
|
||||
sheba = attrs['sheba']
|
||||
|
||||
if self.Meta.model.objects.filter(Q(account=account) | Q(card=card) | Q(sheba=sheba)).exists():
|
||||
raise BankAccountExistException()
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
""" update user bank account information """
|
||||
instance.name = validated_data.get('name', instance.name)
|
||||
|
||||
@@ -11,6 +11,12 @@ class TokenBlackListedException(APIException):
|
||||
default_code = 'unauthorized'
|
||||
|
||||
|
||||
class BankAccountExistException(APIException):
|
||||
status_code = status.HTTP_403_FORBIDDEN
|
||||
default_detail = "اطلاعات بانکی وارد شده از قبل ثبت شده است" # noqa
|
||||
default_code = "اطلاعات بانکی وارد شده از قبل ثبت شده است" # noqa
|
||||
|
||||
|
||||
class OrganizationBankAccountException(APIException):
|
||||
""" if organization does not have bank account """
|
||||
|
||||
|
||||
@@ -195,9 +195,9 @@ class BankAccountInformation(BaseModel):
|
||||
)
|
||||
account_type = models.CharField(max_length=10, default='USR')
|
||||
name = models.CharField(max_length=150, null=True)
|
||||
card = models.CharField(max_length=25, null=True, unique=True)
|
||||
account = models.CharField(max_length=25, null=True, unique=True)
|
||||
sheba = models.CharField(max_length=30, null=True, unique=True)
|
||||
card = models.CharField(max_length=25, null=True)
|
||||
account = models.CharField(max_length=25, null=True)
|
||||
sheba = models.CharField(max_length=30, null=True)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.name}-{self.card}'
|
||||
|
||||
Reference in New Issue
Block a user