diff --git a/Inventario/__pycache__/forms.cpython-313.pyc b/Inventario/__pycache__/forms.cpython-313.pyc index 6fd3fff..9e6a6bb 100644 Binary files a/Inventario/__pycache__/forms.cpython-313.pyc and b/Inventario/__pycache__/forms.cpython-313.pyc differ diff --git a/Inventario/__pycache__/views.cpython-313.pyc b/Inventario/__pycache__/views.cpython-313.pyc index 46650bf..3e21d35 100644 Binary files a/Inventario/__pycache__/views.cpython-313.pyc and b/Inventario/__pycache__/views.cpython-313.pyc differ diff --git a/Inventario/forms.py b/Inventario/forms.py index 1c0b469..92c19bd 100644 --- a/Inventario/forms.py +++ b/Inventario/forms.py @@ -119,14 +119,11 @@ class VentaForm(forms.ModelForm): empty_label="Selecciona una bodega", widget=forms.Select(attrs={'class': 'btn btn-secondary dropdown-toggle ', 'data-bs-toggle': 'dropdown', 'aria-expanded': 'false'}), label="bodega") - cantidad=forms.DecimalField( - label="cantidad", - max_digits=10, - decimal_places=2, - widget=forms.NumberInput(attrs={'class': 'form-control', 'placeholder': 'Escribe un decimal'})) + class Meta: model = Venta fields = ['bodega', 'articulo', 'cantidad', 'observaciones'] widgets={ + 'cantidad': forms.NumberInput(attrs={'class': 'form-control', 'placeholder': 'Escribe un decimal'}), 'observaciones': forms.Textarea(attrs={'class':'form-control','placeholder':'describa el producto','rows':'5'}), } diff --git a/Inventario/templates/index.html b/Inventario/templates/index.html index 884fb63..f8118c9 100644 --- a/Inventario/templates/index.html +++ b/Inventario/templates/index.html @@ -2,7 +2,169 @@ {% block content %} {% if user.is_authenticated %} +
+

Dashboard - Inventario y Ventas

+ +
+ +
+
+
+
Total de Ventas
+

+ ${{ total_ventas|floatformat:2 }} +

+
+
+
+ +
+
+
+
Productos en Inventario
+

+ {{ total_productos_en_inventario }} +

+
+
+
+ +
+
+
+
Artículos Vendidos
+

+ {{ total_articulos_vendidos }} +

+
+
+
+ +
+
+
+
Proveedores
+

+ {{ total_proveedores }} +

+
+
+
+
+ + +
+ +
+

Ventas por Bodega

+ +
+ +
+

Inventario Total

+ +
+
+ +
+ +
+

Ventas por Artículo

+ +
+ +
+

Precios de Artículos

+ +
+
+
+ + {% else %} {% endif %} diff --git a/Inventario/views.py b/Inventario/views.py index cc15510..ee91729 100644 --- a/Inventario/views.py +++ b/Inventario/views.py @@ -18,6 +18,61 @@ def base(request): return render(request, 'index.html') +def graficos_view(request): + # 1. Ventas por bodega + ventas_por_bodega = ( + Venta.objects.values("bodega__nombre_bodega") + .annotate(total_ventas=Sum("total")) + ) + for item in ventas_por_bodega: + item["total_ventas"] = float(Decimal(item["total_ventas"] or 0)) # Convertir a float + + # 2. Inventario total por artículo + inventario_total = ( + inventario.objects.values("articulo__nombre_articulo") + .annotate(total=Sum("cantidad")) + ) + + # 3. Ventas por artículo + ventas_por_articulo = ( + Venta.objects.values("articulo__nombre_articulo") + .annotate(total=Sum("cantidad")) + ) + + # 4. Comparación de precios de artículos + precios_articulos = list(articulo.objects.values( + "nombre_articulo", + "precio_compra", + "precio_venta", + )) + for item in precios_articulos: + item["precio_compra"] = float(Decimal(item["precio_compra"] or 0)) # Convertir a float + item["precio_venta"] = float(Decimal(item["precio_venta"] or 0)) # Convertir a float + + # Calcular el total de ventas + total_ventas = Venta.objects.aggregate(total_ventas=Sum('total'))['total_ventas'] or Decimal(0) + + # Calcular el total de productos en inventario + total_productos_en_inventario = inventario.objects.aggregate(total_productos=Sum('cantidad'))['total_productos'] or 0 + + # Calcular el total de artículos vendidos + total_articulos_vendidos = ventas_por_articulo.aggregate(total_vendidos=Sum('total'))['total_vendidos'] or 0 + + # Calcular el total de proveedores + total_proveedores = proveedor.objects.count() + + context = { + "ventas_por_bodega": list(ventas_por_bodega), + "inventario_total": list(inventario_total), + "ventas_por_articulo": list(ventas_por_articulo), + "precios_articulos": precios_articulos, + "total_ventas": float(total_ventas), # Sumar todas las ventas totales + "total_productos_en_inventario": total_productos_en_inventario, # Número total de productos en inventario + "total_articulos_vendidos": total_articulos_vendidos, # Total de unidades vendidas + "total_proveedores": total_proveedores, # Número de proveedores + } + + return render(request, "index.html", context) def signin(request): if request.method == 'GET': return render ( request, 'signin.html',{ diff --git a/TiendAlfa/__pycache__/urls.cpython-313.pyc b/TiendAlfa/__pycache__/urls.cpython-313.pyc index 0b4ef3a..5bfef84 100644 Binary files a/TiendAlfa/__pycache__/urls.cpython-313.pyc and b/TiendAlfa/__pycache__/urls.cpython-313.pyc differ diff --git a/TiendAlfa/urls.py b/TiendAlfa/urls.py index e68c6f0..0cda0c8 100644 --- a/TiendAlfa/urls.py +++ b/TiendAlfa/urls.py @@ -20,8 +20,8 @@ from Inventario import views, viewspdf urlpatterns = [ path('admin/', admin.site.urls), -# path('',views.generar_grafico_chartjs, name='home'), - path('',views.base, name ='home'), + path('',views.graficos_view, name='home'), +# path('',views.base, name ='home'), path('logout/',views.signout, name ='logout'), path('signin/',views.signin, name ='signin'), path('proveedor/',views.proveedor_lista, name ='proveedor'),