From 8ed7b3bef2e1e32c6444c25022ab65f0325999ef Mon Sep 17 00:00:00 2001 From: fjrodriguez Date: Tue, 6 Dec 2022 11:01:11 -0600 Subject: [PATCH] mas reportes --- Clientes/models.py | 2 -- Clientes/views.py | 46 ++++++++++++++++++++++------------- Templates/Clientes/index.html | 23 +++++++++++++++--- 3 files changed, 49 insertions(+), 22 deletions(-) diff --git a/Clientes/models.py b/Clientes/models.py index 3c9b52c..4185a32 100644 --- a/Clientes/models.py +++ b/Clientes/models.py @@ -36,8 +36,6 @@ class ErroresTimbres(models.Model): class Clientes(models.Model): RFC = models.CharField(max_length=13, unique=True) Nombre = models.CharField(max_length=100) - - Activo = models.BooleanField(default=False) fecha_baja = models.DateField(blank=True,null=True) diff --git a/Clientes/views.py b/Clientes/views.py index ebf1181..04a4ff6 100644 --- a/Clientes/views.py +++ b/Clientes/views.py @@ -1,4 +1,5 @@ -from django.shortcuts import render +from django.shortcuts import render,redirect +from django.contrib import messages from django.http import HttpResponse from django.http import JsonResponse from django.contrib.auth.decorators import login_required @@ -157,29 +158,40 @@ class ClientesUpdateView(UserPassesTestMixin,LoginRequiredMixin,UpdateView): @sync_to_async(thread_sensitive=False) def export_Excel(request): - RFC = request.GET.get('RFC', '') + RFC = request.GET.get('RFC', None) today = datetime.date.today() month = today.month year = today.year - - objeto_a_trabajar = Timbres.objects.filter(rfcc=RFC, created_at__year=str(year),created_at__month=str(month)) + if RFC is not None: + objeto_a_trabajar = Timbres.objects.filter(rfcc=RFC, created_at__year=str(year),created_at__month=str(month)) + else: + + objeto_a_trabajar = Clientes.objects.all() + wb = Workbook() ws = wb.active - #contador = 1 - ws['A1']='UUID' - ws['B1']='RFC_Cliente' - ws['C1']='Fecha' - contador =2 - - for q in objeto_a_trabajar: - column = str(contador) - ws['A' + column] = q.uuid - ws['B'+ column] = q.rfcc - ws['C'+ column] = q.fecha - contador += 1 - nombre_archivo = f"Timbres_{RFC}_{str(year)}_{str(month)}.xlsx" + if RFC is not None: + #Encabezado + ws['A1']='RFC_EXPEDIDO' + ws['B1']='UUID' + ws['C1']='Fecha' + for q,qq in enumerate(objeto_a_trabajar,start=2): + ws['A' + str(q)] = qq.rfcc + ws['B'+ str(q)] = qq.uuid + ws['C'+ str(q)] = qq.fecha + else:#cuando no es pro RFC y es para contabilizar los timbres del mes de cada cliente + ws['A1']='RFC_EXPEDIDO' + ws['B1']='Nombre' + ws['C1']='Timbres' + for q,qq in enumerate(objeto_a_trabajar,start=2): + ws['A' + str(q)] = qq.RFC + ws['B'+ str(q)] = qq.Nombre + ws['C'+ str(q)] = qq.timbres_mes_count + + + nombre_archivo = f"Timbres_{RFC if RFC is not None else 'Clientes_MES'}_{str(year)}_{str(month)}.xlsx" response = HttpResponse(content_type="application/ms-excel") contenido = "attachment; filename = {0}".format(nombre_archivo) response["Content-Disposition"] = contenido diff --git a/Templates/Clientes/index.html b/Templates/Clientes/index.html index c836dc6..6acc8e2 100644 --- a/Templates/Clientes/index.html +++ b/Templates/Clientes/index.html @@ -22,13 +22,16 @@ Timbres disponibles Comercio Digital: {{saldo.saldo}} Totales Mes {{fecha|date:"F"}} Estado actions + + Excel Todos los clientes X Mes + {% for obj in lista %} - - {{obj.RFC}} + + {{obj.RFC}} {{obj.Nombre}} {{obj.timbres_mes_count}} @@ -46,7 +49,10 @@ Timbres disponibles Comercio Digital: {{saldo.saldo}} Ver Timbres {% endif %} - Excel + + + + {% endfor %} @@ -55,11 +61,22 @@ Timbres disponibles Comercio Digital: {{saldo.saldo}} {% block scripts %} {% endblock scripts %} \ No newline at end of file