From 52cb5f9ad3c16a9383f46bd607a0da663276b0e4 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Mon, 9 Oct 2017 13:56:37 -0300 Subject: [PATCH] Fix #1058 redundancia doc adm v2 (#1510) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Inicia refatoração * Inicia a resolução da issue * Remove ipdb --- sapl/protocoloadm/forms.py | 20 ++++++++++++++----- ...ocumentoadministrativo_numero_protocolo.py | 19 ++++++++++++++++++ sapl/protocoloadm/models.py | 3 +-- sapl/protocoloadm/views.py | 2 +- sapl/relatorios/views.py | 2 +- 5 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 sapl/protocoloadm/migrations/0002_remove_documentoadministrativo_numero_protocolo.py diff --git a/sapl/protocoloadm/forms.py b/sapl/protocoloadm/forms.py index 692a2c4f2..e3874181f 100644 --- a/sapl/protocoloadm/forms.py +++ b/sapl/protocoloadm/forms.py @@ -4,7 +4,8 @@ from crispy_forms.bootstrap import InlineRadios from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Button, Fieldset, Layout from django import forms -from django.core.exceptions import ObjectDoesNotExist, ValidationError +from django.core.exceptions import (MultipleObjectsReturned, + ObjectDoesNotExist, ValidationError) from django.db import models from django.forms import ModelForm from django.utils import timezone @@ -153,7 +154,7 @@ class DocumentoAdministrativoFilterSet(django_filters.FilterSet): model = DocumentoAdministrativo fields = ['tipo', 'numero', - 'numero_protocolo', + 'protocolo__numero', 'data', 'tramitacaoadministrativo__unidade_tramitacao_destino', 'tramitacaoadministrativo__status'] @@ -172,7 +173,7 @@ class DocumentoAdministrativoFilterSet(django_filters.FilterSet): row2 = to_row( [('ano', 4), - ('numero_protocolo', 4), + ('protocolo__numero', 4), ('data', 4)]) row3 = to_row( @@ -549,6 +550,10 @@ class DocumentoAdministrativoForm(ModelForm): widget=forms.Select( attrs={'class': 'selector'})) + numero_protocolo = forms.IntegerField(required=False, + label=Protocolo._meta. + get_field('numero').verbose_name) + class Meta: model = DocumentoAdministrativo fields = ['tipo', @@ -577,8 +582,8 @@ class DocumentoAdministrativoForm(ModelForm): if not self.is_valid(): return cleaned_data - numero_protocolo = cleaned_data['numero_protocolo'] - ano_protocolo = cleaned_data['ano_protocolo'] + numero_protocolo = self.data['numero_protocolo'] + ano_protocolo = self.data['ano_protocolo'] # campos opcionais, mas que se informados devem ser válidos if numero_protocolo and ano_protocolo: @@ -590,6 +595,11 @@ class DocumentoAdministrativoForm(ModelForm): msg = _('Protocolo %s/%s inexistente.' % ( numero_protocolo, ano_protocolo)) raise ValidationError(msg) + except MultipleObjectsReturned: + msg = _( + 'Existe mais de um Protocolo com este ano e número.' % ( + numero_protocolo, ano_protocolo)) + raise ValidationError(msg) return self.cleaned_data diff --git a/sapl/protocoloadm/migrations/0002_remove_documentoadministrativo_numero_protocolo.py b/sapl/protocoloadm/migrations/0002_remove_documentoadministrativo_numero_protocolo.py new file mode 100644 index 000000000..de12f4139 --- /dev/null +++ b/sapl/protocoloadm/migrations/0002_remove_documentoadministrativo_numero_protocolo.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.3 on 2017-09-20 21:52 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('protocoloadm', '0001_initial'), + ] + + operations = [ + migrations.RemoveField( + model_name='documentoadministrativo', + name='numero_protocolo', + ), + ] diff --git a/sapl/protocoloadm/models.py b/sapl/protocoloadm/models.py index 6294399f8..d4d45b3ad 100644 --- a/sapl/protocoloadm/models.py +++ b/sapl/protocoloadm/models.py @@ -120,8 +120,7 @@ class DocumentoAdministrativo(models.Model): on_delete=models.PROTECT, verbose_name=_('Protocolo')) data = models.DateField(verbose_name=_('Data')) - numero_protocolo = models.PositiveIntegerField( - blank=True, null=True, verbose_name=_('Núm. Protocolo')) + interessado = models.CharField( max_length=50, blank=True, verbose_name=_('Interessado')) autor = models.ForeignKey(Autor, blank=True, null=True, diff --git a/sapl/protocoloadm/views.py b/sapl/protocoloadm/views.py index 348f79229..3384e4934 100644 --- a/sapl/protocoloadm/views.py +++ b/sapl/protocoloadm/views.py @@ -88,7 +88,7 @@ class DocumentoAdministrativoCrud(Crud): class BaseMixin(Crud.BaseMixin): list_field_names = ['tipo', 'numero', 'ano', 'data', - 'numero_protocolo', 'assunto', + 'protocolo__numero', 'assunto', 'interessado', 'tramitacao', 'texto_integral'] @property diff --git a/sapl/relatorios/views.py b/sapl/relatorios/views.py index 01a3b06b2..7719e6d2d 100644 --- a/sapl/relatorios/views.py +++ b/sapl/relatorios/views.py @@ -956,7 +956,7 @@ def get_etiqueta_protocolos(prots): dic['num_documento'] = '' for documento in DocumentoAdministrativo.objects.filter( - numero_protocolo=p.numero): + protocolo=p): dic['num_documento'] = str(documento) dic['ident_processo'] = dic['num_materia'] or dic['num_documento']