change map structure of rancher statistics

This commit is contained in:
2025-09-22 15:22:04 +03:30
parent 383cbc4162
commit ecb1049681
2 changed files with 5 additions and 4 deletions

View File

@@ -22,7 +22,7 @@ def get_rancher_statistics(rancher: Rancher = None) -> typing.Any:
camel_count=Count('id', filter=Q(type__name='شتر')),
horse_count=Count('id', filter=Q(type__name='بز')),
)
return stats
return [{'name': key, 'value': value} for key, value in stats.items()], stats
def rancher_quota_weight(rancher, inventory_entry: InventoryEntry = None, distribution: QuotaDistribution = None):
@@ -53,7 +53,7 @@ def rancher_quota_weight(rancher, inventory_entry: InventoryEntry = None, distri
# list of quota incentive plans
incentive_plans = list(quota.incentive_assignments.all().select_related('livestock_type'))
livestock_counts = get_rancher_statistics(rancher)
livestock_counts_list, livestock_counts_dict = get_rancher_statistics(rancher)
total_weight = 0
merged = {}
@@ -62,7 +62,7 @@ def rancher_quota_weight(rancher, inventory_entry: InventoryEntry = None, distri
if item.livestock_type:
animal_type = item.livestock_type.name
per_head = item.quantity_kg
count = livestock_counts.get(live_stock_meta.get(animal_type), 0)
count = livestock_counts_dict.get(live_stock_meta.get(animal_type), 0)
weight = per_head * count
total_weight += weight

View File

@@ -127,7 +127,8 @@ class QuotaDistributionSerializer(serializers.ModelSerializer):
if 'rancher' in self.context.keys():
# rancher herd & live stock statistics
representation['rancher_statistics'] = get_rancher_statistics(self.context['rancher'])
livestock_counts_list, livestock_counts_dict = get_rancher_statistics(self.context['rancher'])
representation['rancher_statistics'] = livestock_counts_list
# rancher live stock statistics by quota distributions
representation['rancher_quota_weight_statistics'] = rancher_quota_weight(