some improvements on pos rancher distributions
This commit is contained in:
@@ -16,10 +16,13 @@ import typing
|
|||||||
def get_rancher_statistics(rancher: Rancher = None) -> typing.Any:
|
def get_rancher_statistics(rancher: Rancher = None) -> typing.Any:
|
||||||
""" get statistics of a rancher """ # noqa
|
""" get statistics of a rancher """ # noqa
|
||||||
|
|
||||||
|
# get rancher livestock
|
||||||
livestocks = LiveStock.objects.filter(herd__rancher=rancher) # noqa
|
livestocks = LiveStock.objects.filter(herd__rancher=rancher) # noqa
|
||||||
|
|
||||||
|
# get rancher temporary livestock , rancher will have no herd
|
||||||
temporary_livestock = TemporaryLiveStock.objects.filter(rancher=rancher)
|
temporary_livestock = TemporaryLiveStock.objects.filter(rancher=rancher)
|
||||||
|
|
||||||
if livestocks:
|
if livestocks.exists():
|
||||||
stats = livestocks.aggregate(
|
stats = livestocks.aggregate(
|
||||||
herd_count=Count("herd", distinct=True),
|
herd_count=Count("herd", distinct=True),
|
||||||
light_count=Count('id', filter=Q(weight_type='L')),
|
light_count=Count('id', filter=Q(weight_type='L')),
|
||||||
@@ -28,7 +31,7 @@ def get_rancher_statistics(rancher: Rancher = None) -> typing.Any:
|
|||||||
goat=Count('id', filter=Q(type__name='بز')),
|
goat=Count('id', filter=Q(type__name='بز')),
|
||||||
cow=Count('id', filter=Q(type__name='گاو')),
|
cow=Count('id', filter=Q(type__name='گاو')),
|
||||||
camel=Count('id', filter=Q(type__name='شتر')),
|
camel=Count('id', filter=Q(type__name='شتر')),
|
||||||
horse=Count('id', filter=Q(type__name='بز')),
|
horse=Count('id', filter=Q(type__name='اسب')),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
stats = temporary_livestock.aggregate(
|
stats = temporary_livestock.aggregate(
|
||||||
@@ -38,7 +41,7 @@ def get_rancher_statistics(rancher: Rancher = None) -> typing.Any:
|
|||||||
goat=Coalesce(Sum('count', filter=Q(livestock_type__name='بز')), Value(0)),
|
goat=Coalesce(Sum('count', filter=Q(livestock_type__name='بز')), Value(0)),
|
||||||
cow=Coalesce(Sum('count', filter=Q(livestock_type__name='گاو')), Value(0)),
|
cow=Coalesce(Sum('count', filter=Q(livestock_type__name='گاو')), Value(0)),
|
||||||
camel=Coalesce(Sum('count', filter=Q(livestock_type__name='شتر')), Value(0)),
|
camel=Coalesce(Sum('count', filter=Q(livestock_type__name='شتر')), Value(0)),
|
||||||
horse=Coalesce(Sum('count', filter=Q(livestock_type__name='بز')), Value(0)),
|
horse=Coalesce(Sum('count', filter=Q(livestock_type__name='اسب')), Value(0)),
|
||||||
)
|
)
|
||||||
|
|
||||||
return [{'name': key, 'value': value} for key, value in stats.items()], stats
|
return [{'name': key, 'value': value} for key, value in stats.items()], stats
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ def pos_organizations_sharing_information(
|
|||||||
pos sharing organizations' information,
|
pos sharing organizations' information,
|
||||||
device have multiple organizations (sub_accounts) for sharing money
|
device have multiple organizations (sub_accounts) for sharing money
|
||||||
"""
|
"""
|
||||||
stake_holders = device.stake_holders.select_related('broker', 'organization')
|
stake_holders = device.stake_holders.select_related('broker', 'organization').filter(default=False)
|
||||||
|
|
||||||
sharing_information_list = [{
|
sharing_information_list = [{
|
||||||
"organization_name": item.organization.name,
|
"organization_name": item.organization.name,
|
||||||
|
|||||||
Reference in New Issue
Block a user