From 1955c527f693c93f3899ccf615807ad0e54cda03 Mon Sep 17 00:00:00 2001 From: Eliseu Egewarth Date: Tue, 8 Aug 2017 14:04:12 -0300 Subject: [PATCH] Fix #1342 (#1360) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix #1342 Signed-off-by: Eliseu Egewarth * Corrige erro de lógica Signed-off-by: Eliseu Egewarth --- sapl/protocoloadm/forms.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/sapl/protocoloadm/forms.py b/sapl/protocoloadm/forms.py index c8880960c..a3b71e998 100644 --- a/sapl/protocoloadm/forms.py +++ b/sapl/protocoloadm/forms.py @@ -12,7 +12,7 @@ from django.utils.translation import ugettext_lazy as _ from sapl.base.models import Autor from sapl.crispy_layout_mixin import form_actions, to_row -from sapl.materia.models import TipoMateriaLegislativa, UnidadeTramitacao +from sapl.materia.models import MateriaLegislativa, TipoMateriaLegislativa, UnidadeTramitacao from sapl.utils import (RANGE_ANOS, AnoNumeroOrderingFilter, RangeWidgetOverride, autor_label, autor_modal) @@ -233,7 +233,18 @@ class AnularProcoloAdmForm(ModelForm): except ObjectDoesNotExist: raise forms.ValidationError( _("Protocolo %s/%s não existe" % (numero, ano))) - + exists = False + if protocolo.tipo_materia: + exists = MateriaLegislativa.objects.filter( + numero_protocolo=protocolo.numero, ano=protocolo.ano).exists() + elif protocolo.tipo_documento: + exists = protocolo.documentoadministrativo_set.all( + ).order_by('-ano', '-numero').exists() + + if exists: + raise forms.ValidationError( + _("Protocolo %s/%s não pode ser removido pois existem" + "documentos vinculados a ele." % (numero, ano))) class Meta: model = Protocolo fields = ['numero',