Browse Source

Inclui campo telefone_geral em Orgao

pull/159/head
Sesostris Vieira 3 years ago
parent
commit
7de838edbc
  1. 3
      sigi/apps/casas/admin.py
  2. 18
      sigi/apps/casas/migrations/0025_orgao_telefone_geral.py
  3. 29
      sigi/apps/casas/migrations/0026_carga_telefone_geral.py
  4. 17
      sigi/apps/casas/models.py
  5. 25
      sigi/apps/convenios/migrations/0030_alter_projeto_modelo_minuta_and_more.py
  6. 10
      sigi/apps/eventos/forms.py

3
sigi/apps/casas/admin.py

@ -324,8 +324,9 @@ class OrgaoAdmin(CartExportReportMixin, admin.ModelAdmin):
_("Outras informações"),
{
"fields": (
"observacoes",
"telefone_geral",
"horario_funcionamento",
"observacoes",
"foto",
"brasao",
),

18
sigi/apps/casas/migrations/0025_orgao_telefone_geral.py

@ -0,0 +1,18 @@
# Generated by Django 4.0.5 on 2022-06-30 17:21
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('casas', '0024_delete_presidente'),
]
operations = [
migrations.AddField(
model_name='orgao',
name='telefone_geral',
field=models.CharField(blank=True, default='', help_text='Exemplo: <em>(31)8851-9898</em>.', max_length=64, verbose_name='telefone geral'),
),
]

29
sigi/apps/casas/migrations/0026_carga_telefone_geral.py

@ -0,0 +1,29 @@
# Generated by Django 4.0.5 on 2022-06-30 17:26
from django.db import migrations
def carrega_telefone_geral(apps, schema_editor):
Orgao = apps.get_model("casas", "Orgao")
Telefone = apps.get_model("contatos", "Telefone")
telefones = Telefone.objects.filter(
content_type__app_label="casas", content_type__model="orgao"
)
for orgao in Orgao.objects.all():
telefone = (
telefones.filter(object_id=orgao.id).exclude(numero="").first()
)
if telefone:
orgao.telefone_geral = telefone.numero
orgao.save()
class Migration(migrations.Migration):
dependencies = [
("casas", "0025_orgao_telefone_geral"),
]
operations = [
migrations.RunPython(carrega_telefone_geral),
]

17
sigi/apps/casas/models.py

@ -100,6 +100,13 @@ class Orgao(models.Model):
ult_alt_endereco = models.DateTimeField(
_("última alteração do endereço"), null=True, blank=True, editable=True
)
telefone_geral = models.CharField(
_("telefone geral"),
max_length=64,
blank=True,
default="",
help_text=_("Exemplo: <em>(31)8851-9898</em>."),
)
telefones = GenericRelation("contatos.Telefone")
foto = models.ImageField(
_("foto"),
@ -153,10 +160,12 @@ class Orgao(models.Model):
@property
def telefone(self):
telefones = self.telefones.all()
if telefones:
return telefones[0]
return None
if self.telefone_geral:
return self.telefone_geral
telefone = self.telefones.first()
if telefone:
return telefone.numero
return ""
@property
def presidente(self):

25
sigi/apps/convenios/migrations/0030_alter_projeto_modelo_minuta_and_more.py

File diff suppressed because one or more lines are too long

10
sigi/apps/eventos/forms.py

@ -61,7 +61,15 @@ class ConviteForm(forms.ModelForm):
class CasaForm(forms.ModelForm):
class Meta:
model = Orgao
fields = ["cnpj", "logradouro", "bairro", "cep", "email", "brasao"]
fields = [
"cnpj",
"logradouro",
"bairro",
"cep",
"telefone_geral",
"email",
"brasao",
]
class FuncionarioForm(forms.ModelForm):

Loading…
Cancel
Save