first commit
This commit is contained in:
38
Base/Metrics/DashboardProf/get_total_money.py
Normal file
38
Base/Metrics/DashboardProf/get_total_money.py
Normal file
@@ -0,0 +1,38 @@
|
||||
from django.db.models import Sum , Count
|
||||
from django.utils import timezone
|
||||
from Movement.models import (
|
||||
Calendar,
|
||||
ExpenseOrCredit
|
||||
)
|
||||
|
||||
def metric(Prof_id):
|
||||
current_month = timezone.localtime(timezone.now()).month
|
||||
current_year = timezone.localtime(timezone.now()).year
|
||||
|
||||
calenda = Calendar.objects.filter(
|
||||
professional_id=Prof_id,
|
||||
date__month=current_month,
|
||||
date__year=current_year,
|
||||
)
|
||||
debit = ExpenseOrCredit.objects.filter(
|
||||
prof=True,
|
||||
debit=True,
|
||||
credit=False,
|
||||
professional_id=Prof_id,
|
||||
date__month=current_month,
|
||||
date__year=current_year,
|
||||
)
|
||||
credit = ExpenseOrCredit.objects.filter(
|
||||
prof=True,
|
||||
debit=False,
|
||||
credit=True,
|
||||
professional_id=Prof_id,
|
||||
date__month=current_month,
|
||||
date__year=current_year,
|
||||
)
|
||||
sum_calenda = calenda.aggregate(Sum('prof_money'))['prof_money__sum'] or 0
|
||||
sum_debit = calenda.aggregate(Sum('gross_value'))['gross_value__sum'] or 0
|
||||
sum_credit = calenda.aggregate(Sum('gross_value'))['gross_value__sum'] or 0
|
||||
all = sum_calenda + sum_credit - sum_debit
|
||||
|
||||
return all
|
||||
Reference in New Issue
Block a user