From a0a45d10ac1adaa2ba40911dfc82d7a233bf3ad8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Tue, 31 Aug 2021 16:48:40 -0300 Subject: [PATCH] =?UTF-8?q?Remodelagem=20convenios=20-=20elima=20dura?= =?UTF-8?q?=C3=A7=C3=A3o=20e=20adiciona=20t=C3=A9rmino=20vig=C3=AAncia?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/apps/convenios/admin.py | 4 +- .../management/commands/duracao_act.py | 43 ------------------- .../0011_convenio_data_termino_vigencia.py | 20 +++++++++ .../migrations/0012_auto_20210831_0844.py | 38 ++++++++++++++++ .../0013_remove_convenio_duracao.py | 18 ++++++++ sigi/apps/convenios/models.py | 37 ++++------------ 6 files changed, 86 insertions(+), 74 deletions(-) delete mode 100644 sigi/apps/convenios/management/commands/duracao_act.py create mode 100644 sigi/apps/convenios/migrations/0011_convenio_data_termino_vigencia.py create mode 100644 sigi/apps/convenios/migrations/0012_auto_20210831_0844.py create mode 100644 sigi/apps/convenios/migrations/0013_remove_convenio_duracao.py diff --git a/sigi/apps/convenios/admin.py b/sigi/apps/convenios/admin.py index 55b5841..dcaa156 100644 --- a/sigi/apps/convenios/admin.py +++ b/sigi/apps/convenios/admin.py @@ -57,7 +57,7 @@ class ConvenioAdmin(BaseModelAdmin): {'fields': ('servico_gestao', 'servidor_gestao',)} ), (_(u'Datas'), - {'fields': ('data_retorno_assinatura', 'duracao', + {'fields': ('data_retorno_assinatura', 'data_termino_vigencia', 'data_pub_diario',)} ), ) @@ -66,7 +66,7 @@ class ConvenioAdmin(BaseModelAdmin): inlines = (AnexosInline,) list_display = ('num_convenio', 'casa_legislativa', 'get_uf', 'status_convenio', 'link_sigad', 'data_retorno_assinatura', - 'duracao', 'projeto',) + 'data_termino_vigencia', 'projeto',) list_display_links = ('num_convenio', 'casa_legislativa',) list_filter = (('casa_legislativa__gerentes_interlegis', GerentesInterlegisFilter), 'projeto', diff --git a/sigi/apps/convenios/management/commands/duracao_act.py b/sigi/apps/convenios/management/commands/duracao_act.py deleted file mode 100644 index 2144582..0000000 --- a/sigi/apps/convenios/management/commands/duracao_act.py +++ /dev/null @@ -1,43 +0,0 @@ -# -*- coding: utf-8 -*- -# -# sigi.apps.casas.management.commands.importa_gerentes -# -# Copyright (c) 2015 by Interlegis -# -# GNU General Public License (GPL) -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. -# - -from django.core.management.base import BaseCommand, CommandError -from sigi.apps.convenios.models import Projeto, Convenio - -class Command(BaseCommand): - help = u"""Define a duração de todos os ACT para 60 meses. - * A sigla do Projeto precisa ser ACT; - * O campo duracao precisa estar em branco. - """ - - def handle(self, *args, **options): - self.stdout.write(u"Atualizando ACTs... ") - act = Projeto.objects.get(sigla='ACT') - for conv in Convenio.objects.filter(projeto=act, duracao=None): - conv.duracao = 60 - conv.save() - self.stdout.write(u"\tACT {sigad} da Casa {casa} atualizado".format( - sigad=conv.num_processo_sf, casa=conv.casa_legislativa.nome - )) - self.stdout.write(u"Pronto!") diff --git a/sigi/apps/convenios/migrations/0011_convenio_data_termino_vigencia.py b/sigi/apps/convenios/migrations/0011_convenio_data_termino_vigencia.py new file mode 100644 index 0000000..c5065c1 --- /dev/null +++ b/sigi/apps/convenios/migrations/0011_convenio_data_termino_vigencia.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', '0010_auto_20210819_0833'), + ] + + operations = [ + migrations.AddField( + model_name='convenio', + name='data_termino_vigencia', + field=models.DateField(help_text='T\xe9rmino da vig\xeancia do conv\xeanio.', null=True, verbose_name='Data t\xe9rmino vig\xeancia', blank=True), + preserve_default=True, + ), + ] diff --git a/sigi/apps/convenios/migrations/0012_auto_20210831_0844.py b/sigi/apps/convenios/migrations/0012_auto_20210831_0844.py new file mode 100644 index 0000000..b4e2692 --- /dev/null +++ b/sigi/apps/convenios/migrations/0012_auto_20210831_0844.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals +from datetime import date +from django.db import models, migrations + +def migra_data_termino_vigencia(apps, schema_editor): + Convenio = apps.get_model('convenios', 'Convenio') + + for c in Convenio.objects.all(): + if (c.data_retorno_assinatura is None or c.duracao is None): + continue + + ano = c.data_retorno_assinatura.year + int(c.duracao / 12) + mes = int(c.data_retorno_assinatura.month + int(c.duracao % 12)) + if mes > 12: + ano = ano + 1 + mes = mes - 12 + dia = c.data_retorno_assinatura.day + + while True: + try: + data_fim = date(year=ano, month=mes,day=dia) + break + except: + dia = dia - 1 + + c.data_termino_vigencia = data_fim + c.save() + +class Migration(migrations.Migration): + + dependencies = [ + ('convenios', '0011_convenio_data_termino_vigencia'), + ] + + operations = [ + migrations.RunPython(migra_data_termino_vigencia), + ] diff --git a/sigi/apps/convenios/migrations/0013_remove_convenio_duracao.py b/sigi/apps/convenios/migrations/0013_remove_convenio_duracao.py new file mode 100644 index 0000000..bcc66bc --- /dev/null +++ b/sigi/apps/convenios/migrations/0013_remove_convenio_duracao.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('convenios', '0012_auto_20210831_0844'), + ] + + operations = [ + migrations.RemoveField( + model_name='convenio', + name='duracao', + ), + ] diff --git a/sigi/apps/convenios/models.py b/sigi/apps/convenios/models.py index a0dff36..59f00fa 100644 --- a/sigi/apps/convenios/models.py +++ b/sigi/apps/convenios/models.py @@ -15,10 +15,10 @@ class Projeto(models.Model): def __unicode__(self): return self.sigla - + class Meta: ordering = ('nome',) - + class StatusConvenio(models.Model): nome = models.CharField(max_length=100) cancela = models.BooleanField(_(u"Cancela o convênio"), default=False) @@ -135,12 +135,12 @@ class Convenio(models.Model): blank=True, help_text=_(u'Convênio firmado.') ) - duracao = models.PositiveIntegerField( - _(u"duração (meses)"), + data_termino_vigencia = models.DateField( + _(u'Data término vigência'), null=True, blank=True, - help_text=_(u"Deixar em branco caso a duração seja indefinida") - ) + help_text=_(u'Término da vigência do convênio.') + ) data_pub_diario = models.DateField( _(u'data da publicação no Diário Oficial'), null=True, @@ -178,34 +178,13 @@ class Convenio(models.Model): conveniada = models.BooleanField(default=False) equipada = models.BooleanField(default=False) - def get_termino_convenio(self): - if (self.data_retorno_assinatura is None or - self.duracao is None): - return None - - ano = self.data_retorno_assinatura.year + int(self.duracao / 12) - mes = int(self.data_retorno_assinatura.month + int(self.duracao % 12)) - if mes > 12: - ano = ano + 1 - mes = mes - 12 - dia = self.data_retorno_assinatura.day - - while True: - try: - data_fim = date(year=ano, month=mes,day=dia) - break - except: - dia = dia - 1 - - return data_fim - def get_status(self): if self.status and self.status.cancela: return _(u"Cancelado") if self.data_retorno_assinatura is not None: - if self.duracao is not None: - if date.today() >= self.get_termino_convenio(): + if self.data_termino_vigencia is not None: + if date.today() >= self.data_termino_vigencia: return _(u"Vencido") return _(u"Vigente")