21 lines
677 B
Python
21 lines
677 B
Python
from django.db.models import Sum
|
|
|
|
from apps.emtiyazat.models import Emtiyazat as EmtiyazatModel, ArzeshEmtiyaz as ArzeshEmtiyazModel
|
|
|
|
|
|
def get_arzesh_emtiyaz():
|
|
arzesh_obj = ArzeshEmtiyazModel.objects.filter().last()
|
|
return arzesh_obj.price
|
|
|
|
|
|
def get_emtiyaz_mojri(cuser) -> int:
|
|
sum_credit = EmtiyazatModel.objects.filter(cuser=cuser).aggregate(Sum('credit'))
|
|
sum_debit = EmtiyazatModel.objects.filter(cuser=cuser).aggregate(Sum('debit'))
|
|
|
|
if sum_credit['credit__sum'] is None:
|
|
sum_credit['credit__sum'] = 0
|
|
if sum_debit['debit__sum'] is None:
|
|
sum_debit['debit__sum'] = 0
|
|
|
|
return sum_credit['credit__sum'] - sum_debit['debit__sum']
|