コード例 #1
0
def transfer(request):
    if request.method == "POST":
        f = TransactionForm(request.POST)
        if f.is_valid():
            recaccno = f.cleaned_data['receiver_accno']
            transpass = f.cleaned_data['transaction_password']
            amt = f.cleaned_data['amount']
            curruser = User.objects.get(username=request.user.username)
            balance = curruser.profile.balance
            transactionpass = curruser.profile.transaction_password
            receiver = Profile.objects.get(account_no=recaccno)
            if balance >= amt:
                if receiver is not None:
                    if transpass == transactionpass:
                        receiver.balance = receiver.balance + amt
                        receiver.save()
                        curruser.profile.balance = curruser.profile.balance - amt
                        curruser.save()
                        f.save()
                        iid = (Transaction.objects.all().aggregate(
                            Max('id')))['id__max']
                        currtrans = Transaction.objects.get(id=iid)
                        currtrans.sender_accno = curruser.profile.account_no
                        currtrans.save()
                        return render_to_response('transfer_success.html')
        return render_to_response('transfer_fail.html')
    args = {}
    #args.update(csrf(request))

    args['f'] = TransactionForm()
    print args
    #return render_to_response('register.html', args)
    return render(request, 'transfer.html', args)
コード例 #2
0
ファイル: views.py プロジェクト: mwotil/nuaza
def transact(request, product_slug, template_name="pdcts/transact.html"):
	page_title = "Bid Product"

	pdct = get_object_or_404(Product, slug=product_slug)
	offers = Transaction.objects.filter(product__slug=product_slug).order_by('-bid_price')[:1]

	if request.method =='POST':
		form = TransactionForm (request.POST)
		p = get_object_or_404(Product, slug=product_slug)
		
		email_subject = 'Approve a buyer Offer'
		email_body = "Hello %s, \n\nThis is a My Campuser seller alert send to the Site's Sellers. \n\nPlease, check your My Campuser transactions page to either Accept or Reject a new buyer offer for the product %s by using the following link: \n\nhttp://mycampuser.com/accounts/my_transactions/ \n\nRegards,\nMy Campuser Team" % (p.user, p.product_name) 

		if form.is_valid():

			r = form.cleaned_data["quantity"]

			if r > p.quantity:
#				raise forms.ValidationError('%s is only available. Request for it or less' % (p.quantity))
				qtty = "Available: %d . Enter it or Less." % (p.quantity) 
				form = BuyNowForm()
			else:

				buy = form.save(commit=False)
				buy.user = request.user
				buy.product = p
				buy.status = "Not Yet Approved"
				buy.save()
				send_mail(email_subject, email_body, '*****@*****.**', [p.user.email])

				return HttpResponseRedirect('/accounts/my_transactions/')
	else:
		p = get_object_or_404(Product, slug=product_slug)
		form = TransactionForm()
	return render_to_response(template_name, locals(), context_instance = RequestContext(request))
コード例 #3
0
def createFinancialTranx(request):
	isLoged(request)
	acc = getCurrentAccount(request)
	currentAccFina = getSavedInSession(request, 'currentAccFina')
	team = getSavedInSession(request, 'team')
	accFina = team.financialacc_set.all()
	page = request.GET.get('page','1')
	msj = ''
	
	if request.method == 'POST':
		trx = TransactionForm(request.POST)
		if trx.is_valid():
			typeTrx = request.POST.get('transTypeParam' , '')
			trxt = trx.save(commit = False)
			trxt.creator = acc
			trxt.accounttrans =  currentAccFina
			if typeTrx == 'isSpending':
				trxt.amount = trxt.amount * -1
			
			trxt.save()
			budgetlist = currentAccFina.budget_set.all()
			data = []
			if budgetlist:
				data=budgetlist[0].transactionbudget_set.filter(concept= trxt.concept)
				if data:
					
					newAmount = abs(data[0].amount) - abs(trxt.amount)
					
					if trxt.amount >=0 and data[0].amount<0:
						msj = "El presupuesto asumira este ingreso como un gasto por usar su mismo concepto."
					if (newAmount<=0):
						data[0].isDone = True
						data[0].save()
					else:
						if(data[0].amount < 0):
							data[0].amount = newAmount * -1
						else:
							data[0].amount = newAmount
						
						data[0].save()
					 
	trxs = 	Paginator(currentAccFina.transaction_set.all(),5).page(int(page))
	
	balance = 0 
	for t in trxs:
		balance += t.amount
		
	return render(request,'financialAcctnx.html',{'msjInfo':msj ,'user':getLogin(request),'accFina':accFina,'currentAccFina':currentAccFina.name,'trans':trxs,'balance':balance})
コード例 #4
0
ファイル: views.py プロジェクト: iamads/miniature-pancake
def addtransaction(request):
    categories = Category.objects.all()
    if request.method == "POST":
        form = TransactionForm(request.POST)
        if form.is_valid():
            transaction = form.save(commit=False)
            transaction.user = request.user
            transaction.save()
            return redirect("/expensemanager/")
        else:
            print form.errors
    else:
        form = TransactionForm()
    return render(request, "expensemanager/addtransaction.html", {
        'categories': categories,
        'form': form
    })
