Browse Source

Fix #615960 (OSTicket) (#2893)

* Adicionar migração - deduplica protocolos

* Fixes #615960 (OSTicket)

* Corrigir erros

* Refatoração

* Adicionar correção
pull/2965/head
João Rodrigues 5 years ago
committed by Edward
parent
commit
b230416a5a
  1. 26
      sapl/base/tests/test_view_base.py
  2. 12
      sapl/base/views.py
  3. 4
      sapl/protocoloadm/forms.py
  4. 25
      sapl/protocoloadm/migrations/0022_deduplica_protocolos.py
  5. 19
      sapl/protocoloadm/migrations/0023_auto_20190711_1755.py
  6. 16
      sapl/protocoloadm/migrations/0024_merge_20190821_1418.py
  7. 1
      sapl/protocoloadm/models.py
  8. 8
      sapl/templates/base/protocolos_duplicados.html

26
sapl/base/tests/test_view_base.py

@ -24,32 +24,6 @@ from sapl.base.views import (protocolos_duplicados, protocolos_com_materias,
bancada_comissao_autor_externo, anexados_ciclicos)
@pytest.mark.django_db(transaction=False)
def test_lista_protocolos_duplicados():
mommy.make(
Protocolo,
numero=15,
ano=2031
)
mommy.make(
Protocolo,
numero=15,
ano=2031
)
mommy.make(
Protocolo,
numero=33,
ano=2033
)
lista_protocolos_duplicados = protocolos_duplicados()
assert len(lista_protocolos_duplicados) == 1
assert lista_protocolos_duplicados[0][1] == 2
assert lista_protocolos_duplicados[0][0].numero == 15
assert lista_protocolos_duplicados[0][0].ano == 2031
@pytest.mark.django_db(transaction=False)
def test_lista_protocolos_com_materias():
mommy.make(

12
sapl/base/views.py

@ -1653,14 +1653,10 @@ class ListarProtocolosComMateriasView(PermissionRequiredMixin, ListView):
def protocolos_duplicados():
protocolos = {}
for p in Protocolo.objects.order_by('-ano', 'numero'):
key = "{}/{}".format(p.numero, p.ano)
val = protocolos.get(key, list())
val.append(p)
protocolos[key] = val
return [(v[0], len(v)) for (k, v) in protocolos.items() if len(v) > 1]
return [
protocolo for protocolo in Protocolo.objects.values(
'numero', 'ano').order_by('-ano', 'numero').annotate(total=Count('numero')).filter(total__gt=1)
]
class ListarProtocolosDuplicadosView(PermissionRequiredMixin, ListView):

4
sapl/protocoloadm/forms.py

@ -302,9 +302,7 @@ class AnularProtocoloAdmForm(ModelForm):
class Meta:
model = Protocolo
fields = ['numero',
'ano',
'justificativa_anulacao',
fields = ['justificativa_anulacao',
'anulado',
'user_anulacao',
'ip_anulacao',

25
sapl/protocoloadm/migrations/0022_deduplica_protocolos.py

@ -0,0 +1,25 @@
from __future__ import unicode_literals
from django.db import migrations
def deduplica_protocolos(apps, schema_editor):
from sapl.base.views import protocolos_duplicados
Protocolo = apps.get_model('protocoloadm', 'Protocolo')
protocolos = protocolos_duplicados()
for protocolo in protocolos:
protocolo_principal = Protocolo.objects.filter(numero=protocolo['numero'], ano=protocolo['ano']).order_by('-id')[0]
Protocolo.objects.filter(numero=protocolo['numero'], ano=protocolo['ano']).exclude(id=protocolo_principal.id).delete()
class Migration(migrations.Migration):
dependencies = [
('protocoloadm', '0021_merge_20190429_1531'),
]
operations = [
migrations.RunPython(deduplica_protocolos)
]

19
sapl/protocoloadm/migrations/0023_auto_20190711_1755.py

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-07-11 20:55
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('protocoloadm', '0022_deduplica_protocolos'),
]
operations = [
migrations.AlterUniqueTogether(
name='protocolo',
unique_together=set([('numero', 'ano')]),
),
]

16
sapl/protocoloadm/migrations/0024_merge_20190821_1418.py

@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-08-21 17:18
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('protocoloadm', '0023_auto_20190711_1755'),
('protocoloadm', '0023_merge_20190802_1112'),
]
operations = [
]

1
sapl/protocoloadm/models.py

@ -120,6 +120,7 @@ class Protocolo(models.Model):
permissions = (
('action_anular_protocolo', _('Permissão para Anular Protocolo')),
)
unique_together = ('numero', 'ano',)
def __str__(self):
return _('%(numero)s/%(ano)s') % {

8
sapl/templates/base/protocolos_duplicados.html

@ -15,12 +15,14 @@
</tr>
</thead>
<tbody>
{% for protocolo, quantidade in protocolos_duplicados %}
{% for protocolo in protocolos_duplicados %}
<tr>
<td>
<a href="{% url 'sapl.protocoloadm:protocolo' %}?numero={{ protocolo.numero }}&ano={{ protocolo.ano }}">{{ protocolo }}</a>
<a href="{% url 'sapl.protocoloadm:protocolo' %}?numero={{ protocolo.numero }}&ano={{ protocolo.ano }}">
{{ protocolo.numero }}/{{ protocolo.ano }}
</a>
</td>
<td>{{ quantidade }}</td>
<td>{{ protocolo.total }}</td>
</tr>
{% endfor %}
</tbody>

Loading…
Cancel
Save