From 2d55c0974a745ef104eb8c5eb3412bc4ccb84505 Mon Sep 17 00:00:00 2001 From: fjrodriguez Date: Wed, 30 Nov 2022 08:44:59 -0600 Subject: [PATCH] filtros --- Admin/settings.py | 2 +- ...lter_timbres_options_timbres_created_at.py | 24 ++++ Clientes/models.py | 28 +++++ Clientes/urls.py | 5 +- Clientes/views.py | 60 ++++++++- Templates/Clientes/index.html | 38 +++--- Templates/Clientes/timbres_cliente.html | 118 ++++++++++++++++++ Templates/account/base.html | 11 +- Templates/account/login.html | 12 +- Templates/base.html | 29 ++--- Templates/base2.html | 58 +++++++++ Templates/partials/search_form.html | 25 ++++ Templates/sidebar.html | 6 +- 13 files changed, 370 insertions(+), 46 deletions(-) create mode 100644 Clientes/migrations/0003_alter_timbres_options_timbres_created_at.py create mode 100644 Templates/Clientes/timbres_cliente.html create mode 100644 Templates/base2.html create mode 100644 Templates/partials/search_form.html diff --git a/Admin/settings.py b/Admin/settings.py index 9c1b2ba..6a6c375 100644 --- a/Admin/settings.py +++ b/Admin/settings.py @@ -112,7 +112,7 @@ if DEBUG: 'ENGINE': 'django.db.backends.mysql', 'NAME': 'cfdi_as', 'USER': 'root', - 'PASSWORD': 'root', + 'PASSWORD': 'Soluciones28@', 'HOST': '127.0.0.1', 'PORT': '', 'OPTIONS': {'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"}, diff --git a/Clientes/migrations/0003_alter_timbres_options_timbres_created_at.py b/Clientes/migrations/0003_alter_timbres_options_timbres_created_at.py new file mode 100644 index 0000000..543ead3 --- /dev/null +++ b/Clientes/migrations/0003_alter_timbres_options_timbres_created_at.py @@ -0,0 +1,24 @@ +# Generated by Django 4.1.3 on 2022-11-29 12:14 + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('Clientes', '0002_timbres_rfcp'), + ] + + operations = [ + migrations.AlterModelOptions( + name='timbres', + options={'ordering': ('-created_at',)}, + ), + migrations.AddField( + model_name='timbres', + name='created_at', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + ] diff --git a/Clientes/models.py b/Clientes/models.py index efc7ca9..5173e99 100644 --- a/Clientes/models.py +++ b/Clientes/models.py @@ -9,3 +9,31 @@ class Timbres(models.Model): serie = models.CharField(max_length=10) tipo = models.CharField(max_length=35) + created_at = models.DateTimeField(auto_now_add=True) + class Meta: + ordering = ('-created_at',) + + +class ErroresTimbres(models.Model): + uuid = models.CharField(max_length=36) + description = models.TextField() + rfcc = models.CharField(max_length=13) + folio = models.CharField(max_length=55) + + created_at = models.DateTimeField(auto_now_add=True) + class Meta: + ordering = ('uuid',) + abstract = True + +class Clientes(models.Model): + RFC = models.CharField(max_length=13, unique=True) + Nombre = models.CharField(max_length=100) + + + Activo = models.BooleanField(default=True) + fecha_baja = models.DateField(blank=True) + + class Meta: + ordering = ('RFC',) + abstract =True + diff --git a/Clientes/urls.py b/Clientes/urls.py index e8cea62..c0860fb 100644 --- a/Clientes/urls.py +++ b/Clientes/urls.py @@ -1,6 +1,9 @@ from django.urls import path,include -from .views import index,add_timbre +from .views import index,add_timbre, timbres_cliente urlpatterns = [ path('', index, name='index'), path('add_timbre/', add_timbre, name='add_timbre'), + path('timbres_cliente//', timbres_cliente, name='timbres_cliente'), + + ] \ No newline at end of file diff --git a/Clientes/views.py b/Clientes/views.py index 7d3a950..ea26e5a 100644 --- a/Clientes/views.py +++ b/Clientes/views.py @@ -3,11 +3,21 @@ from django.http import HttpResponse from django.contrib.auth.decorators import login_required from .models import Timbres from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger +from django.db.models import Q +import datetime @login_required def index(request): - timbres_list = Timbres.objects.all() + + timbres_list = Timbres.objects.values('rfcc').distinct() + page = request.GET.get('page', 1) + + search = request.GET.get('search',None) + rfcc = request.GET.get('rfcc', None) + if rfcc: + timbres_list = Timbres.objects.filter(Q(rfcc__icontains=search)) + paginator = Paginator(timbres_list, 1) try: @@ -44,4 +54,50 @@ def add_timbre(request): return HttpResponse('ok') except Exception as e: - return HttpResponse(e) \ No newline at end of file + return HttpResponse(e) + + +def pageFunc(page,qs,per_page): + paginator = Paginator(qs,per_page) + try: + qs = paginator.page(page) + except PageNotAnInteger: + qs = Paginator.page(1) + except EmptyPage: + qs = paginator.page(paginator.num_pages) + return qs + +def timbres_cliente(request, RFC): + lista = Timbres.objects.filter(rfcc=RFC) + + search = request.GET.get('search',None) + page = request.GET.get('page', 1) + datepicker = request.GET.get('datepicker', None) + datepickerFin = request.GET.get('datepickerFin', None) + tipo = request.GET.get('tipo',None) + + + filters = {key:value for (key,value) in dict(request.GET).items() if value !=None} + print(filters) + if tipo: + lista = lista.filter(Q(tipo__icontains=search)) + if datepicker and datepickerFin: + inicio = [int(i) for i in datepicker.split("/")] + fin = [int(i) for i in datepickerFin.split("/")] + inicio.sort(reverse=True) + fin.sort(reverse=True) + start = datetime.date(inicio[0],inicio[2],inicio[1]) + end = datetime.date(fin[0],fin[2],fin[1]) + end += datetime.timedelta(days=1) + print(start, end) + lista = lista.filter(created_at__range=[start, end]) + + conteo = lista.count() + pageFunc(page,lista,1) + + context ={ + 'lista':lista, + 'conteo':conteo, + 'RFC':RFC + } + return render(request, 'Clientes/timbres_cliente.html', context) \ No newline at end of file diff --git a/Templates/Clientes/index.html b/Templates/Clientes/index.html index 90f712f..b65f64d 100644 --- a/Templates/Clientes/index.html +++ b/Templates/Clientes/index.html @@ -1,17 +1,24 @@ -{% extends "base.html" %} +{% extends "base.html" %} + + + +{% block titlePage %} + +{% endblock titlePage %} + + {% block content %} + - + - - @@ -19,15 +26,10 @@ {% for obj in timbres %} - - - - - - + @@ -35,4 +37,12 @@
UUID - - RFC Cliente + + Cliente RFC PACTipo CFDI actions
{{obj.uuid}}{{obj.rfcc}}{{obj.rfcp}}{{obj.tipo}}{{obj.rfcc}} {% if request.user.is_staff %} - View + View Timbres {% endif %}
{% endblock content %} - \ No newline at end of file + +{% block scripts %} + + +{% endblock scripts %} \ No newline at end of file diff --git a/Templates/Clientes/timbres_cliente.html b/Templates/Clientes/timbres_cliente.html new file mode 100644 index 0000000..a0e3dc4 --- /dev/null +++ b/Templates/Clientes/timbres_cliente.html @@ -0,0 +1,118 @@ + +{% extends 'base.html' %} + + + +{% block content %} +

Timbres {{RFC}}

+

Timbres totales: {{conteo}}

+ +

+ + + + + + + + + + + + + + {% for obj in lista %} + + + + + + + + {% endfor %} + +
UUIDPAC + + Tipo CFDI + Serie/Folio + + Fecha +
{{obj.uuid}}{{obj.rfcp}}{{obj.tipo}}{{obj.serie}}/{{obj.folio}}{{obj.created_at|date:"d M Y"}}
+ +{% if lista.has_other_pages %} + +{% endif %} + +{% endblock content %} + + +{% block scripts %} + +{% endblock scripts %} + + \ No newline at end of file diff --git a/Templates/account/base.html b/Templates/account/base.html index d3c5126..b82317a 100644 --- a/Templates/account/base.html +++ b/Templates/account/base.html @@ -4,11 +4,11 @@ - + - - + + @@ -16,7 +16,7 @@ - + {% block extra_head %} @@ -182,8 +182,7 @@ {% endblock %} - {% block extra_body %} - {% endblock %} + diff --git a/Templates/account/login.html b/Templates/account/login.html index 8edd799..0800017 100644 --- a/Templates/account/login.html +++ b/Templates/account/login.html @@ -27,12 +27,16 @@ {{form.password|add_class:"form-control"}} {{form.password.errors}} - - +
+ + {% comment %} + + {% endcomment %} +
@@ -40,7 +44,11 @@
+{% comment %}

Don't have an account? Register Here

+{% endcomment %} + + {% endblock %} \ No newline at end of file diff --git a/Templates/base.html b/Templates/base.html index 5b03a0c..7923815 100644 --- a/Templates/base.html +++ b/Templates/base.html @@ -4,29 +4,22 @@ - - - - + + + + + + - {% block title %}{% endblock title %} + {% block title %}{% endblock title %} - {% include 'sidebar.html' %} +
+ {% include 'sidebar.html' %}

{% block titlePage %}{% endblock titlePage %}

- -
- {% comment %} - {% include "Profiles/partials/messages.html" %} - {% endcomment %} -
- - {% block content %} - - {% endblock content %} - + {% block content %}{% endblock content %} {% include 'paginator.html' %}
@@ -36,6 +29,8 @@ + + + + + {% block title %}{% endblock title %} + + + + +
+

{% block titlePage %}{% endblock titlePage %}

+ {% block content %} + + {% endblock content %} + + {% include 'paginator.html' %} +
+ + + + + + + + {% block scripts %} + + {% endblock scripts %} + + \ No newline at end of file diff --git a/Templates/partials/search_form.html b/Templates/partials/search_form.html new file mode 100644 index 0000000..a3a389a --- /dev/null +++ b/Templates/partials/search_form.html @@ -0,0 +1,25 @@ +
+ + +
+ +
+ +
+ +
+ + + +
\ No newline at end of file diff --git a/Templates/sidebar.html b/Templates/sidebar.html index a8b292b..ddac99f 100644 --- a/Templates/sidebar.html +++ b/Templates/sidebar.html @@ -35,9 +35,9 @@ - {% comment %} - {% include "Profiles/partials/search_form.html" %} - {% endcomment %} + + {% include "partials/search_form.html" %} +