Celestino Rey 7 miesięcy temu
rodzic
commit
71ea38449d
2 zmienionych plików z 16 dodań i 2 usunięć
  1. 15 2
      src/finanzas/views.py
  2. 1 0
      src/templates/informe_categoria.html

+ 15 - 2
src/finanzas/views.py

@@ -368,11 +368,24 @@ def informe_categoria(request):
             categoria=categoria,
             usuario=request.user,
             fecha__range=(fecha_inicio_dt, fecha_fin_dt)
-        ).order_by('fecha')
+        ).order_by('fecha').aggregate(total=Sum('monto'))
+
+
+        movimientos_con_saldo = []
+        saldo_acumulado = Decimal('0.00')
+        for mov in movimientos:
+            if mov.tipo == 'Ingreso':
+                saldo_acumulado += mov.monto
+            else:
+                saldo_acumulado -= mov.monto
+            movimientos_con_saldo.append({
+                'movimiento': mov,
+                'saldo_acumulado': saldo_acumulado
+            })
 
         context = {
             'categoria': categoria,
-            'movimientos': movimientos,
+            'movimientos': movimientos_con_saldo,
             'fecha_inicio': fecha_inicio_str,
             'fecha_fin': fecha_fin_str,
         }

+ 1 - 0
src/templates/informe_categoria.html

@@ -56,6 +56,7 @@
                         {% else %}
                         <td style="color: red" class="text-end">-{{ movimiento.monto|formato_numero:2 }}</td>
                         {% endif %}
+                        <td class="text-end">{{ movimiento.saldo_acumulado|formato_numero:2 }}</td>
                     </tr>
                 {% empty %}
                     <tr><td colspan="3">No hay movimientos para esta categoría en el periodo seleccionado.</td></tr>