Controle de faturas e bloqueio de usuários para o sistema de lojas web
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

29 lines
1.0 KiB

from datetime import datetime
from django.contrib.admin.models import LogEntry, ContentType, CHANGE
# from django.contrib.contenttypes.models import ContentType
from controle.models import Boleto, Cliente
from django.db.models import Count
def my_cron_job():
print('my cron job is working!')
def check_boletos_vencidos_cron_job():
boletos = Boleto.objects.filter(situacao='A', data_vencimento__lt=datetime.today(
).date()).values('cliente_id').annotate(ccount=Count('cliente')).order_by()
for boleto in boletos:
cliente = Cliente.objects.get(pk=boleto['cliente_id'])
cliente.situacao = 'A'
cliente.save()
print(f'cliente {cliente} atualizado')
LogEntry.objects.log_action(
user_id=1,
content_type_id=ContentType.objects.get_for_model(
cliente, False).pk,
object_id=cliente.pk,
object_repr=str(cliente),
action_flag=CHANGE,
change_message='Situação atualizada para ATRASADO pelo cronjob.'
)