From bf7c3b1b86929b03b51422e5274d567be0f0d5f4 Mon Sep 17 00:00:00 2001 From: Luciano Almeida Date: Wed, 2 Aug 2017 15:51:00 -0300 Subject: [PATCH] =?UTF-8?q?Ajusta=20rela=C3=A7=C3=A3o=20e=20cria=C3=A7?= =?UTF-8?q?=C3=A3o=20de=20protocolos=20inexistentes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Luciano Almeida --- sapl/legacy/migration.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/sapl/legacy/migration.py b/sapl/legacy/migration.py index 61de0854e..8878d3522 100644 --- a/sapl/legacy/migration.py +++ b/sapl/legacy/migration.py @@ -655,9 +655,27 @@ def adjust_acompanhamentomateria(new, old): def adjust_documentoadministrativo(new, old): if new.numero_protocolo: - protocolo = Protocolo.objects.get(numero=new.numero_protocolo, - ano=new.ano) - new.protocolo = protocolo + try: + protocolo = Protocolo.objects.get(numero=new.numero_protocolo, + ano=new.ano) + new.protocolo = protocolo + except Exception: + try: + protocolo = Protocolo.objects.get(numero=new.numero_protocolo, + ano=new.ano+1) + new.protocolo = protocolo + except Exception: + protocolo = mommy.make(Protocolo, numero=new.numero_protocolo, + ano=new.ano) + with reversion.create_revision(): + problema = 'Protocolo Vinculado [numero_protocolo=%s, '\ + 'ano=%s] não existe' % (new.numero_protocolo, + new.ano) + descricao = 'O protocolo inexistente foi criado' + warn(problema + ' => ' + descricao) + save_relation(obj=protocolo, problema=problema, + descricao=descricao, eh_stub=True) + reversion.set_comment('Protocolo não existia.') def adjust_mandato(new, old):