diff --git a/sapl/protocoloadm/forms.py b/sapl/protocoloadm/forms.py
index e85e9ecf2..19d9d9b81 100644
--- a/sapl/protocoloadm/forms.py
+++ b/sapl/protocoloadm/forms.py
@@ -757,3 +757,63 @@ class DocumentoAdministrativoForm(ModelForm):
row6, row7))
super(DocumentoAdministrativoForm, self).__init__(
*args, **kwargs)
+
+class DesvincularDocumentoForm(ModelForm):
+
+ numero = forms.CharField(required=True,
+ label=DocumentoAdministrativo._meta.
+ get_field('numero').verbose_name
+ )
+ ano = forms.ChoiceField(required=True,
+ label=DocumentoAdministrativo._meta.
+ get_field('ano').verbose_name,
+ choices=RANGE_ANOS,
+ widget=forms.Select(attrs={'class': 'selector'}))
+
+ def clean(self):
+ super(DesvincularDocumentoForm, self).clean()
+
+ cleaned_data = self.cleaned_data
+
+ if not self.is_valid():
+ return cleaned_data
+
+ numero = cleaned_data['numero']
+ ano = cleaned_data['ano']
+ tipo = cleaned_data['tipo']
+
+ try:
+ documento = DocumentoAdministrativo.objects.get(numero=numero, ano=ano, tipo=tipo)
+ if not documento.protocolo:
+ raise forms.ValidationError(
+ _("%s %s/%s não se encontra vinculado a nenhum protocolo" % (tipo, numero, ano)))
+ except ObjectDoesNotExist:
+ raise forms.ValidationError(
+ _("%s %s/%s não existe" % (tipo, numero, ano)))
+
+ return cleaned_data
+
+ class Meta:
+ model = DocumentoAdministrativo
+ fields = ['tipo',
+ 'numero',
+ 'ano',
+ ]
+
+ def __init__(self, *args, **kwargs):
+
+ row1 = to_row(
+ [('numero', 4),
+ ('ano', 4),
+ ('tipo', 4)])
+
+ self.helper = FormHelper()
+ self.helper.layout = Layout(
+ Fieldset(_('Identificação do Documento'),
+ row1,
+ HTML(" "),
+ form_actions(label='Desvincular')
+ )
+ )
+ super(DesvincularDocumentoForm, self).__init__(
+ *args, **kwargs)
\ No newline at end of file
diff --git a/sapl/protocoloadm/urls.py b/sapl/protocoloadm/urls.py
index 46fec9980..de5c79b58 100644
--- a/sapl/protocoloadm/urls.py
+++ b/sapl/protocoloadm/urls.py
@@ -15,7 +15,8 @@ from sapl.protocoloadm.views import (AnularProtocoloAdmView,
TipoDocumentoAdministrativoCrud,
TramitacaoAdmCrud,
atualizar_numero_documento,
- doc_texto_integral)
+ doc_texto_integral,
+ DesvincularDocumentoView)
from .apps import AppConfig
@@ -61,6 +62,8 @@ urlpatterns_protocolo = [
url(r'^protocoloadm/anular-protocolo',
AnularProtocoloAdmView.as_view(), name='anular_protocolo'),
+ url(r'^protocoloadm/desvincular-documento',
+ DesvincularDocumentoView.as_view(), name='desvincular_documento'),
url(r'^protocoloadm/protocolar-mat',
ProtocoloMateriaView.as_view(), name='protocolar_mat'),
diff --git a/sapl/protocoloadm/views.py b/sapl/protocoloadm/views.py
index 733b7388e..8aa51d814 100644
--- a/sapl/protocoloadm/views.py
+++ b/sapl/protocoloadm/views.py
@@ -30,7 +30,7 @@ from .forms import (AnularProcoloAdmForm, DocumentoAcessorioAdministrativoForm,
DocumentoAdministrativoFilterSet,
DocumentoAdministrativoForm, ProtocoloDocumentForm,
ProtocoloFilterSet, ProtocoloMateriaForm,
- TramitacaoAdmEditForm, TramitacaoAdmForm)
+ TramitacaoAdmEditForm, TramitacaoAdmForm, DesvincularDocumentoForm)
from .models import (DocumentoAcessorioAdministrativo, DocumentoAdministrativo,
StatusTramitacaoAdministrativo,
TipoDocumentoAdministrativo, TramitacaoAdministrativo)
@@ -721,3 +721,20 @@ def atualizar_numero_documento(request):
{'numero': 1, 'ano': ano})
return response
+
+class DesvincularDocumentoView(PermissionRequiredMixin, CreateView):
+ template_name = 'protocoloadm/anular_protocoloadm.html'
+ form_class = DesvincularDocumentoForm
+ form_valid_message = _('Documento desvinculado com sucesso!')
+ permission_required = ('protocoloadm.action_anular_protocolo', )
+
+ def get_success_url(self):
+ return reverse('sapl.protocoloadm:protocolo')
+
+ def form_valid(self, form):
+ documento = DocumentoAdministrativo.objects.get(numero=form.cleaned_data['numero'],
+ ano=form.cleaned_data['ano'],
+ tipo=form.cleaned_data['tipo'])
+ documento.protocolo = None
+ documento.save()
+ return redirect(self.get_success_url())
diff --git a/sapl/templates/protocoloadm/protocoloadm_detail.html b/sapl/templates/protocoloadm/protocoloadm_detail.html
index 5a3fe05d0..e9da072ec 100644
--- a/sapl/templates/protocoloadm/protocoloadm_detail.html
+++ b/sapl/templates/protocoloadm/protocoloadm_detail.html
@@ -5,5 +5,6 @@
{% trans 'Protocolar Matéria' %}
{% trans 'Protocolar Documento' %}
{% trans 'Anular Protocolo' %}
+ {% trans 'Desvincular Documentos' %}
{% endblock editions %}