fix - change quota weight statistic by herd light/heavy vount
This commit is contained in:
@@ -54,6 +54,30 @@ def get_rancher_statistics(rancher: Rancher = None) -> typing.Any:
|
|||||||
return [{'name': key, 'value': value} for key, value in stats.items()], stats
|
return [{'name': key, 'value': value} for key, value in stats.items()], stats
|
||||||
|
|
||||||
|
|
||||||
|
def get_rancher_statistic_by_herd(rancher: Rancher = None) -> typing.Any:
|
||||||
|
""" get statistics of a rancher by his herds """ # noqa
|
||||||
|
|
||||||
|
herds = rancher.herd.all()
|
||||||
|
if herds.exists():
|
||||||
|
stats = herds.aggregate(
|
||||||
|
herd_count=Count("id", distinct=True),
|
||||||
|
light_count=Sum('light_livestock_number'),
|
||||||
|
heavy_count=Sum('heavy_livestock_number'),
|
||||||
|
sheep=Sum('light_livestock_number'), # noqa
|
||||||
|
cow=Sum('heavy_livestock_number'),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
stats = {
|
||||||
|
'herd_count': 0,
|
||||||
|
'light_count': 0,
|
||||||
|
'heavy_count': 0,
|
||||||
|
'sheep': 0,
|
||||||
|
'cow': 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
return [{'name': key, 'value': value} for key, value in stats.items()], stats
|
||||||
|
|
||||||
|
|
||||||
def rancher_quota_weight(
|
def rancher_quota_weight(
|
||||||
rancher: Rancher,
|
rancher: Rancher,
|
||||||
inventory_entry: InventoryEntry = None,
|
inventory_entry: InventoryEntry = None,
|
||||||
@@ -89,7 +113,7 @@ def rancher_quota_weight(
|
|||||||
herds = rancher.herd.all()
|
herds = rancher.herd.all()
|
||||||
herd_livestock_gropes = [herd.activity for herd in herds]
|
herd_livestock_gropes = [herd.activity for herd in herds]
|
||||||
|
|
||||||
livestock_counts_list, livestock_counts_dict = get_rancher_statistics(rancher)
|
livestock_counts_list, livestock_counts_dict = get_rancher_statistic_by_herd(rancher)
|
||||||
|
|
||||||
total_weight = 0
|
total_weight = 0
|
||||||
merged = {}
|
merged = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user