コード例 #5
0
def new_transaction(request):
    if request.session.has_key('logged_in'):
        # get the time, time as string, and location via json thingy
        now = datetime.datetime.now()
        strnow = now.strftime('%d/%m/%Y')
        # handle form submission
        if request.method == 'POST':
            # Get everything from form
            form = TransactionForm(request.POST, request.FILES)
            if form.is_valid():
                # clean up and set vars
                cd = form.cleaned_data
                item = cd['item']
                price = cd['price']
                shop = cd['shop']
                notes = cd['notes']
                bing_image = cd['bing_image']
                address = request.POST.get('address')
                lat = request.POST.get('manual-lat')
                lon = request.POST.get('manual-lon')
                t = Transaction(date=now,
                                strdate=strnow,
                                item=item,
                                price=price,
                                shop=shop,
                                notes=notes,
                                address=address,
                                bing_image=bing_image,
                                lat=lat,
                                lon=lon)
                t.save()
                success = True
                return render(request, 'new_transaction.html',
                              {'success': success})
        else:
            # not POST, render form
            form = TransactionForm()
            return render(request, 'new_transaction.html', {'form': form})
    else:
        # not logged in, render login
        return render(
            request, 'login.html', {
                'user_login': '******',
                'destiantion': 'new_transaction'
            })
コード例 #6
0
ファイル: views.py プロジェクト: mwotil/nuaza
def transact(request, product_slug, template_name="pdcts/transact.html"):
    page_title = "Bid Product"

    pdct = get_object_or_404(Product, slug=product_slug)
    offers = Transaction.objects.filter(
        product__slug=product_slug).order_by('-bid_price')[:1]

    if request.method == 'POST':
        form = TransactionForm(request.POST)
        p = get_object_or_404(Product, slug=product_slug)

        email_subject = 'Approve a buyer Offer'
        email_body = "Hello %s, \n\nThis is a My Campuser seller alert send to the Site's Sellers. \n\nPlease, check your My Campuser transactions page to either Accept or Reject a new buyer offer for the product %s by using the following link: \n\nhttp://mycampuser.com/accounts/my_transactions/ \n\nRegards,\nMy Campuser Team" % (
            p.user, p.product_name)

        if form.is_valid():

            r = form.cleaned_data["quantity"]

            if r > p.quantity:
                #				raise forms.ValidationError('%s is only available. Request for it or less' % (p.quantity))
                qtty = "Available: %d . Enter it or Less." % (p.quantity)
                form = BuyNowForm()
            else:

                buy = form.save(commit=False)
                buy.user = request.user
                buy.product = p
                buy.status = "Not Yet Approved"
                buy.save()
                send_mail(email_subject, email_body, '*****@*****.**',
                          [p.user.email])

                return HttpResponseRedirect('/accounts/my_transactions/')
    else:
        p = get_object_or_404(Product, slug=product_slug)
        form = TransactionForm()
    return render_to_response(template_name,
                              locals(),
                              context_instance=RequestContext(request))
コード例 #7
0
ファイル: views.py プロジェクト: guillaume-miara/mista
def transaction(request):

    if request.user.is_authenticated():
        # if this is a POST request we need to process the form data
        if request.method == 'POST':
            # create a form instance and populate it with data from the request:
            form = TransactionForm(request.POST)
            EntryFormSet = formset_factory(EntryForm, extra=10)
            formset = EntryFormSet(request.POST)

            # check whether it's valid:
            if form.is_valid() and formset.is_valid():
                # process the data in form.cleaned_data as required

                in_type = form.cleaned_data['type']
                in_party = form.cleaned_data['party']
                in_description = form.cleaned_data['description']

                # create the transaction
                # todo be careful because there is a DB hit with create, consider using save
                transaction = Transaction.objects.create(transaction_type=in_type,
                                                         transaction_actor=request.user.username,
                                                         transaction_party=in_party,
                                                         transaction_description=in_description)

                # now save the data for each entry in the formset
                new_entries = []

                for entry_form in formset:
                    in_transaction_gkey = transaction
                    in_product = entry_form.cleaned_data.get('product')
                    in_color = entry_form.cleaned_data.get('color')
                    in_quantity = entry_form.cleaned_data.get('quantity')

                    if in_transaction_gkey and in_product and in_color and in_quantity:

                        # Adjust the stock
                        try:
                            product = Product.objects.get(product_name=in_product, product_color=in_color)
                        except Product.DoesNotExist:
                            product = Product(product_name=in_product, product_color=in_color)
                            product.save()
                        try:
                            stk = Stock.objects.get(product_gkey=product)
                        except Stock.DoesNotExist:
                            stk = Stock(product_gkey=product)
                            stk.save()

                        if transaction.transaction_type == 'In':
                            stk.quantity = stk.quantity + in_quantity
                        else:
                            stk.quantity = stk.quantity - in_quantity
                        stk.save()

                        new_entries.append(Entry(transaction_gkey=in_transaction_gkey,
                                                 product_gkey=product,
                                                 quantity=in_quantity))
                        #todo: add try catch
                        #todo: add verification no 2 same product
                        Entry.objects.bulk_create(new_entries)

                # redirect to a new URL:
                return render(request,'mafia/index.html')

        # if a GET (or any other method) we'll create a blank form
        else:
            form = TransactionForm()
            EntryFormSet = formset_factory(EntryForm,extra=10)
            formset = EntryFormSet()
        return render(request, 'mafia/transaction.html',  {'form': form, 'formset': formset})
    else:
        return render(request, 'mafia/request_login.html')