Skip to content

Commit

Permalink
🔧 Models: Ajustar models e importação de models
Browse files Browse the repository at this point in the history
  • Loading branch information
Voctor-367 committed Jul 28, 2023
1 parent d1d6089 commit bebfaf7
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 51 deletions.
8 changes: 2 additions & 6 deletions code/apps/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
from .permissions import set_permission
from .models import Usuario, SolicitacaoCadastro
from django.contrib import messages


from financas.models import Saida, Entrada
from igreja.models import Dizimo, OfertaCulto, Membro, Igreja, SaldoMes
from financas.models import Saida, Entradas
from igreja.models import Dizimo, OfertaCulto, Membro, Igreja

@login_required
def obterUsuario(request):
Expand Down Expand Up @@ -45,7 +43,6 @@ def home(request):
variacao_total = []
membros = Membro.objects.filter(igreja=usuario.igreja)[:5]
igrejas = Igreja.objects.all()[:5]
saldos = SaldoMes.objects.all()[:5]

for i, data in enumerate(datas):
proximo_mes = data.replace(day=28) + timedelta(days=4)
Expand Down Expand Up @@ -92,7 +89,6 @@ def home(request):
'usuario': usuario,
'igreja': usuario.igreja,
'usuario_nome': usuario.nome.split()[0],
'saldos': saldos,
# Formatação com duas casas decimais e separador de milhares
'total_dizimos': '{:,.2f}'.format(total_dizimos[-1]),
'variacao_dizimos': variacao_dizimos[-1],
Expand Down
2 changes: 1 addition & 1 deletion code/apps/financas/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ class RMAdmin(admin.ModelAdmin):

admin.site.register(RelatorioMensal, RMAdmin)
admin.site.register(RelatorioGeral)
admin.site.register(Entrada, EntradaAdmin)
admin.site.register(Entradas, EntradaAdmin)
admin.site.register(Saida)
4 changes: 2 additions & 2 deletions code/apps/financas/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from django.core.exceptions import ValidationError

from .models import Saida, Entrada, RelatorioGeral
from .models import Saida, Entradas, RelatorioGeral

class SaidaForm(forms.ModelForm):

Expand All @@ -14,7 +14,7 @@ class Meta:
class EntradaForm(forms.ModelForm):

class Meta:
model = Entrada
model = Entradas
fields = ['igreja']

class RelatorioGeralForm(forms.ModelForm):
Expand Down
2 changes: 1 addition & 1 deletion code/apps/financas/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def gerar_relatorio(self, **kargs):
return "Gerar Relatorio"


