From b1d7e5034679b41ee9c92e3eb2d2a70a41a8072e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Mon, 6 Dec 2021 12:37:33 -0300 Subject: [PATCH] Fixes #94 --- sigi/apps/convenios/admin.py | 14 +++++++++++-- .../0017_convenio_id_contrato_gescon.py | 20 +++++++++++++++++++ sigi/apps/convenios/models.py | 17 ++++++++++++++-- 3 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 sigi/apps/convenios/migrations/0017_convenio_id_contrato_gescon.py diff --git a/sigi/apps/convenios/admin.py b/sigi/apps/convenios/admin.py index 328f46f..368f8f8 100644 --- a/sigi/apps/convenios/admin.py +++ b/sigi/apps/convenios/admin.py @@ -62,10 +62,10 @@ class ConvenioAdmin(BaseModelAdmin): 'data_pub_diario',)} ), (_(u'Gescon'), - {'fields': ('atualizacao_gescon', 'observacao_gescon',)} + {'fields': ('atualizacao_gescon', 'observacao_gescon', 'link_gescon')} ), ) - readonly_fields = ('data_sigi', 'atualizacao_gescon', 'observacao_gescon',) + readonly_fields = ('data_sigi', 'atualizacao_gescon', 'observacao_gescon', 'link_gescon') actions = ['adicionar_convenios'] inlines = (AnexosInline,) list_display = ('num_convenio', 'casa_legislativa', 'get_uf', @@ -115,6 +115,16 @@ class ConvenioAdmin(BaseModelAdmin): link_sigad.short_description = _("Processo no Senado") link_sigad.allow_tags = True + def link_gescon(self, obj): + if not obj.id_contrato_gescon: + return u"" + return ( + u"https://adm.senado.gov.br/" + u"gestao-contratos/api/{id}").format(id=obj.id_contrato_gescon) + link_gescon.short_description = _("Download PDF do Gescon") + link_gescon.allow_tags = True + def changelist_view(self, request, extra_context=None): from sigi.apps.convenios.views import normaliza_data request.GET._mutable = True diff --git a/sigi/apps/convenios/migrations/0017_convenio_id_contrato_gescon.py b/sigi/apps/convenios/migrations/0017_convenio_id_contrato_gescon.py new file mode 100644 index 0000000..83bddab --- /dev/null +++ b/sigi/apps/convenios/migrations/0017_convenio_id_contrato_gescon.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('convenios', '0016_auto_20210909_0732'), + ] + + operations = [ + migrations.AddField( + model_name='convenio', + name='id_contrato_gescon', + field=models.CharField(default=b'', verbose_name='ID do contrato no Gescon', max_length=20, editable=False, blank=True), + preserve_default=True, + ), + ] diff --git a/sigi/apps/convenios/models.py b/sigi/apps/convenios/models.py index cabc724..39eeeac 100644 --- a/sigi/apps/convenios/models.py +++ b/sigi/apps/convenios/models.py @@ -71,6 +71,13 @@ class Convenio(models.Model): max_length=10, blank=True ) + id_contrato_gescon = models.CharField( + _(u"ID do contrato no Gescon"), + max_length=20, + blank=True, + default="", + editable=False + ) data_sigi = models.DateField( _(u"data de cadastro no SIGI"), blank=True, @@ -504,7 +511,7 @@ class Gescon(models.Model): self.add_message( _(u"\tErro ao acessar {url}: {errmsg}").format( url=url, - errmsg=str(e) + errmsg=e.message.decode("utf8") ) ) continue @@ -734,6 +741,12 @@ class Gescon(models.Model): 'terminoVigencia' ] convenio.data_pub_diario = contrato['publicacao'] + if contrato['codTextoContrato']: + convenio.id_contrato_gescon = contrato[ + 'codTextoContrato' + ] + else: + convenio.id_contrato_gescon = "" try: convenio.save() @@ -748,7 +761,7 @@ class Gescon(models.Model): convenio._meta.model_name), args=[convenio.id] ), - errmsg=str(e) + errmsg=e.message.decode("utf8") ) ) erros += 1