|
@@ -9,27 +9,15 @@ from django.contrib.auth.decorators import login_required
|
|
|
def dashboard(request):
|
|
def dashboard(request):
|
|
|
movimientos = Movimiento.objects.filter(usuario=request.user).order_by('-fecha')
|
|
movimientos = Movimiento.objects.filter(usuario=request.user).order_by('-fecha')
|
|
|
|
|
|
|
|
- form = FiltroForm(request.GET or None)
|
|
|
|
|
- form.fields['cuenta'].queryset = Cuenta.objects.filter(usuario=request.user)
|
|
|
|
|
-
|
|
|
|
|
- if form.is_valid():
|
|
|
|
|
- if form.cleaned_data['fecha_inicio']:
|
|
|
|
|
- movimientos = movimientos.filter(fecha__gte=form.cleaned_data['fecha_inicio'])
|
|
|
|
|
- if form.cleaned_data['fecha_fin']:
|
|
|
|
|
- movimientos = movimientos.filter(fecha__lte=form.cleaned_data['fecha_fin'])
|
|
|
|
|
- if form.cleaned_data['cuenta']:
|
|
|
|
|
- cuenta = form.cleaned_data['cuenta']
|
|
|
|
|
- movimientos = movimientos.filter(models.Q(cuenta_origen=cuenta) | models.Q(cuenta_destino=cuenta))
|
|
|
|
|
-
|
|
|
|
|
ingresos = sum(m.monto for m in movimientos if m.cuenta_destino.tipo == 'ingreso')
|
|
ingresos = sum(m.monto for m in movimientos if m.cuenta_destino.tipo == 'ingreso')
|
|
|
gastos = sum(m.monto for m in movimientos if m.cuenta_origen.tipo == 'gasto')
|
|
gastos = sum(m.monto for m in movimientos if m.cuenta_origen.tipo == 'gasto')
|
|
|
balance = ingresos - gastos
|
|
balance = ingresos - gastos
|
|
|
|
|
+
|
|
|
return render(request, 'dashboard.html', {
|
|
return render(request, 'dashboard.html', {
|
|
|
'movimientos': movimientos,
|
|
'movimientos': movimientos,
|
|
|
'ingresos': ingresos,
|
|
'ingresos': ingresos,
|
|
|
'gastos': gastos,
|
|
'gastos': gastos,
|
|
|
'balance': balance,
|
|
'balance': balance,
|
|
|
- 'form': form,
|
|
|
|
|
'user': request.user,
|
|
'user': request.user,
|
|
|
})
|
|
})
|
|
|
|
|
|