diff --git a/sapl/materia/forms.py b/sapl/materia/forms.py index ff9b12d56..97e0ef9b4 100644 --- a/sapl/materia/forms.py +++ b/sapl/materia/forms.py @@ -1839,11 +1839,7 @@ class ConfirmarProposicaoForm(ProposicaoForm): protocolo = Protocolo() protocolo.numero = (nm['numero__max'] + 1) if nm['numero__max'] else 1 protocolo.ano = timezone.now().year - protocolo.data = timezone.now() - protocolo.hora = timezone.now().time() - # TODO transformar campo timestamp em auto_now_add - protocolo.timestamp = timezone.now() protocolo.tipo_protocolo = '1' protocolo.interessado = str(proposicao.autor) diff --git a/sapl/protocoloadm/migrations/0005_auto_20180824_1241.py b/sapl/protocoloadm/migrations/0005_auto_20180824_1241.py new file mode 100644 index 000000000..f18dd9717 --- /dev/null +++ b/sapl/protocoloadm/migrations/0005_auto_20180824_1241.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.13 on 2018-08-24 15:41 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('protocoloadm', '0004_documentoadministrativo_numero_externo'), + ] + + operations = [ + migrations.AlterField( + model_name='protocolo', + name='data', + field=models.DateField(blank=True, null=True), + ), + migrations.AlterField( + model_name='protocolo', + name='hora', + field=models.TimeField(blank=True, null=True), + ), + migrations.AlterField( + model_name='protocolo', + name='timestamp', + field=models.DateTimeField(default=django.utils.timezone.now), + ), + ] diff --git a/sapl/protocoloadm/models.py b/sapl/protocoloadm/models.py index 33ceade8c..1fd38e720 100644 --- a/sapl/protocoloadm/models.py +++ b/sapl/protocoloadm/models.py @@ -1,5 +1,6 @@ import reversion from django.db import models +from django.utils import timezone from django.utils.translation import ugettext_lazy as _ from model_utils import Choices @@ -57,10 +58,11 @@ class Protocolo(models.Model): verbose_name=_('Ano do Protocolo')) # TODO: Remover esses dois campos após migração, # TODO: pois timestamp supre a necessidade - data = models.DateField() - hora = models.TimeField() - # TODO transformar campo timestamp em auto_now_add - timestamp = models.DateTimeField() + data = models.DateField(null=True, blank=True) + hora = models.TimeField(null=True, blank=True) + # Não foi utilizado auto_now_add=True em timestamp porque + # ele usa datetime.now que não é timezone aware. + timestamp = models.DateTimeField(default=timezone.now) tipo_protocolo = models.PositiveIntegerField( blank=True, null=True, verbose_name=_('Tipo de Protocolo')) tipo_processo = models.PositiveIntegerField() diff --git a/sapl/protocoloadm/views.py b/sapl/protocoloadm/views.py index 824bd1664..21dc60a52 100644 --- a/sapl/protocoloadm/views.py +++ b/sapl/protocoloadm/views.py @@ -333,9 +333,6 @@ class ProtocoloDocumentoView(PermissionRequiredMixin, messages.add_message(self.request, messages.ERROR, msg) return self.render_to_response(self.get_context_data()) protocolo.ano = timezone.now().year - protocolo.data = timezone.now() - protocolo.hora = timezone.now().time() - protocolo.timestamp = timezone.now() protocolo.assunto_ementa = self.request.POST['assunto'] protocolo.save() @@ -419,10 +416,14 @@ class ComprovanteProtocoloView(PermissionRequiredMixin, TemplateView): autenticacao = _("** NULO **") if not protocolo.anulado: + if protocolo.timestamp: + data = protocolo.timestamp.strftime("%Y/%m/%d") + else: + data = protocolo.data.strftime("%Y/%m/%d") + # data is not i18n sensitive 'Y-m-d' is the right format. autenticacao = str(protocolo.tipo_processo) + \ - protocolo.data.strftime("%Y/%m/%d") + \ - str(protocolo.numero).zfill(6) + data + str(protocolo.numero).zfill(6) context.update({"protocolo": protocolo, "barcode": barcode, @@ -479,9 +480,6 @@ class ProtocoloMateriaView(PermissionRequiredMixin, CreateView): messages.add_message(self.request, messages.ERROR, msg) return self.render_to_response(self.get_context_data()) protocolo.ano = timezone.now().year - protocolo.data = timezone.now().date() - protocolo.hora = timezone.now().time() - protocolo.timestamp = timezone.now() protocolo.tipo_protocolo = 0 protocolo.tipo_processo = '1' # TODO validar o significado diff --git a/sapl/relatorios/views.py b/sapl/relatorios/views.py index 57752753e..50aa9c44d 100644 --- a/sapl/relatorios/views.py +++ b/sapl/relatorios/views.py @@ -827,9 +827,12 @@ def get_protocolos(prots): dic['titulo'] = str(protocolo.numero) + '/' + str(protocolo.ano) ts = timezone.localtime(protocolo.timestamp) - - dic['data'] = ts.strftime("%d/%m/%Y") + ' - Horário:' + \ - ts.strftime("%H:%m") + if protocolo.timestamp: + dic['data'] = ts.strftime("%d/%m/%Y") + ' - Horário:' + \ + ts.strftime("%H:%m") + else: + dic['data'] = protocolo.data.strftime("%d/%m/%Y") + ' - Horário:' \ + + protocolo.hora.strftime("%H:%m") dic['txt_assunto'] = protocolo.assunto_ementa @@ -941,9 +944,12 @@ def get_etiqueta_protocolos(prots): dic['titulo'] = str(p.numero) + '/' + str(p.ano) tz_hora = timezone.localtime(p.timestamp) - - dic['data'] = 'Data: ' + tz_hora.strftime( - "%d/%m/%Y") + ' - Horário: ' + tz_hora.strftime("%H:%M") + if p.timestamp: + dic['data'] = 'Data: ' + tz_hora.strftime( + "%d/%m/%Y") + ' - Horário: ' + tz_hora.strftime("%H:%M") + else: + dic['data'] = 'Data: ' + p.data.strftime( + "%d/%m/%Y") + ' - Horário: ' + p.hora.strftime("%H:%M") dic['txt_assunto'] = p.assunto_ementa dic['txt_interessado'] = p.interessado diff --git a/sapl/templates/protocoloadm/comprovante.html b/sapl/templates/protocoloadm/comprovante.html index f4ec4cc62..795eecb9c 100644 --- a/sapl/templates/protocoloadm/comprovante.html +++ b/sapl/templates/protocoloadm/comprovante.html @@ -59,7 +59,7 @@