Browse Source

Remodelagem convenios - elima duração e adiciona término vigência

pull/89/head
Sesostris Vieira 3 years ago
parent
commit
a0a45d10ac
  1. 4
      sigi/apps/convenios/admin.py
  2. 43
      sigi/apps/convenios/management/commands/duracao_act.py
  3. 20
      sigi/apps/convenios/migrations/0011_convenio_data_termino_vigencia.py
  4. 38
      sigi/apps/convenios/migrations/0012_auto_20210831_0844.py
  5. 18
      sigi/apps/convenios/migrations/0013_remove_convenio_duracao.py
  6. 37
      sigi/apps/convenios/models.py

4
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',

43
sigi/apps/convenios/management/commands/duracao_act.py

@ -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!")

20
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,
),
]

38
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),
]

18
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',
),
]

37
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")

Loading…
Cancel
Save