Example #1
0
def set_projection(request):
    proj_date = datetime.date(int(request.POST["year"]), month_abbr_to_int(request.POST["month"], False), 1).strftime(
        "%Y-%m-%d"
    )
    trans = (
        Transaction.objects.filter(to_account=request.POST["account_id"]).filter(prediction=True).filter(date=proj_date)
    )
    if trans:
        trans = trans[0]
        trans.amount = request.POST["amount"]
        trans.save()
    else:
        trans = Transaction()
        trans.date = proj_date
        trans.to_account = Account.objects.get(pk=request.POST["account_id"])
        trans.from_account = Account.objects.get(name="Checking Account")
        trans.prediction = True
        trans.amount = Decimal(request.POST["amount"])
        trans.memo = "Projection"
        trans.save()
        # return HttpResponse(serialize('json', (trans,)), mimetype="application/json")

        # need to give back the new difference amount
    amounts = get_account_amounts_by_date(trans.to_account.id, request.POST["month"], request.POST["year"])
    return HttpResponse(amounts["diff"])
Example #2
0
    def save(self):
        '''
        manually sets the budget this is associated with based on the 
        input date
        '''

        cd = self.cleaned_data
        date = cd['date']
        month = date.month
        year = date.year
        budget, created = Budget.objects.get_or_create(month=month, year=year)
        transaction = Transaction(date=date, transaction_type=cd['transaction_type'],
            category=cd['category'], amount=cd['amount'], notes=cd['notes'],
            budget=budget)
        transaction.save()
        return transaction
Example #3
0
def set_projection(request):
	proj_date = datetime.date(int(request.POST['year']), month_abbr_to_int(request.POST['month'], False), 1).strftime('%Y-%m-%d')
	trans = Transaction.objects.filter(to_account=request.POST['account_id']).filter(prediction=True).filter(date=proj_date)
	if trans:
		trans = trans[0]
		trans.amount = request.POST['amount']
		trans.save()
	else:
		trans = Transaction()
		trans.date = proj_date
		trans.to_account = Account.objects.get(pk=request.POST['account_id'])
		trans.from_account = Account.objects.get(name="Checking Account")
		trans.prediction = True
		trans.amount = Decimal(request.POST['amount'])
		trans.memo = 'Projection'
		trans.save()
	#return HttpResponse(serialize('json', (trans,)), mimetype="application/json")
	
	#need to give back the new difference amount
	amounts = get_account_amounts_by_date(trans.to_account.id, request.POST['month'], request.POST['year'])
	return HttpResponse(amounts['diff'])