validation of organization bank accounts

This commit is contained in:
2025-11-05 17:16:54 +03:30
parent 6811217f01
commit 6791938bd9
2 changed files with 34 additions and 3 deletions

View File

@@ -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):