def adduser(request): email = request.session.get('email', None) user_type = request.session.get('user_type', None) if email and user_type == 1: if request.method == "POST": first_name = request.POST.get('first_name', None) last_name = request.POST.get('last_name', None) email = request.POST.get('email', None) address = request.POST.get('address', None) password = request.POST.get('password', None) amount = request.POST.get('amount', None) context_dict = dict() if (first_name == '') or (last_name == '') or (email == '') or (address == '') or (password == '' )or (amount == '' ): context_dict['messages'] = "First name, Last name, email, password, Amount, address can't be empty. all fields required." context_dict['status'] = 0 else: check_email = email__exist(email) if check_email: context_dict['messages'] = "This email is already registered please enter another one." context_dict['status'] = 0 else: gmt = time.gmtime() userData = AuthUser() dataDeposit = Deposit() accuntData = CustomerAccountdetail() tran = Transaction() userData.first_name = first_name.capitalize() userData.last_name = last_name userData.email = email.capitalize() userData.password = make_password(password,salt=None,hasher='default') userData.username = email userData.is_superuser = 2 userData.is_staff = 1 userData.is_active = 1 userData.date_joined = datetime.now() userData.save() # print(userData.id) accuntData.address = address accuntData.account_no = calendar.timegm(gmt) accuntData.acc_user_id = userData.id accuntData.created = datetime.now() accuntData.save() dataDeposit.amount += int(amount) dataDeposit.date = datetime.now() dataDeposit.dep_user_id = userData.id dataDeposit.save() tran.amount = amount tran.account_no = accuntData.account_no tran.tran_type = 'Deposit' tran.date = datetime.now() tran.tran_user_id = userData.id tran.save() context_dict['messages'] = "Successfully Created Account." context_dict['status'] = 1 return JsonResponse(context_dict) elif email: return HttpResponseRedirect('/account/summary') else: return HttpResponseRedirect('/')
def clean(self): description = self.cleaned_data.get("description") amount = self.cleaned_data.get("amount") source = self.cleaned_data.get("sourceiban") destinationiban = self.cleaned_data.get("destinationiban") if source.user != self.request.user: raise ValidationError("This is not your Account") try: destination = Accounts.objects.get(iban = destinationiban) except Accounts.DoesNotExist: raise ValidationError("Wrong Destination IBAN") if source.amount > amount: transaction = Transaction() transaction.amount = amount transaction.description = description transaction.sourceaccount = source transaction.destinationaccount = destination transaction.currency_type = source.currency_type transaction.sending_date = date.today() transaction.make_transaction() else: raise ValidationError("Not Enough Account Balance")
def task_do_clearance(request, clearance_id): logging.info('task do clearance - clearance_id=%s'%clearance_id) clearance = Clearance.get_by_id(int(clearance_id)) if clearance is None: raise Http404 logging.info('clearance = %s'%clearance) items = ClearanceItem.objects.all().ancestor(clearance) for i in items: logging.info('i=%s'%i) if not (i.transaction_item is None): logging.info('has transaction...') if not i.clear: logging.info('but,not clear...') i.clear = True i.save() logging.info('cleared') else: tr = Transaction.objects.all().filter('clearance_item_key =', i.key()).get() if not (tr is None): logging.info('corresponding transaction found (%s)'%tr) i.transaction_item=tr logging.info('linked') else: logging.info('no corresponding transaction found') tr = Transaction(parent=i.account) tr.setDate() tr.clearance_item_key = i.key() if i.purpose == 'pick': logging.info('pick item') tr.purpose = 'payment' tr.order_item_key = i.order_item.key() tr.amount = -i.cost tr.desc = i.desc elif i.purpose == 'give': logging.info('give item') tr.purpose = 'payment' tr.amount = -i.cost tr.desc = i.desc elif i.purpose == 'deposit': logging.info('deposit item') tr.purpose = 'deposit' tr.amount = i.cost tr.desc = i.desc elif i.purpose == 'load': logging.info('load item') tr.purpose = 'deposit' tr.amount = i.cost tr.desc = i.desc else: logging.info('unexpected purpose (%s)'%i.purpose) tr = None logging.info('new tr=%s'%tr) if not (tr is None): tr.save() logging.info('tr save ok %s'%tr) i.transaction_item = tr i.clear = True i.save() logging.info('new tr=%s'%tr) logging.info('unlock clearance') clearance.status = 'closed' clearance.lock = False clearance.clear = True clearance.save() return HttpResponse('ok')