示例#1
0
    def save(self, *args, **kwargs):
        try:
            if not self.created_at:
                self.created_at = get_time()
            self.updated_at = get_time()
            super(BaseModel, self).save(*args, **kwargs)

        except ValueError:
            return False
示例#2
0
    def save(self, *args, **kwargs):
        try:
            self.transaction_id = str(self.to_account.account_number[:5]), str(
                get_time()), str(self.to_account.account_number[6:])
            super(Transactions, self).save(*args, **kwargs)

        except ValueError:
            return False
示例#3
0
    def post(self, request):  #for past dates
        request_data = request.data
        response = ResponseEngine()
        transaction_time = get_time()
        transaction_type = 'credit'
        amount, valid_amount = Validator.isValidAmount(
            request_data.get('amount'))
        if not valid_amount:
            return response(
                'error', {
                    'message':
                    'Invalid amount for deposit - {}.'.format(str(amount)),
                    'status_code':
                    '400'
                })

        bank_account = BankAccount.objects.filter()[0]
        if not bank_account:
            return response('error', {
                'message': 'No account found.',
                'status_code': '400'
            })

        valid_transaction, message = TransationValidations.isValidTransaction(
            bank_account, amount, transaction_time, transaction_type)
        if not valid_transaction:
            return response('error', {
                'message': message,
                'status_code': '400'
            })

        bank_account.initiateTransaction(amount, transaction_time,
                                         transaction_type)
        bank_account.account_balance += amount
        bank_account.save()

        return response(
            'success', {
                'message':
                'Amount of {} {} Successfully Deposited.'.format(
                    str(bank_account.getAccountCurrency()), str(amount)),
                'status_code':
                '200',
                'body': {}
            })
示例#4
0
 def initiateTransaction(self, amount, transaction_time, transaction_type):
     Transactions.objects.create(to_account=self,
                                 transaction_type=transaction_type,
                                 transaction_start_time=transaction_time,
                                 transaction_end_time=get_time(),
                                 transaction_amount=amount)