diff --git a/sapl/protocoloadm/views.py b/sapl/protocoloadm/views.py index 24e3ac080..4bd6abb8a 100755 --- a/sapl/protocoloadm/views.py +++ b/sapl/protocoloadm/views.py @@ -37,7 +37,7 @@ from sapl.protocoloadm.models import Protocolo from sapl.relatorios.views import relatorio_doc_administrativos from sapl.utils import (create_barcode, get_base_url, get_client_ip, get_mime_type_from_file_extension, lista_anexados, - show_results_filter_set, mail_service_configured) + show_results_filter_set, mail_service_configured, from_date_to_datetime_utc) from .forms import (AcompanhamentoDocumentoForm, AnularProtocoloAdmForm, DocumentoAcessorioAdministrativoForm, @@ -542,6 +542,7 @@ class ProtocoloDocumentoView(PermissionRequiredMixin, @transaction.atomic def form_valid(self, form): + import ipdb; ipdb.set_trace() protocolo = form.save(commit=False) username = self.request.user.username @@ -564,12 +565,24 @@ class ProtocoloDocumentoView(PermissionRequiredMixin, legislatura = Legislatura.objects.filter( data_inicio__year__lte=timezone.now().year, data_fim__year__gte=timezone.now().year).first() + data_inicio = legislatura.data_inicio data_fim = legislatura.data_fim + + data_inicio_utc = from_date_to_datetime_utc(data_inicio) + data_fim_utc = from_date_to_datetime_utc(data_fim) + numero = Protocolo.objects.filter( - data__gte=data_inicio, - data__lte=data_fim).aggregate( - Max('numero')) + Q(data__isnull=False, + data__gte=data_inicio, + data__lte=data_fim) | + Q(timestamp__isnull=False, + timestamp__gte=data_inicio_utc, + timestamp__lte=data_fim_utc) | + Q(timestamp_data_hora_manual__isnull=False, + timestamp_data_hora_manual__gte=data_inicio_utc, + timestamp_data_hora_manual__lte=data_fim_utc,)).\ + aggregate(Max('numero')) elif numeracao == 'U': numero = Protocolo.objects.all().aggregate(Max('numero')) diff --git a/sapl/utils.py b/sapl/utils.py index 6d53ef8c0..cc463b759 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -986,6 +986,21 @@ def lista_anexados(principal, isMateriaLegislativa=True): return anexados_total +def from_date_to_datetime_utc(data): + """ + + :param data: datetime.date + :return: datetime.timestamp com UTC + """ + import pytz + from datetime import datetime + + # from date to datetime + dt_unware = datetime.combine(data, datetime.min.time()) + dt_utc = pytz.utc.localize(dt_unware) + return dt_utc + + class OverwriteStorage(FileSystemStorage): ''' Solução derivada do gist: https://gist.github.com/fabiomontefuscolo/1584462