浏览代码

Filtra el informe correctamente y saca el pdf bien

Celestino Rey 1 年之前
父节点
当前提交
a21c6f94d2
共有 2 个文件被更改,包括 11 次插入 和 4 次删除
  1. 10 1
      src/finanzas/views.py
  2. 1 3
      src/templates/informe_cuenta.html

+ 10 - 1
src/finanzas/views.py

@@ -489,6 +489,7 @@ def informe_cuenta(request):
             fecha_inicio = datetime.strptime(fecha_inicio_str, '%Y-%m-%d').date()
             fecha_fin = datetime.strptime(fecha_fin_str, '%Y-%m-%d').date()
         else:
+            logger.warning(f"informe_cuenta => cojo fechas por defecto")
             fecha_inicio = primer_dia
             fecha_fin = hoy
 
@@ -510,11 +511,18 @@ def informe_cuenta(request):
         saldo = 0
         movimientos_con_saldo = []
         for mov in movimientos:
+            logger.warning(f"informe_cuenta => de '{mov.cuenta_origen}' a '{mov.cuenta_destino}'")
             if mov.cuenta_origen == cuenta:
                 saldo -= mov.monto
             elif mov.cuenta_destino == cuenta:
                 saldo += mov.monto
-            movimientos_con_saldo.append((mov, saldo))
+            
+            movimientos_con_saldo.append({
+                'fecha': mov.fecha,
+                'descripcion': mov.descripcion,
+                'monto': mov.monto,
+                'saldo_despues': saldo,
+            })
 
         # Renderizado del PDF o del HTML como prefieras
         context = {
@@ -553,6 +561,7 @@ def informe_cuenta_pdf(request):
     fecha_fin_dt = timezone.make_aware(datetime.combine(fecha_fin, time.max))
 
     logger.warning(f"informe_cuenta_pdf: entre {fecha_inicio} y {fecha_fin}")
+    logger.warning(f"informe_cuenta_pdf => cuenta: {cuenta}. fecha_inicio_dt: {fecha_inicio_dt}. fecha_fin_dt: {fecha_fin_dt}")
 
     movimientos = Movimiento.objects.filter(
         Q(cuenta_origen=cuenta) | Q(cuenta_destino=cuenta),

+ 1 - 3
src/templates/informe_cuenta.html

@@ -35,17 +35,15 @@
                 <tr>
                     <th>Fecha</th>
                     <th>Descripción</th>
-                    <th>Tipo</th>
                     <th class="text-end">Monto (€)</th>
                     <th class="text-end">Saldo después (€)</th>
                 </tr>
             </thead>
             <tbody>
-                {% for item in historial %}
+                {% for item in movimientos_con_saldo %}
                 <tr>
                     <td>{{ item.fecha|date:"Y-m-d H:i" }}</td>
                     <td>{{ item.descripcion }}</td>
-                    <td>{{ item.tipo }}</td>
                     <td class="text-end">{{ item.monto|floatformat:2 }}</td>
                     <td class="text-end">{{ item.saldo_despues|floatformat:2 }}</td>
                 </tr>