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:
|
||||
""" get statistics of a rancher """ # noqa
|
||||
|
||||
# get rancher livestock
|
||||
livestocks = LiveStock.objects.filter(herd__rancher=rancher) # noqa
|
||||
|
||||
# get rancher temporary livestock , rancher will have no herd
|
||||
temporary_livestock = TemporaryLiveStock.objects.filter(rancher=rancher)
|
||||
|
||||
if livestocks:
|
||||
if livestocks.exists():
|
||||
stats = livestocks.aggregate(
|
||||
herd_count=Count("herd", distinct=True),
|
||||
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='بز')),
|
||||
cow=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:
|
||||
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)),
|
||||
cow=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
|
||||
|
||||
@@ -12,7 +12,7 @@ def pos_organizations_sharing_information(
|
||||
pos sharing organizations' information,
|
||||
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 = [{
|
||||
"organization_name": item.organization.name,
|
||||
|
||||
Reference in New Issue
Block a user