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,36 @@
from django.db.models import Sum,Count
from django.utils import timezone
from Base.models import (
ServiceList,
)
from Movement.models import (
Calendar,
)
def metric():
now = timezone.localtime(timezone.now())
current_month = now.month
current_year = now.year
# Criamos um queryset base para evitar repetição de filtros
base_queryset = Calendar.objects.filter(
date__month=current_month,
date__year=current_year
)
# Breakdown (Agrupado por profissional e serviço)
services_breakdown = base_queryset.values(
'professional__name',
'service__name'
).annotate(
quantidade_feitas=Count('id'),
lucro_liquido=Sum('value_cash')
).order_by('professional__name', 'service__name')
# Total geral de lucro no mês
total_geral = base_queryset.aggregate(total=Sum('value_cash'))['total'] or 0
return {
'services': services_breakdown,
'total': total_geral
}