From bd7d6565c39b08368d7601ee9612d01de3568e6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Wed, 12 Jan 2022 10:17:40 -0300 Subject: [PATCH] =?UTF-8?q?Migra=C3=A7=C3=A3o=20app=20Invent=C3=A1rio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MIGRACAO.md | 4 +- sigi/apps/inventario/admin.py | 40 ++++++---------- sigi/apps/inventario/apps.py | 6 +++ .../inventario/migrations/0001_initial.py | 12 ++--- .../migrations/0002_auto_20210406_1945.py | 2 +- ...er_bem_id_alter_equipamento_id_and_more.py | 48 +++++++++++++++++++ sigi/apps/inventario/models.py | 27 ++++------- sigi/apps/inventario/tests.py | 3 ++ sigi/settings/base.py | 1 + 9 files changed, 92 insertions(+), 51 deletions(-) create mode 100644 sigi/apps/inventario/apps.py create mode 100644 sigi/apps/inventario/migrations/0004_alter_bem_id_alter_equipamento_id_and_more.py create mode 100644 sigi/apps/inventario/tests.py diff --git a/MIGRACAO.md b/MIGRACAO.md index 8cfe716..7423dfa 100644 --- a/MIGRACAO.md +++ b/MIGRACAO.md @@ -43,7 +43,7 @@ Macro-tarefas: * [ ] Migração dos APPS, nesta sequência: * [x] servidores * [x] contatos - * [ ] casas + * [-] casas - migração básica - falta integração com outros apps * [ ] convenios * [ ] parlamentares * [ ] eventos @@ -51,6 +51,6 @@ Macro-tarefas: * [ ] ocorrencias * [ ] whois * [ ] financeiro - * [ ] inventario + * [x] inventario * [ ] metas * [ ] Definição de um novo tema *bootstrapado* para o admin diff --git a/sigi/apps/inventario/admin.py b/sigi/apps/inventario/admin.py index b7e206b..c2d8406 100644 --- a/sigi/apps/inventario/admin.py +++ b/sigi/apps/inventario/admin.py @@ -1,56 +1,53 @@ -# -*- coding: utf-8 -*- from django.contrib import admin -from django.contrib.contenttypes import generic +from django.contrib.contenttypes.admin import GenericTabularInline from sigi.apps.contatos.models import Contato, Telefone from sigi.apps.inventario.models import (Fornecedor, Fabricante, Equipamento, TipoEquipamento, ModeloEquipamento, Bem) -from sigi.apps.utils.base_admin import BaseModelAdmin -class ContatosInline(generic.GenericTabularInline): +class ContatosInline(GenericTabularInline): model = Contato extra = 2 raw_id_fields = ('municipio',) - -class TelefonesInline(generic.GenericTabularInline): +class TelefonesInline(GenericTabularInline): model = Telefone extra = 2 - -class FornecedorAdmin(BaseModelAdmin): +@admin.register(Fornecedor) +class FornecedorAdmin(admin.ModelAdmin): inlines = (TelefonesInline, ContatosInline) list_display = ('id', 'nome', 'email', 'pagina_web') list_display_links = ('id', 'nome') list_filter = ('nome',) search_fields = ('id', 'nome', 'email', 'pagina_web') - -class FabricanteAdmin(BaseModelAdmin): +@admin.register(Fabricante) +class FabricanteAdmin(admin.ModelAdmin): list_display = ('id', 'nome') list_display_links = list_display list_filter = ('nome',) search_fields = ('id', 'nome') - -class TipoEquipamentoAdmin(BaseModelAdmin): +@admin.register(TipoEquipamento) +class TipoEquipamentoAdmin(admin.ModelAdmin): list_display = ('id', 'tipo') list_display_links = list_display list_filter = ('tipo',) search_fields = ('id', 'tipo') - -class ModeloEquipamentoAdmin(BaseModelAdmin): +@admin.register(ModeloEquipamento) +class ModeloEquipamentoAdmin(admin.ModelAdmin): list_display = ('id', 'tipo', 'modelo') list_filter = ('tipo', 'modelo') ordering = ('tipo', 'modelo') search_fields = ('id', 'tipo', 'modelo') raw_id_fields = ('tipo',) - -class EquipamentoAdmin(BaseModelAdmin): +@admin.register(Equipamento) +class EquipamentoAdmin(admin.ModelAdmin): list_display = ('id', 'fabricante', 'modelo', 'get_tipo') list_display_links = ('id',) list_filter = ('fabricante',) @@ -62,8 +59,8 @@ class EquipamentoAdmin(BaseModelAdmin): return obj.modelo.tipo.tipo get_tipo.short_description = 'tipo' - -class BemAdmin(BaseModelAdmin): +@admin.register(Bem) +class BemAdmin(admin.ModelAdmin): list_display = ('equipamento', 'fornecedor', 'num_serie', 'casa_legislativa') list_filter = ('fornecedor',) @@ -72,10 +69,3 @@ class BemAdmin(BaseModelAdmin): search_fields = ('fornecedor__nome', 'equipamento__fabricante__nome', 'equipamento__modelo__modelo', 'num_serie', 'num_tombamento', 'casa_legislativa__nome') - -admin.site.register(Fornecedor, FornecedorAdmin) -admin.site.register(Fabricante, FabricanteAdmin) -admin.site.register(TipoEquipamento, TipoEquipamentoAdmin) -admin.site.register(ModeloEquipamento, ModeloEquipamentoAdmin) -admin.site.register(Equipamento, EquipamentoAdmin) -admin.site.register(Bem, BemAdmin) diff --git a/sigi/apps/inventario/apps.py b/sigi/apps/inventario/apps.py new file mode 100644 index 0000000..40ed946 --- /dev/null +++ b/sigi/apps/inventario/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig +from django.utils.translation import gettext_lazy as _ + +class InventarioConfig(AppConfig): + name = 'sigi.apps.inventario' + verbose_name = _('inventário') diff --git a/sigi/apps/inventario/migrations/0001_initial.py b/sigi/apps/inventario/migrations/0001_initial.py index b16ba94..23b6bdb 100644 --- a/sigi/apps/inventario/migrations/0001_initial.py +++ b/sigi/apps/inventario/migrations/0001_initial.py @@ -18,7 +18,7 @@ class Migration(migrations.Migration): ('num_serie', models.CharField(help_text='N\xfamero fornecido pelo fabricante.', unique=True, max_length=64, verbose_name='n\xfamero de s\xe9rie')), ('recebido_por', models.CharField(help_text='Nome de quem recebeu o equipamento.', max_length=64, blank=True)), ('observacoes', models.TextField(verbose_name='observa\xe7\xf5es', blank=True)), - ('casa_legislativa', models.ForeignKey(to='casas.CasaLegislativa')), + ('casa_legislativa', models.ForeignKey(to='casas.CasaLegislativa', on_delete=models.CASCADE)), ], options={ 'verbose_name_plural': 'bens', @@ -88,19 +88,19 @@ class Migration(migrations.Migration): migrations.AddField( model_name='modeloequipamento', name='tipo', - field=models.ForeignKey(verbose_name='tipo de equipamento', to='inventario.TipoEquipamento'), + field=models.ForeignKey(verbose_name='tipo de equipamento', to='inventario.TipoEquipamento', on_delete=models.CASCADE), preserve_default=True, ), migrations.AddField( model_name='equipamento', name='fabricante', - field=models.ForeignKey(to='inventario.Fabricante'), + field=models.ForeignKey(to='inventario.Fabricante', on_delete=models.CASCADE), preserve_default=True, ), migrations.AddField( model_name='equipamento', name='modelo', - field=models.ForeignKey(to='inventario.ModeloEquipamento'), + field=models.ForeignKey(to='inventario.ModeloEquipamento', on_delete=models.CASCADE), preserve_default=True, ), migrations.AlterUniqueTogether( @@ -110,13 +110,13 @@ class Migration(migrations.Migration): migrations.AddField( model_name='bem', name='equipamento', - field=models.ForeignKey(to='inventario.Equipamento'), + field=models.ForeignKey(to='inventario.Equipamento', on_delete=models.CASCADE), preserve_default=True, ), migrations.AddField( model_name='bem', name='fornecedor', - field=models.ForeignKey(to='inventario.Fornecedor'), + field=models.ForeignKey(to='inventario.Fornecedor', on_delete=models.CASCADE), preserve_default=True, ), ] diff --git a/sigi/apps/inventario/migrations/0002_auto_20210406_1945.py b/sigi/apps/inventario/migrations/0002_auto_20210406_1945.py index 0473f66..e165c11 100644 --- a/sigi/apps/inventario/migrations/0002_auto_20210406_1945.py +++ b/sigi/apps/inventario/migrations/0002_auto_20210406_1945.py @@ -15,7 +15,7 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='bem', name='casa_legislativa', - field=models.ForeignKey(to='casas.Orgao'), + field=models.ForeignKey(to='casas.Orgao', on_delete=models.CASCADE), preserve_default=True, ), ] diff --git a/sigi/apps/inventario/migrations/0004_alter_bem_id_alter_equipamento_id_and_more.py b/sigi/apps/inventario/migrations/0004_alter_bem_id_alter_equipamento_id_and_more.py new file mode 100644 index 0000000..eb89482 --- /dev/null +++ b/sigi/apps/inventario/migrations/0004_alter_bem_id_alter_equipamento_id_and_more.py @@ -0,0 +1,48 @@ +# Generated by Django 4.0.1 on 2022-01-12 13:15 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('inventario', '0003_auto_20210416_0841'), + ] + + operations = [ + migrations.AlterField( + model_name='bem', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='equipamento', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='fabricante', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='fornecedor', + name='email', + field=models.EmailField(blank=True, max_length=254, verbose_name='e-mail'), + ), + migrations.AlterField( + model_name='fornecedor', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='modeloequipamento', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='tipoequipamento', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + ] diff --git a/sigi/apps/inventario/models.py b/sigi/apps/inventario/models.py index 590f47f..c4c8076 100644 --- a/sigi/apps/inventario/models.py +++ b/sigi/apps/inventario/models.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from django.contrib.contenttypes.fields import GenericRelation from django.db import models from django.utils.translation import gettext as _ @@ -6,7 +5,6 @@ from django.utils.translation import gettext as _ class Fornecedor(models.Model): nome = models.CharField(max_length=40) - nome.alphabetic_filter = True email = models.EmailField(_('e-mail'), blank=True) pagina_web = models.URLField(_('página web'), blank=True) telefones = GenericRelation('contatos.Telefone') @@ -16,21 +14,18 @@ class Fornecedor(models.Model): ordering = ('nome',) verbose_name_plural = _('fornecedores') - def __unicode__(self): + def __str__(self): return self.nome - class Fabricante(models.Model): nome = models.CharField(max_length=40, unique=True) - nome.alphabetic_filter = True class Meta: ordering = ('nome',) - def __unicode__(self): + def __str__(self): return self.nome - class TipoEquipamento(models.Model): tipo = models.CharField(max_length=40) @@ -39,10 +34,9 @@ class TipoEquipamento(models.Model): verbose_name = _('tipo de equipamento') verbose_name_plural = _('tipos de equipamentos') - def __unicode__(self): + def __str__(self): return self.tipo - class ModeloEquipamento(models.Model): tipo = models.ForeignKey( TipoEquipamento, @@ -56,10 +50,9 @@ class ModeloEquipamento(models.Model): verbose_name = _('modelo de equipamento') verbose_name_plural = _('modelos de equipamentos') - def __unicode__(self): + def __str__(self): return self.modelo - class Equipamento(models.Model): fabricante = models.ForeignKey( Fabricante, @@ -73,10 +66,10 @@ class Equipamento(models.Model): class Meta: unique_together = (('fabricante', 'modelo'),) - def __unicode__(self): - return unicode('%s %s %s' % (self.modelo.tipo, self.fabricante.nome, - self.modelo.modelo)) - + def __str__(self): + return _( + f"{self.modelo.tipo} {self.fabricante.nome} {self.modelo.modelo}" + ) class Bem(models.Model): casa_legislativa = models.ForeignKey( @@ -101,5 +94,5 @@ class Bem(models.Model): class Meta: verbose_name_plural = _('bens') - def __unicode__(self): - return unicode('%s (%s)') % (self.equipamento, self.casa_legislativa) + def __str__(self): + return _(f"{self.equipamento} ({self.casa_legislativa})") diff --git a/sigi/apps/inventario/tests.py b/sigi/apps/inventario/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/sigi/apps/inventario/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/sigi/settings/base.py b/sigi/settings/base.py index 1724944..8a97af3 100644 --- a/sigi/settings/base.py +++ b/sigi/settings/base.py @@ -22,6 +22,7 @@ INSTALLED_APPS = [ 'sigi.apps.servidores', 'sigi.apps.contatos', 'sigi.apps.casas', + 'sigi.apps.inventario', 'django_bootstrap5', 'localflavor', 'django.forms',