bank account existance exception

This commit is contained in:
2025-11-05 12:47:13 +03:30
parent 1942042a2b
commit 57b8d10714
3 changed files with 18 additions and 4 deletions

View File

@@ -5,7 +5,7 @@ from django.db.models import Q
from rest_framework import serializers from rest_framework import serializers
from apps.authentication.exceptions import UserExistException, OrganizationNationalUniqueIDException, \ from apps.authentication.exceptions import UserExistException, OrganizationNationalUniqueIDException, \
OrganizationTypeRepeatableException OrganizationTypeRepeatableException, BankAccountExistException
from apps.authentication.models import ( from apps.authentication.models import (
User, User,
City, City,
@@ -51,6 +51,14 @@ class BankAccountSerializer(serializers.ModelSerializer):
model = BankAccountInformation model = BankAccountInformation
fields = '__all__' 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): def update(self, instance, validated_data):
""" update user bank account information """ """ update user bank account information """
instance.name = validated_data.get('name', instance.name) instance.name = validated_data.get('name', instance.name)

View File

@@ -11,6 +11,12 @@ class TokenBlackListedException(APIException):
default_code = 'unauthorized' default_code = 'unauthorized'
class BankAccountExistException(APIException):
status_code = status.HTTP_403_FORBIDDEN
default_detail = "اطلاعات بانکی وارد شده از قبل ثبت شده است" # noqa
default_code = "اطلاعات بانکی وارد شده از قبل ثبت شده است" # noqa
class OrganizationBankAccountException(APIException): class OrganizationBankAccountException(APIException):
""" if organization does not have bank account """ """ if organization does not have bank account """

View File

@@ -195,9 +195,9 @@ class BankAccountInformation(BaseModel):
) )
account_type = models.CharField(max_length=10, default='USR') account_type = models.CharField(max_length=10, default='USR')
name = models.CharField(max_length=150, null=True) name = models.CharField(max_length=150, null=True)
card = models.CharField(max_length=25, null=True, unique=True) card = models.CharField(max_length=25, null=True)
account = models.CharField(max_length=25, null=True, unique=True) account = models.CharField(max_length=25, null=True)
sheba = models.CharField(max_length=30, null=True, unique=True) sheba = models.CharField(max_length=30, null=True)
def __str__(self): def __str__(self):
return f'{self.name}-{self.card}' return f'{self.name}-{self.card}'