Exemplo n.º 1
0
    def create_account(self , nameBank , typeAccount , balance):

        # Check that the user has this type of account in this bank.
        # 1) convert nameBank and typeAccount to binary.
        # 2) exists this account to ListOfIdAccount.

        # If there are accounts in this bank and this type of account is True and if not False.
        Flag = False

        binaryBank , binaryAccount = Account.convert_to_Binary(nameBank , typeAccount)

        if len(self.ListOfIdAccount) != 0 :
            for account in self.ListOfIdAccount:
                if (binaryBank + binaryAccount) == account[1:7]:
                    Flag = True 
                    break
        
        if Flag:
            return False , 'This type of account exists'
        else:

            # Check that the bank has this type of account
            # If there is type of account in this bank create account and if not return error 

            bank = ListBanks[nameBank]
            Flag = bank.contain_typeAccount(typeAccount)

            if Flag:
                # create account
                account = Account(nameBank , typeAccount , self.nationalCode)

                # deposit balance to account
                account.deposit_to_account(balance)

                # add id new account to ListOfIdAccount
                self.add_idAccount(account.getId())

                # add account to ListOfAccounts bank
                bank.add_account(account)

                return True , account.getId()
            else:
                return False , 'The bank does not support this type of account.'