Browse Source

HOT-FIX: corrige bug em protocolo por legislatura

pull/3029/head
Edward Ribeiro 5 years ago
parent
commit
658f261394
  1. 19
      sapl/protocoloadm/views.py
  2. 15
      sapl/utils.py

19
sapl/protocoloadm/views.py

@ -37,7 +37,7 @@ from sapl.protocoloadm.models import Protocolo
from sapl.relatorios.views import relatorio_doc_administrativos from sapl.relatorios.views import relatorio_doc_administrativos
from sapl.utils import (create_barcode, get_base_url, get_client_ip, from sapl.utils import (create_barcode, get_base_url, get_client_ip,
get_mime_type_from_file_extension, lista_anexados, 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, from .forms import (AcompanhamentoDocumentoForm, AnularProtocoloAdmForm,
DocumentoAcessorioAdministrativoForm, DocumentoAcessorioAdministrativoForm,
@ -542,6 +542,7 @@ class ProtocoloDocumentoView(PermissionRequiredMixin,
@transaction.atomic @transaction.atomic
def form_valid(self, form): def form_valid(self, form):
import ipdb; ipdb.set_trace()
protocolo = form.save(commit=False) protocolo = form.save(commit=False)
username = self.request.user.username username = self.request.user.username
@ -564,12 +565,24 @@ class ProtocoloDocumentoView(PermissionRequiredMixin,
legislatura = Legislatura.objects.filter( legislatura = Legislatura.objects.filter(
data_inicio__year__lte=timezone.now().year, data_inicio__year__lte=timezone.now().year,
data_fim__year__gte=timezone.now().year).first() data_fim__year__gte=timezone.now().year).first()
data_inicio = legislatura.data_inicio data_inicio = legislatura.data_inicio
data_fim = legislatura.data_fim 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( numero = Protocolo.objects.filter(
Q(data__isnull=False,
data__gte=data_inicio, data__gte=data_inicio,
data__lte=data_fim).aggregate( data__lte=data_fim) |
Max('numero')) 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': elif numeracao == 'U':
numero = Protocolo.objects.all().aggregate(Max('numero')) numero = Protocolo.objects.all().aggregate(Max('numero'))

15
sapl/utils.py

@ -986,6 +986,21 @@ def lista_anexados(principal, isMateriaLegislativa=True):
return anexados_total 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): class OverwriteStorage(FileSystemStorage):
''' '''
Solução derivada do gist: https://gist.github.com/fabiomontefuscolo/1584462 Solução derivada do gist: https://gist.github.com/fabiomontefuscolo/1584462

Loading…
Cancel
Save