New functionality

This commit is contained in:
fjrodriguez
2022-12-01 10:25:21 -06:00
parent f2aad5de52
commit 178a1ea55d
13 changed files with 157 additions and 43 deletions

View File

@@ -1,6 +1,12 @@
from pathlib import Path from pathlib import Path
import os import os
import pytz
#print time zones
# for x in pytz.all_timezones_set:
# print(x)
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent BASE_DIR = Path(__file__).resolve().parent.parent
@@ -12,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 = ['*']
@@ -155,9 +161,9 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/ # https://docs.djangoproject.com/en/4.1/topics/i18n/
LANGUAGE_CODE = 'en-us' LANGUAGE_CODE = 'es-MX'
TIME_ZONE = 'UTC' TIME_ZONE = 'CST6CDT'
USE_I18N = True USE_I18N = True

View File

@@ -1,5 +1,7 @@
from django.contrib import admin from django.contrib import admin
from .models import Timbres, saldoModel from .models import Timbres, saldoModel, Clientes
admin.site.register(Timbres) admin.site.register(Timbres)
admin.site.register(saldoModel) admin.site.register(saldoModel)
admin.site.register(Clientes)

View File

@@ -7,9 +7,7 @@ class ClientesConfig(AppConfig):
name = 'Clientes' name = 'Clientes'
def ready(self): def ready(self):
from .models import Timbres
from .signals import save_Cliente
from .models import saldoModel post_save.connect(save_Cliente,sender=Timbres)
from .signals import save_saldo
post_save.connect(save_saldo,sender=saldoModel)

View File

@@ -0,0 +1,26 @@
# Generated by Django 4.1.3 on 2022-12-01 13:35
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Clientes', '0004_saldomodel'),
]
operations = [
migrations.CreateModel(
name='Clientes',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('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)),
],
options={
'ordering': ('RFC',),
},
),
]

View File

@@ -0,0 +1,18 @@
# Generated by Django 4.1.3 on 2022-12-01 13:54
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Clientes', '0005_clientes'),
]
operations = [
migrations.AlterField(
model_name='clientes',
name='fecha_baja',
field=models.DateField(blank=True, null=True),
),
]

View File

@@ -0,0 +1,18 @@
# Generated by Django 4.1.3 on 2022-12-01 13:58
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Clientes', '0006_alter_clientes_fecha_baja'),
]
operations = [
migrations.AlterField(
model_name='timbres',
name='serie',
field=models.CharField(blank=True, max_length=10),
),
]

View File

@@ -0,0 +1,27 @@
# Generated by Django 4.1.3 on 2022-12-01 16:24
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Clientes', '0007_alter_timbres_serie'),
]
operations = [
migrations.CreateModel(
name='ErroresTimbres',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('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)),
],
options={
'ordering': ('uuid',),
},
),
]

View File

@@ -1,4 +1,5 @@
from django.db import models from django.db import models
import datetime
class saldoModel(models.Model): class saldoModel(models.Model):
@@ -11,10 +12,11 @@ class Timbres(models.Model):
rfcp = models.CharField(max_length=13) rfcp = models.CharField(max_length=13)
fecha = models.CharField(max_length=55) fecha = models.CharField(max_length=55)
folio = models.CharField(max_length=55) folio = models.CharField(max_length=55)
serie = models.CharField(max_length=10) serie = models.CharField(max_length=10,blank=True)
tipo = models.CharField(max_length=35) tipo = models.CharField(max_length=35)
created_at = models.DateTimeField(auto_now_add=True) created_at = models.DateTimeField(auto_now_add=True)
class Meta: class Meta:
ordering = ('-created_at',) ordering = ('-created_at',)
@@ -28,7 +30,7 @@ class ErroresTimbres(models.Model):
created_at = models.DateTimeField(auto_now_add=True) created_at = models.DateTimeField(auto_now_add=True)
class Meta: class Meta:
ordering = ('uuid',) ordering = ('uuid',)
abstract = True
class Clientes(models.Model): class Clientes(models.Model):
RFC = models.CharField(max_length=13, unique=True) RFC = models.CharField(max_length=13, unique=True)
@@ -36,9 +38,13 @@ class Clientes(models.Model):
Activo = models.BooleanField(default=True) Activo = models.BooleanField(default=True)
fecha_baja = models.DateField(blank=True) fecha_baja = models.DateField(blank=True,null=True)
@property
def timbres_mes_count(self):
print('date',datetime.date.today())
return Timbres.objects.filter(rfcc=self.RFC, created_at__gte=datetime.date.today()).count()
class Meta: class Meta:
ordering = ('RFC',) ordering = ('RFC',)
abstract =True

View File

@@ -1,7 +1,7 @@
import requests import requests
from asgiref.sync import sync_to_async from asgiref.sync import sync_to_async
from .models import saldoModel from .models import saldoModel
#from django.urls import reverse import datetime
async def req(): async def req():
results = await sync_to_async(get_saldo, thread_sensitive=True) results = await sync_to_async(get_saldo, thread_sensitive=True)
@@ -10,12 +10,15 @@ def get_saldo(request):
try: try:
Saldo = saldoModel.objects.first() Saldo = saldoModel.objects.first()
except: except:
Saldo = saldoModel.objects.create(saldo=1) pass
if not Saldo : if not Saldo :
Saldo = saldoModel.objects.create(saldo=1) Saldo = saldoModel.objects.create(saldo=1)
Saldo.save() Saldo.save()
#print( reverse('saldo_funct') )
#r = requests.get('https://app2.comercio-digital.mx/x3/saldo?usr=SCT050708AD1&pwd=0dcu2SwCv',verify=False) #r = requests.get('https://app2.comercio-digital.mx/x3/saldo?usr=SCT050708AD1&pwd=0dcu2SwCv',verify=False)
return {'saldo':Saldo} return {
'saldo':Saldo,
'fecha': datetime.date.today()
}

