temporary livestock add to rancher statistic struvture
This commit is contained in:
@@ -8,7 +8,8 @@ from apps.warehouse.models import (
|
|||||||
from django.db.models import Sum
|
from django.db.models import Sum
|
||||||
from apps.product.models import Quota, QuotaDistribution
|
from apps.product.models import Quota, QuotaDistribution
|
||||||
from apps.herd.services.rancher_service import RancherService
|
from apps.herd.services.rancher_service import RancherService
|
||||||
from django.db.models import Count, Q
|
from django.db.models import Count, Q, Value
|
||||||
|
from django.db.models.functions import Coalesce
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
|
|
||||||
@@ -31,14 +32,13 @@ def get_rancher_statistics(rancher: Rancher = None) -> typing.Any:
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
stats = temporary_livestock.aggregate(
|
stats = temporary_livestock.aggregate(
|
||||||
herd_count=0,
|
light_count=Coalesce(Sum('count', filter=Q(livestock_type__weight_type='L')), Value(0)),
|
||||||
light_count=Count('id', filter=Q(livestock_type__weight_type='L')),
|
heavy_count=Coalesce(Sum('count', filter=Q(livestock_type__weight_type='H')), Value(0)),
|
||||||
heavy_count=Count('id', filter=Q(livestock_type__weight_type='H')),
|
sheep=Coalesce(Sum('count', filter=Q(livestock_type__name='گوسفند')), Value(0)), # noqa
|
||||||
sheep=Count('id', filter=Q(livestock_type__name='گوسفند')), # noqa
|
goat=Coalesce(Sum('count', filter=Q(livestock_type__name='بز')), Value(0)),
|
||||||
goat=Count('id', filter=Q(livestock_type__name='بز')),
|
cow=Coalesce(Sum('count', filter=Q(livestock_type__name='گاو')), Value(0)),
|
||||||
cow=Count('id', filter=Q(livestock_type__name='گاو')),
|
camel=Coalesce(Sum('count', filter=Q(livestock_type__name='شتر')), Value(0)),
|
||||||
camel=Count('id', filter=Q(livestock_type__name='شتر')),
|
horse=Coalesce(Sum('count', filter=Q(livestock_type__name='بز')), Value(0)),
|
||||||
horse=Count('id', filter=Q(livestock_type__name='بز')),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return [{'name': key, 'value': value} for key, value in stats.items()], stats
|
return [{'name': key, 'value': value} for key, value in stats.items()], stats
|
||||||
@@ -119,6 +119,7 @@ def rancher_quota_weight(
|
|||||||
return {
|
return {
|
||||||
"total_weight": total_weight,
|
"total_weight": total_weight,
|
||||||
"remaining_weight": total_weight - rancher_remaining_usage,
|
"remaining_weight": total_weight - rancher_remaining_usage,
|
||||||
|
"rancher_temporary_livestock": rancher.without_herd,
|
||||||
"by_type": [{
|
"by_type": [{
|
||||||
"name": key,
|
"name": key,
|
||||||
"name_fa": value['name_fa'],
|
"name_fa": value['name_fa'],
|
||||||
|
|||||||
Reference in New Issue
Block a user