mas reportes
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user