View File

@@ -1,9 +1,8 @@
from django.db.models.signals import post_save from django.db.models.signals import post_save
from django.dispatch import receiver from django.dispatch import receiver
from .saldo_context_proc import get_saldo from .models import Clientes
#@receiver(post_save, sender=saldoModel) #@receiver(post_save, sender=saldoModel)
def save_saldo(sender,instance,**kwargs): def save_Cliente(sender,instance,**kwargs):
pass obj, created = Clientes.objects.get_or_create(RFC=instance.rfcc)
#print('----save_saldo') if created:
#get_saldo() print(f'----signal se creo cliente {obj.RFC}')
#print(sender,instance.saldo,kwargs)

View File

@@ -2,33 +2,34 @@ from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from django.http import JsonResponse from django.http import JsonResponse
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from .models import Timbres,saldoModel from .models import Clientes,Timbres,saldoModel,ErroresTimbres
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.db.models import Q from django.db.models import Q
import datetime import datetime
@login_required @login_required
def index(request): def index(request):
timbres_list = Timbres.objects.values('rfcc').distinct() clientes_list = Clientes.objects.all()
page = request.GET.get('page', 1) page = request.GET.get('page', 1)
search = request.GET.get('search',None) search = request.GET.get('search',None)
rfcc = request.GET.get('rfcc', None) rfcc = request.GET.get('rfcc', None)
if rfcc: if rfcc:
timbres_list = Timbres.objects.filter(Q(rfcc__icontains=search)) clientes_list = Clientes.objects.filter(Q(RFC__icontains=search))
paginator = Paginator(timbres_list, 1) paginator = Paginator(clientes_list, 1)
try: try:
timbres = paginator.page(page) clientes = paginator.page(page)
except PageNotAnInteger: except PageNotAnInteger:
timbres = paginator.page(1) clientes = paginator.page(1)
except EmptyPage: except EmptyPage:
timbres = paginator.page(paginator.num_pages) clientes = paginator.page(paginator.num_pages)
context = { context = {
'timbres':timbres, 'clientes':clientes,
} }
return render(request,'Clientes/index.html',context) return render(request,'Clientes/index.html',context)
@@ -54,7 +55,12 @@ def add_timbre(request):
obj = Timbres.objects.create(**obj) obj = Timbres.objects.create(**obj)
return HttpResponse('ok') return HttpResponse('ok')
except Exception as e: except Exception as e:
obj = ErroresTimbres.objects.create(
uuid=uuid,
description=e,
rfcc=rfcc,
folio=folio
)
return HttpResponse(e) return HttpResponse(e)
@@ -68,6 +74,8 @@ def pageFunc(page,qs,per_page):
qs = paginator.page(paginator.num_pages) qs = paginator.page(paginator.num_pages)
return qs return qs
@login_required
def timbres_cliente(request, RFC): def timbres_cliente(request, RFC):
lista = Timbres.objects.filter(rfcc=RFC) lista = Timbres.objects.filter(rfcc=RFC)
@@ -103,7 +111,6 @@ def timbres_cliente(request, RFC):
} }
return render(request, 'Clientes/timbres_cliente.html', context) return render(request, 'Clientes/timbres_cliente.html', context)
def saldo_funct(request): def saldo_funct(request):
timbres=request.GET.get('num',None) timbres=request.GET.get('num',None)
try: try:

View File

@@ -24,17 +24,20 @@
<input id="table_rfcc" name="rfcc" value="True" type="checkbox" class="form-check-input" > <input id="table_rfcc" name="rfcc" value="True" type="checkbox" class="form-check-input" >
Cliente RFC Cliente RFC
</th> </th>
<th>Nombre</th>
<th>Totales Mes {{fecha|date:"F"}}</th>
<th scope="col">actions</th> <th scope="col">actions</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for obj in timbres %} {% for obj in clientes %}
<tr class=""> <tr class="">
<td>{{obj.rfcc}}</td> <td>{{obj.RFC}}</td>
<td>{{obj.Nombre}}</td>
<td>{{obj.timbres_mes_count}}</td>
<td> <td>
{% if request.user.is_staff %} {% if request.user.is_staff %}
<a href="{% url 'timbres_cliente' obj.rfcc %}" class="btn btn-info">View Timbres</a> <a href="{% url 'timbres_cliente' obj.RFC %}" class="btn btn-info">Ver Timbres</a>
{% endif %} {% endif %}
</td> </td>
</tr> </tr>
@@ -49,9 +52,6 @@
document.getElementById('rfcc').checked= table_rfcc.checked? true:false; document.getElementById('rfcc').checked= table_rfcc.checked? true:false;
}) })
</script> </script>
{% endblock scripts %} {% endblock scripts %}

View File

@@ -1,3 +1,7 @@
<span class="navbar-text mr-2">
Fecha: <strong>{{fecha|date:"d F Y"}}</strong>
</span>
<form action="{{request.path}}" method="get" class="form-inline my-2 my-lg-0"> <form action="{{request.path}}" method="get" class="form-inline my-2 my-lg-0">
<input id="search" class="form-control mr-sm-2" name="search" type="search" placeholder="Search" aria-label="Search"> <input id="search" class="form-control mr-sm-2" name="search" type="search" placeholder="Search" aria-label="Search">