export RFC month timbres
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
from django.urls import path,include
|
||||
from .views import index,add_timbre, timbres_cliente,saldo_funct,ClientesUpdateView
|
||||
from .views import index,add_timbre, timbres_cliente,saldo_funct,ClientesUpdateView, export_Excel
|
||||
urlpatterns = [
|
||||
path('', index, name='index'),
|
||||
path('add_timbre/', add_timbre, name='add_timbre'),
|
||||
path('timbres_cliente/<str:RFC>/', timbres_cliente, name='timbres_cliente'),
|
||||
path('get_saldo/', saldo_funct, name='saldo_funct'),
|
||||
path('cliente/update/<int:pk>/',ClientesUpdateView.as_view(),name='update_cliente'),
|
||||
path('get_timbres_xls/', export_Excel, name='export_Excel'),
|
||||
]
|
||||
@@ -11,6 +11,11 @@ from .forms import ClienteForm
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.contrib.auth.mixins import UserPassesTestMixin
|
||||
|
||||
|
||||
#EXCEL
|
||||
from openpyxl import Workbook
|
||||
from openpyxl.styles import Alignment, Border, Font, PatternFill, Side
|
||||
|
||||
@login_required
|
||||
def index(request):
|
||||
|
||||
@@ -148,4 +153,37 @@ class ClientesUpdateView(UserPassesTestMixin,LoginRequiredMixin,UpdateView):
|
||||
|
||||
def test_func(self):
|
||||
#self.request.user.groups.all()
|
||||
return self.request.user.groups.filter(name= 'admin_soft')
|
||||
return self.request.user.groups.filter(name= 'admin_soft')
|
||||
|
||||
|
||||
def export_Excel(request):
|
||||
RFC = request.GET.get('RFC', '')
|
||||
|
||||
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))
|
||||
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 = "ListadoObjeto.xlsx"
|
||||
response = HttpResponse(content_type="application/ms-excel")
|
||||
contenido = "attachment; filename = {0}".format(nombre_archivo)
|
||||
response["Content-Disposition"] = contenido
|
||||
wb.save(response)
|
||||
return response
|
||||
Reference in New Issue
Block a user