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