|
|
@@ -18,7 +18,7 @@ import re
|
|
|
|
|
|
from accounts import models
|
|
|
from .models import Movimiento, Cuenta, MovimientoFrecuente, Categoria, TransaccionRecurrente
|
|
|
-from .forms import MovimientoForm, FiltroForm, CuentaForm
|
|
|
+from .forms import MovimientoForm, FiltroForm, CuentaForm, FiltroMesAnioForm
|
|
|
from .recurrentes import procesar_transacciones_recurrentes
|
|
|
|
|
|
|
|
|
@@ -32,21 +32,19 @@ def dashboard(request):
|
|
|
|
|
|
hoy = now()
|
|
|
|
|
|
- # Obtener mes y año de GET o usar el actual
|
|
|
- mes = int(request.GET.get('mes', hoy.month))
|
|
|
- anio = int(request.GET.get('anio', hoy.year))
|
|
|
+ form_fecha = FiltroMesAnioForm(request.GET or None)
|
|
|
+ mes = hoy.month
|
|
|
+ anio = hoy.year
|
|
|
|
|
|
- logger.warning(f"dashboard: mes: {mes} / año: {anio}")
|
|
|
+ if form_fecha.is_valid():
|
|
|
+ mes = int(form_fecha.cleaned_data['mes'])
|
|
|
+ anio = int(form_fecha.cleaned_data['anio'])
|
|
|
|
|
|
- # Obtener último día del mes
|
|
|
- ultimo_dia = monthrange(anio, mes)[1]
|
|
|
-
|
|
|
- # Crear fechas aware
|
|
|
- inicio_naive = datetime.combine(date(anio, mes, 1), time.min)
|
|
|
- fin_naive = datetime.combine(date(anio, mes, ultimo_dia), time.max)
|
|
|
+ #logger.warning(f"dashboard: mes: {mes} / año: {anio}")
|
|
|
|
|
|
- inicio_mes = make_aware(inicio_naive) if is_naive(inicio_naive) else inicio_naive
|
|
|
- fin_mes = make_aware(fin_naive) if is_naive(fin_naive) else fin_naive
|
|
|
+ inicio_mes = timezone.make_aware(datetime(anio, mes, 1))
|
|
|
+ ultimo_dia = monthrange(anio, mes)[1]
|
|
|
+ fin_mes = timezone.make_aware(datetime(anio, mes, ultimo_dia, 23, 59, 59))
|
|
|
|
|
|
movimientos = Movimiento.objects.filter(usuario=request.user, fecha__range=(inicio_mes, fin_mes)).order_by('-fecha')
|
|
|
|
|
|
@@ -67,6 +65,7 @@ def dashboard(request):
|
|
|
'movimientos': movimientos,
|
|
|
'user': request.user,
|
|
|
'form_filtro': form_filtro,
|
|
|
+ 'form_fecha': form_fecha,
|
|
|
'favoritas': favoritas,
|
|
|
'frecuentes': frecuentes,
|
|
|
'mes': mes,
|