first commit

This commit is contained in:
2026-01-02 09:19:43 -03:00
parent 63cf724aaf
commit cc44b7ef4f
187 changed files with 2484 additions and 686 deletions

View File

@@ -0,0 +1,46 @@
from django.db.models import Sum
from django.utils import timezone
from Base.models import (
BankAccount,
ChartOfAccount
)
from Movement.models import (
ExpenseOrCredit,
)
def metric():
# Lista de Bancos
current_month = timezone.localtime(timezone.now()).month
current_year = timezone.localtime(timezone.now()).year
banks = ChartOfAccount.objects.filter(
debit=False,
credit=True,
firm=False,
)
# pegando total de Desspesas Profissinal
sum_expense_prof = {}
for bank in banks:
sum_bank = ExpenseOrCredit.objects.filter(
# active=True,
date__month=current_month,
date__year=current_year,
firm=False,
debit=False,
credit=True,
chart_of_account__name=bank.name,
).aggregate(Sum('gross_value'))['gross_value__sum'] or 0
if sum_bank > 0:
sum_expense_prof[bank.name] = sum_bank
# saldo total de tudo
sum_total = {}
for bank in sum_expense_prof:
sum_expense_get = sum_expense_prof.get(str(bank))
sum_total[bank] = sum_expense_get
sum_all = sum(sum_total.values()) or 0
return {
'sum_total':sum_total,
'sum_all':sum_all,
}