global filter by client and month
This commit is contained in:
@@ -18,7 +18,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
|||||||
SECRET_KEY = 'django-insecure-5*mm&uf5zq@t6nrs_5z8-_qtyapm^3&yz^wqqkc_a!v(!ulj-^'
|
SECRET_KEY = 'django-insecure-5*mm&uf5zq@t6nrs_5z8-_qtyapm^3&yz^wqqkc_a!v(!ulj-^'
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = False
|
DEBUG = True
|
||||||
|
|
||||||
ALLOWED_HOSTS = ['*']
|
ALLOWED_HOSTS = ['*']
|
||||||
|
|
||||||
@@ -39,6 +39,7 @@ INSTALLED_APPS = [
|
|||||||
'widget_tweaks',
|
'widget_tweaks',
|
||||||
'Admin',
|
'Admin',
|
||||||
'Clientes',
|
'Clientes',
|
||||||
|
|
||||||
|
|
||||||
]
|
]
|
||||||
SITE_ID = 1
|
SITE_ID = 1
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class Clientes(models.Model):
|
|||||||
|
|
||||||
today = datetime.date.today()
|
today = datetime.date.today()
|
||||||
year = today.year
|
year = today.year
|
||||||
print('mesmesmesmesmes',mes)
|
|
||||||
if mes==None:
|
if mes==None:
|
||||||
mes = today.month
|
mes = today.month
|
||||||
dat = datetime.datetime(int(year),int(mes),1)
|
dat = datetime.datetime(int(year),int(mes),1)
|
||||||
@@ -58,9 +58,9 @@ class Clientes(models.Model):
|
|||||||
else:#28 or 29
|
else:#28 or 29
|
||||||
findate = dat + datetime.timedelta(days=28)
|
findate = dat + datetime.timedelta(days=28)
|
||||||
findate += datetime.timedelta(days=1)
|
findate += datetime.timedelta(days=1)
|
||||||
print(f'dat {(dat)} fdate={findate}')
|
#print(f'dat {(dat)} fdate={findate}')
|
||||||
cou = Timbres.objects.filter(rfcc=self.RFC, created_at__range=[dat,findate]).count()
|
cou = Timbres.objects.filter(rfcc=self.RFC, created_at__range=[dat,findate]).count()
|
||||||
print(cou)
|
|
||||||
self.conteo_mes =cou
|
self.conteo_mes =cou
|
||||||
self.save()
|
self.save()
|
||||||
return cou
|
return cou
|
||||||
|
|||||||
@@ -174,15 +174,34 @@ class ClientesUpdateView(UserPassesTestMixin,LoginRequiredMixin,UpdateView):
|
|||||||
def export_Excel(request):
|
def export_Excel(request):
|
||||||
|
|
||||||
RFC = request.GET.get('RFC', None)
|
RFC = request.GET.get('RFC', None)
|
||||||
|
mes = request.GET.get('mes',None)
|
||||||
|
|
||||||
today = datetime.date.today()
|
today = datetime.date.today()
|
||||||
month = today.month
|
month = today.month
|
||||||
year = today.year
|
year = today.year
|
||||||
if RFC is not None:
|
|
||||||
objeto_a_trabajar = Timbres.objects.filter(rfcc=RFC, created_at__year=str(year),created_at__month=str(month))
|
if mes is None or mes =='None':
|
||||||
else:
|
mes = month
|
||||||
|
|
||||||
|
dat =datetime.datetime(int(year), int(mes),1)
|
||||||
|
|
||||||
|
if dat.month in(1,3,5,7,8,10,12):
|
||||||
|
findate = dat +datetime.timedelta(days=30)
|
||||||
|
elif dat.month in (4,6,9,11):
|
||||||
|
findate = dat+datetime.timedelta(days=29)
|
||||||
|
else:
|
||||||
|
findate = dat+datetime.timedelta(days=28)
|
||||||
|
findate +=datetime.timedelta(days=1)
|
||||||
|
print(f'dat{dat} findate:{findate}')
|
||||||
|
if mes is not None and RFC is not None:
|
||||||
|
objeto_a_trabajar = Timbres.objects.filter(rfcc=RFC, created_at__range=[dat,findate])
|
||||||
|
#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()
|
||||||
|
for i,ii in enumerate(objeto_a_trabajar):
|
||||||
|
ii.timbres_X_MES(mes=mes )
|
||||||
|
|
||||||
|
|
||||||
objeto_a_trabajar = Clientes.objects.all()
|
|
||||||
|
|
||||||
wb = Workbook()
|
wb = Workbook()
|
||||||
ws = wb.active
|
ws = wb.active
|
||||||
@@ -203,10 +222,10 @@ def export_Excel(request):
|
|||||||
for q,qq in enumerate(objeto_a_trabajar,start=2):
|
for q,qq in enumerate(objeto_a_trabajar,start=2):
|
||||||
ws['A' + str(q)] = qq.RFC
|
ws['A' + str(q)] = qq.RFC
|
||||||
ws['B'+ str(q)] = qq.Nombre
|
ws['B'+ str(q)] = qq.Nombre
|
||||||
ws['C'+ str(q)] = qq.timbres_mes_count
|
ws['C'+ str(q)] = qq.conteo_mes
|
||||||
|
|
||||||
|
|
||||||
nombre_archivo = f"Timbres_{RFC if RFC is not None else 'Clientes_MES'}_{str(year)}_{str(month)}.xlsx"
|
nombre_archivo = f"Timbres_{RFC if RFC is not None else 'Clientes_MES'}_{str(mes)}_AÑO_{str(year)}.xlsx"
|
||||||
response = HttpResponse(content_type="application/ms-excel")
|
response = HttpResponse(content_type="application/ms-excel")
|
||||||
contenido = "attachment; filename = {0}".format(nombre_archivo)
|
contenido = "attachment; filename = {0}".format(nombre_archivo)
|
||||||
response["Content-Disposition"] = contenido
|
response["Content-Disposition"] = contenido
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ Timbres disponibles Comercio Digital: {{saldo.saldo}}
|
|||||||
<th>Estado</th>
|
<th>Estado</th>
|
||||||
<th scope="col">actions</th>
|
<th scope="col">actions</th>
|
||||||
<th>
|
<th>
|
||||||
<a target="_blank" rel="noopener noreferrer" href="{% url 'export_Excel' %}">Excel Todos los clientes X Mes </a>
|
<a target="_blank" rel="noopener noreferrer" href="{% url 'export_Excel' %}?mes={{mes}}">Excel Todos los clientes X Mes </a>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -85,8 +85,8 @@ Timbres disponibles Comercio Digital: {{saldo.saldo}}
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<button class="btn btn-outline-info" id ="id_b_{{obj.RFC}}" onclick="aclick(event, '{{obj.RFC}}','{{obj.timbres_mes_count}}')">Excel</button>
|
<button class="btn btn-outline-info" id ="id_b_{{obj.RFC}}" onclick="aclick(event, '{{obj.RFC}}','{{obj.conteo_mes}}')">Excel</button>
|
||||||
<a style="display: none;" id="id_a_{{obj.RFC}}" target="_blank" rel="noopener noreferrer" href="{% url 'export_Excel' %}?RFC={{obj.RFC}}">Excel</a>
|
<a style="display: none;" id="id_a_{{obj.RFC}}" target="_blank" rel="noopener noreferrer" href="{% url 'export_Excel' %}?RFC={{obj.RFC}}&mes={{mes}}">Excel</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
Reference in New Issue
Block a user