From 3eaeedc5133b4ac23cf98586aa142a01b973e9f3 Mon Sep 17 00:00:00 2001 From: Edward Date: Mon, 18 Feb 2019 15:42:50 -0300 Subject: [PATCH] =?UTF-8?q?Coloca=20data/hora=20de=20protocolo=20como=20co?= =?UTF-8?q?nfigur=C3=A1vel=20(#2504)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Coloca data/hora de protocolo como configurável * Conserta testes --- sapl/base/forms.py | 1 + .../0030_appconfig_protocolo_manual.py | 20 ++++++++++ .../migrations/0031_auto_20190218_1109.py | 20 ++++++++++ sapl/base/models.py | 4 ++ sapl/protocoloadm/forms.py | 40 ++++++++++++++----- sapl/protocoloadm/tests/test_protocoloadm.py | 7 ++++ sapl/templates/base/layouts.yaml | 2 +- 7 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 sapl/base/migrations/0030_appconfig_protocolo_manual.py create mode 100644 sapl/base/migrations/0031_auto_20190218_1109.py diff --git a/sapl/base/forms.py b/sapl/base/forms.py index 3476ac09d..afc2466fb 100644 --- a/sapl/base/forms.py +++ b/sapl/base/forms.py @@ -1155,6 +1155,7 @@ class ConfiguracoesAppForm(ModelForm): 'texto_articulado_materia', 'texto_articulado_norma', 'proposicao_incorporacao_obrigatoria', + 'protocolo_manual', 'cronometro_discurso', 'cronometro_aparte', 'cronometro_ordem', diff --git a/sapl/base/migrations/0030_appconfig_protocolo_manual.py b/sapl/base/migrations/0030_appconfig_protocolo_manual.py new file mode 100644 index 000000000..7782f974d --- /dev/null +++ b/sapl/base/migrations/0030_appconfig_protocolo_manual.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.20 on 2019-02-15 18:25 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('base', '0029_remove_appconfig_relatorios_atos'), + ] + + operations = [ + migrations.AddField( + model_name='appconfig', + name='protocolo_manual', + field=models.BooleanField(choices=[(True, 'Sim'), (False, 'Não')], default=False, verbose_name='Protocolar proposição somente com recibo?'), + ), + ] diff --git a/sapl/base/migrations/0031_auto_20190218_1109.py b/sapl/base/migrations/0031_auto_20190218_1109.py new file mode 100644 index 000000000..a87922a83 --- /dev/null +++ b/sapl/base/migrations/0031_auto_20190218_1109.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.20 on 2019-02-18 14:09 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('base', '0030_appconfig_protocolo_manual'), + ] + + operations = [ + migrations.AlterField( + model_name='appconfig', + name='protocolo_manual', + field=models.BooleanField(choices=[(True, 'Sim'), (False, 'Não')], default=False, verbose_name='Informar data e hora de protocolo?'), + ), + ] diff --git a/sapl/base/models.py b/sapl/base/models.py index 55792b147..2e42ce28e 100644 --- a/sapl/base/models.py +++ b/sapl/base/models.py @@ -160,6 +160,10 @@ class AppConfig(models.Model): verbose_name=_('Protocolar proposição somente com recibo?'), choices=YES_NO_CHOICES, default=True) + protocolo_manual = models.BooleanField( + verbose_name=_('Informar data e hora de protocolo?'), + choices=YES_NO_CHOICES, default=False) + class Meta: verbose_name = _('Configurações da Aplicação') verbose_name_plural = _('Configurações da Aplicação') diff --git a/sapl/protocoloadm/forms.py b/sapl/protocoloadm/forms.py index d358a9d8c..e49b8185f 100644 --- a/sapl/protocoloadm/forms.py +++ b/sapl/protocoloadm/forms.py @@ -14,7 +14,7 @@ from django.utils import timezone from django.utils.translation import ugettext_lazy as _ import django_filters -from sapl.base.models import Autor, TipoAutor +from sapl.base.models import Autor, TipoAutor, AppConfig from sapl.crispy_layout_mixin import SaplFormLayout, form_actions, to_row from sapl.materia.models import (MateriaLegislativa, TipoMateriaLegislativa, UnidadeTramitacao) @@ -404,14 +404,21 @@ class ProtocoloDocumentForm(ModelForm): row7 = to_row( [('numero', 12)]) - self.helper = SaplFormHelper() + fieldset = Fieldset(_('Protocolo com data e hora informados manualmente'), + row3, + css_id='protocolo_data_hora_manual') + + config = AppConfig.objects.first() + if not config.protocolo_manual: + row3 = to_row([(HTML(" "), 12)]) + fieldset = row3 + + self.helper = FormHelper() self.helper.layout = Layout( Fieldset(_('Identificação de Documento'), row1, row2), - Fieldset(_('Protocolo com data e hora informados manualmente'), - row3, - css_id='protocolo_data_hora_manual'), + fieldset, row4, row5, HTML(" "), @@ -425,6 +432,10 @@ class ProtocoloDocumentForm(ModelForm): super(ProtocoloDocumentForm, self).__init__( *args, **kwargs) + if not config.protocolo_manual: + self.fields['data_hora_manual'].widget = forms.HiddenInput() + + class ProtocoloMateriaForm(ModelForm): @@ -583,14 +594,22 @@ class ProtocoloMateriaForm(ModelForm): row6 = to_row( [('numero', 12)]) - self.helper = SaplFormHelper() + fieldset = Fieldset(_('Protocolo com data e hora informados manualmente'), + row3, + css_id='protocolo_data_hora_manual') + + config = AppConfig.objects.first() + if not config.protocolo_manual: + row3 = to_row([(HTML(" "), 12)]) + fieldset = row3 + + + self.helper = FormHelper() self.helper.layout = Layout( Fieldset(_('Identificação da Matéria'), row1, row2), - Fieldset(_('Protocolo com data e hora informados manualmente'), - row3, - css_id='protocolo_data_hora_manual'), + fieldset, row4, row5, HTML(" "), @@ -604,6 +623,9 @@ class ProtocoloMateriaForm(ModelForm): super(ProtocoloMateriaForm, self).__init__( *args, **kwargs) + if not config.protocolo_manual: + self.fields['data_hora_manual'].widget = forms.HiddenInput() + class DocumentoAcessorioAdministrativoForm(ModelForm): diff --git a/sapl/protocoloadm/tests/test_protocoloadm.py b/sapl/protocoloadm/tests/test_protocoloadm.py index c7e4bc341..0e43aebbe 100644 --- a/sapl/protocoloadm/tests/test_protocoloadm.py +++ b/sapl/protocoloadm/tests/test_protocoloadm.py @@ -7,6 +7,7 @@ from django.utils.translation import ugettext_lazy as _ from model_mommy import mommy import pytest +from sapl.base.models import AppConfig from sapl.materia.models import UnidadeTramitacao from sapl.protocoloadm.forms import (AnularProcoloAdmForm, DocumentoAdministrativoForm, @@ -390,8 +391,11 @@ def test_documento_administrativo_protocolo_inexistente(): assert form.errors['__all__'] == [_('Protocolo 11/2017 inexistente.')] +@pytest.mark.django_db(transaction=False) def test_protocolo_documento_form_invalido(): + config = mommy.make(AppConfig) + form = ProtocoloDocumentForm( data={}, initial={ @@ -414,8 +418,11 @@ def test_protocolo_documento_form_invalido(): assert len(errors) == 6 +@pytest.mark.django_db(transaction=False) def test_protocolo_materia_invalido(): + config = mommy.make(AppConfig) + form = ProtocoloMateriaForm(data={}, initial={ 'user_data_hora_manual': '', diff --git a/sapl/templates/base/layouts.yaml b/sapl/templates/base/layouts.yaml index 4f6bbd45d..d83239e63 100644 --- a/sapl/templates/base/layouts.yaml +++ b/sapl/templates/base/layouts.yaml @@ -18,7 +18,7 @@ AppConfig: - esfera_federacao {% trans 'Proposições e Protocolo' %}: - - sequencia_numeracao proposicao_incorporacao_obrigatoria receber_recibo_proposicao + - sequencia_numeracao proposicao_incorporacao_obrigatoria receber_recibo_proposicao protocolo_manual {% trans 'Textos Articulados' %}: - texto_articulado_proposicao texto_articulado_materia texto_articulado_norma