class Entrada(models.Model):
class Entradas(models.Model):
ofertas = models.ManyToManyField(
igreja.models.OfertaCulto,
related_name="entradas_ofertas",
Expand Down
29 changes: 17 additions & 12 deletions code/apps/financas/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from decimal import Decimal

from .forms import SaidaForm, RelatorioGeralForm
from .models import Entrada, RelatorioGeral, RelatorioMensal, Saida
from .models import Entradas, RelatorioGeral, RelatorioMensal, Saida

pdfmetrics.registerFont(TTFont("Arial", "arial.ttf"))

Expand Down Expand Up @@ -258,7 +258,7 @@ def adicionar_dizimo(request):
user = obterUsuario(request)
print(user.igreja)

entrada = get_object_or_404(Entrada, igreja=user.igreja)
entrada = get_object_or_404(Entradas, igreja=user.igreja)

if request.method == 'POST':
form = DizimoFormWithUser(request.POST, usuario=user)
Expand Down Expand Up @@ -409,7 +409,7 @@ def calc_soma_dizimo(oferta):

def adicionar_oferta(request):
user = obterUsuario(request)
entrada, _ = Entrada.objects.get_or_create(
entrada, _ = Entradas.objects.get_or_create(
igreja=user.igreja) # (objeto, se ele existe ou não)

if request.method == 'POST':
Expand Down Expand Up @@ -877,7 +877,6 @@ def gerar_relatorio_mensal(request, relatorio_id):
data_atual = data_atual.strftime("%d/%m/%Y às %H:%M")
tesoureiro = obterUsuario(request)
igreja = tesoureiro.igreja
nome_igreja = igreja.nome

buf = io.BytesIO()
doc = SimpleDocTemplate(buf, pagesize=A4)
Expand All @@ -893,6 +892,7 @@ def gerar_relatorio_mensal(request, relatorio_id):
qr_code.save(buf_qr, format="PNG")
qr_code_img = buf_qr.getvalue()
buf_qr.close()
igreja = igreja.nome
endereco = igreja.localizacao
departamento = "Departamento Administrativo - Guanambi - BA<br/>"

Expand All @@ -906,7 +906,7 @@ def gerar_relatorio_mensal(request, relatorio_id):
header_data = [
[
Image(image_path, width=35, height=35),
Paragraph(nome_igreja+endereco+departamento, getSampleStyleSheet()['Normal']),
Paragraph(igreja+endereco+departamento, getSampleStyleSheet()['Normal']),
Image(qr_img, width=50, height=50)]
]
header_table = Table(header_data, colWidths=[50, 380, 50], rowHeights=[30])
Expand All @@ -930,7 +930,9 @@ def gerar_relatorio_mensal(request, relatorio_id):
# Tabela de entradas
data_entradas = [
["ENTRADAS"],
["TOTAL:", 'R$ ' + str(relatorio_mensal.calc_total_entradas)],
["SEDE:", 'R$ ' + str(relatorio_geral.calc_entradas_sede)],
["CONGREGAÇÕES", 'R$ ' + str(relatorio_geral.calc_entradas_locais)],
["TOTAL:", 'R$ ' + str(relatorio_geral.calc_total_entradas)],
]

table_entradas = Table(data_entradas, colWidths=[300, 100])
Expand All @@ -947,10 +949,14 @@ def gerar_relatorio_mensal(request, relatorio_id):
# Tabela de saídas
data_saidas = [
["SAÍDAS", ""],
["PGTO OBREIROS", 'R$ ' + str(relatorio_mensal.pagamento_obreiro)],
["MISSÕES SEDE", 'R$ ' + str(relatorio_mensal.missoes_sede)],
["FUNDO CONVENCIONAL", 'R$ ' + str(relatorio_mensal.fundo_convencional)],
["TOTAL:", 'R$ ' + str(relatorio_mensal.calc_saidas)],
["SEDE:", 'R$ ' + str(relatorio_geral.calc_saidas_sede)],
["CONGREGAÇÕES", 'R$ ' + str(relatorio_geral.calc_saidas_locais)],
["PGTO OBREIROS", 'R$ ' + str(relatorio_geral.pgto_obreiros)],
["INSS", 'R$ ' + str(relatorio_geral.inss)],
["ALUGUEL DE OBREIROS", 'R$ ' + str(relatorio_geral.aluguel_obreiros)],
["REPS/REFMAS/CONST", 'R$ ' + str(relatorio_geral.construcoes)],
["ASSIS. SOCIAL", 'R$ ' + str(relatorio_geral.assis_social)],
["TOTAL:", 'R$ ' + str(relatorio_geral.calc_total_saidas)],
]

table_saidas = Table(data_saidas, colWidths=[300, 100])
Expand All @@ -967,7 +973,7 @@ def gerar_relatorio_mensal(request, relatorio_id):
# Saldo Atual (using a table)
saldo_atual_data = [
["SALDO ATUAL", ""],
["TOTAL:", 'R$ ' + str(relatorio_mensal.calc_saldo)],
[f"Gerado em {data_atual}", ""]
]

table_saldo_atual = Table(saldo_atual_data, colWidths=[300, 100])
Expand All @@ -984,7 +990,6 @@ def gerar_relatorio_mensal(request, relatorio_id):

elements.append(Paragraph("<br/><br/><br/><br/>",
getSampleStyleSheet()['Normal']))
elements.append(Paragraph("Gerado em " + data_atual, getSampleStyleSheet()['Normal']))

signature_data = [
["_"*40],
Expand Down
4 changes: 1 addition & 3 deletions code/apps/igreja/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ class DizimoAdmin(admin.ModelAdmin):
form = DizimoAdminForm
list_display = ('membro', 'igreja', 'data_culto', 'valor')

class SaldoAdmin(admin.ModelAdmin):
list_display = ('mes', 'valor', 'id')


admin.site.register(Dizimo, DizimoAdmin)
admin.site.register(SaldoMes, SaldoAdmin)
admin.site.register(OfertaCulto)
admin.site.register(Membro)
admin.site.register(Igreja)
23 changes: 2 additions & 21 deletions code/apps/igreja/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.db import models
from django.db.models import F
from multiselectfield import MultiSelectField
import accounts.models

from adgestao.validators import validate_cpf, validate_data

Expand Down Expand Up @@ -37,7 +38,7 @@ class Igreja(models.Model):
default=0,
verbose_name='Saldo',
)

REQUIRED_FIELDS = ['nome', 'localização']


Expand All @@ -46,26 +47,6 @@ def save(self, *args, **kwargs):

def __str__(self):
return self.nome


class SaldoMes(models.Model):
valor = models.DecimalField(
max_digits=12,
decimal_places=3,
)

id = models.UUIDField(
primary_key=True,
default=uuid.uuid4,
editable=False
)

mes = models.CharField(
max_length=100,
)

def save(self, *args, **kwargs):
super().save(*args, **kwargs)



Expand Down
4 changes: 2 additions & 2 deletions code/apps/igreja/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render, reverse
from accounts.views import obterUsuario
from financas.models import Entrada, RelatorioGeral
from financas.models import Entradas, RelatorioGeral
import calendar
from datetime import datetime

Expand All @@ -27,7 +27,7 @@ def cadastrar_igreja(request):

# Ao cadastrar uma nova igreja, uma instância do objeto Entrada é criado. Este objeto é vinculado a uma igreja
# e contém o registro de todos os dízimos e ofertas da mesma
entrada_criada = Entrada(igreja=igreja_cad)
entrada_criada = Entradas(igreja=igreja_cad)

entrada_criada.save()

Expand Down
6 changes: 3 additions & 3 deletions code/templates/registration/logged_out.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{% endblock %}

{% block 'breadcump1' %}
<li class="breadcrumb-item active" aria-current="page">Igrejas</li>
<li class="breadcrumb-item active" aria-current="page">Log out</li>
{% endblock %}

{% block 'content' %}
Expand All @@ -18,6 +18,6 @@


<div class="card-body">
<p>Logged out!</p>
<a href="{% url 'login'%}">Click here to login again.</a>
<p>Conta desconectada !</p>
<a href="{% url 'login'%}">Clique aqui para fazer o login.</a>
{% endblock %}

0 comments on commit bebfaf7

Please sign in to comment.